So I am just wondering, how can I create an event in discord.py where if a user pings the bot it will respond with a message?
I have not found anything concrete anywhere on how to do this and I would appreciate it if someone could help get my feet wet on how to do this. I appreciate it!
As we all know, bots can ping @everyone and @here but they cannot ping roles.
I found that the default function discord.User.mentioned_in
works
In order for it to check for our bot, we add client.user
(which is our bot) in front of the function, making it client.user.mentioned_in(message)
. The argument message
, should be the same argument that you gave for the async def on_message(message)
line
Example:
@client.event
async def on_message(message):
if client.user.mentioned_in(message):
await message.channel.send('You mentioned me!')
I'm not sure why but I haven't seen any others use this function though. Maybe they just aren't aware of this, and instead use client.user.id in message.content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With