Willwell
Willwell

Reputation: 166

Bot Mentions Discord.py

  if client.user.mentioned_in(message):
    await ctx.send("Hi!")

So I want my bot to respond to anyone who @mentions it. It does work as it should, but the only problem it'll respond to @everyone and @here pings. It's probably simple and I am overthinking it but I just want to know if there is any way to make the bot respond to messages it's actually mentioned in, not @everyone or @here pings?

Upvotes: 1

Views: 1612

Answers (4)

Tom Yu
Tom Yu

Reputation: 131

In discord.py 1.7.3 the following code works

if client.user in message.mentions:
    await message.channel.send("Hi!")

Upvotes: 0

NevergonnagiveuupL
NevergonnagiveuupL

Reputation: 60

You can use the

@client.event
async def on_message(message):

Then detect if the message has mentioned the bot:

if client.user.mentioned_in(message):
    await message.channel.send("Hi!")

Documentation: https://docs.pycord.dev/en/master/api.html?highlight=mentioned#discord.ClientUser.mentioned_in

Upvotes: 0

iFreaku
iFreaku

Reputation: 1

Hmm Try This

@client.event
async def on_message(message):
  if f"<@!{client.user.id}>" in message.content:
    await ctx.send("Hi!")

Upvotes: 0

Aditya Tomar
Aditya Tomar

Reputation: 1639

Check whether the bot's user id is in the message content. Try the following:

    if str(client.user.id) in message.content:
        await ctx.send("Hi!")

Upvotes: 1

Related Questions