so i was trying to find a way to have a message deleted if it contained bad words (i mean by finding i just copied some code)
@client.event
async def on_message(message):
if message.author.id == client.user.id:
return
msg_content = message.content.lower()
curseWord = ["cursewords i put"]
if any(word in msg_content for word in curseWord):
await message.delete()
msg = "**`Watch your mouth boiii`**"
await message.channel.send(msg)
await message.msg.add_reaction("⚠")
i was trying to add a reaction to the message but i said
'Message' object has no attribute msg
CodePudding user response:
The error probably also points you to the line
await message.msg.add_reaction("⚠")
As the message says message
doesn't have an attribute called msg
. You can use add_reaction
directly on your message object.
await message.add_reaction("⚠")
But message
is referring to the message that you deleted, so you don't want to add a reaction to that message. Instead, to add the reaction to the message you just sent you need to get that message object and use it. To get it, when you did message.channel.send
the message object was sent back, we just need to save it.
sent_msg = await message.channel.send(msg)
And now we can use it to add a reaction. Altogether that looks like
if any(word in msg_content for word in curseWord):
await message.delete()
msg = "**`Watch your mouth boiii`**"
sent_msg = await message.channel.send(msg)
await sent_msg.add_reaction("⚠")