Discord.py- How to make bot send a message when pinged but not when replied to
Question:
Image Link I’m trying to make something where if the bot is pinged it says a message like "For a list of commands, type .help" and my code works except for it also says that when the bot is replied to.
This is my code – Using discord.py 1.7.3
@client.event
async def on_message(message):
if client.user.mentioned_in(message) and message.mention_everyone is False:
await message.channel.send("For a list of commands, type `.help`")
await client.process_commands(message)
Answers:
You’re looking for client.user.mention
. You can also check if client.user.mention in message.content
if you want to know whether the bot is mentioned somewhere in the message rather than checking if the mention comprises the entire message.
@client.event
async def on_message(message):
if client.user.mention == message.content and message.mention_everyone is False:
await message.channel.send("For a list of commands, type `.help`")
await client.process_commands(message)
Reference:
Image Link I’m trying to make something where if the bot is pinged it says a message like "For a list of commands, type .help" and my code works except for it also says that when the bot is replied to.
This is my code – Using discord.py 1.7.3
@client.event
async def on_message(message):
if client.user.mentioned_in(message) and message.mention_everyone is False:
await message.channel.send("For a list of commands, type `.help`")
await client.process_commands(message)
You’re looking for client.user.mention
. You can also check if client.user.mention in message.content
if you want to know whether the bot is mentioned somewhere in the message rather than checking if the mention comprises the entire message.
@client.event
async def on_message(message):
if client.user.mention == message.content and message.mention_everyone is False:
await message.channel.send("For a list of commands, type `.help`")
await client.process_commands(message)
Reference: