Reputation: 11
So I want to to make the bot to mention the author on author who has said n-word. I've tried to use {message.mention}
but apparently it does not exist so how does I mention someone using on_message event?
Here is the code:
@commands.Cog.listener()
async def on_message(self, message):
if "ni**a" in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author}")
if 'ni**er' in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author}")
if 'Ni**a' in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author}")
if 'Ni**er' in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author}")
Upvotes: 1
Views: 576
Reputation: 75
If you want to mention a user you always have to do this:
await message.channel.send(f"blablabliblu------> {message.authormention}")#you want to mention the message author
#mention a other spezific user
user = client/bot.get_user(user_id)#get the user
await message.channel.sedn(f"hellooooooo---> {user.mention})")
#so you alwas need <someuser.mention>
Upvotes: 0
Reputation: 1173
Member object
In order to mention someone you need to have the member object associated with that person.
The member object contains an attribute "mention" which can be used to retrieve the string used to mention that member.
So how to apply this?
As message.author
is a member object. We can use message.author.mention
to get the string to mention that member. Resulting in the following code:
@commands.Cog.listener()
async def on_message(self, message):
if "ni**a" in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author.mention}")
if 'ni**er' in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author.mention}")
if 'Ni**a' in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author.mention}")
if 'Ni**er' in message.content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author.mention}")
Simplify
And as some people have mentioned before we can simplify your code to this:
@commands.Cog.listener()
async def on_message(self, message):
content = message.content.lower()
if "ni**a" in content or "ni**er" in content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author.mention}")
References:
Upvotes: 1
Reputation: 4743
If you want to mention the author of a message, you can use message.author.mention
. And also you don't have to do 4 if statements, 1 is enough. Here's what you can do:
@commands.Cog.listener()
async def on_message(self, message):
content = message.content.lower()
if "ni**a" in content or "ni**er" in content:
await message.channel.send(f"<:sniper:711509974588719216> R6 BRUH {message.author.mention}")
Upvotes: 1