Reputation: 65
I have a bot that responds when I ping it by tagging its ID but it also responds to @everyone pings. How do I filter those out? I've tried using an if statement to filter out @everyone and the ID of @everyone but then the bot doesn't respond to normal pings. Here's the current code:
@bot.listen('on_message')
async def on_ping(message):
if bot.user.mentioned_in(message):
if "<@747577395086884998>" in message.content:
return
else:
channel = message.channel
embed=discord.Embed(color=0x0fd249)
file = discord.File("logo.png", filename="image.png")
embed.set_author(name="Fallen Bot", icon_url="attachment://image.png")
embed.add_field(name="Hi! I'm Fallen Bot!", value=f"My prefix is, `{bot.command_prefix}` and you can use `{bot.command_prefix}help` for help!", inline=False)
await channel.send(file=file, embed=embed)
I'm using the commands extension from the rewrite. The first block of the code is the filter for @everyone and the second part, below the else
statement is the response to a ping.
Upvotes: 1
Views: 814
Reputation: 2720
You can use the message.mention_everyone
attribute to filter out @everyone and @here-pings like so:
@bot.listen('on_message')
async def on_ping(message):
if message.mention_everyone:
return
else:
# this is a real ping, do your thing
Upvotes: 5
Reputation: 75
Just check if the bot was mentioned in the message, instead of check if it wasn't an everyone ping
if "<!@100>" in message.content: # 100 is the bots id, change it to yours
# handle the ping here
Upvotes: 0