'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?
Solution 1:[1]
Hmm Try This
@client.event
async def on_message(message):
if f"<@!{client.user.id}>" in message.content:
await ctx.send("Hi!")
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | iFreaku |
| Solution 2 | NevergonnagiveuupL |
