I would like to have my bot edit a message if it detects a keyword, i'm not sure how to edit the message though.
I've looked through the documentation but can't seem to figure it out. I'm using discord.py with python 3.6.
This is the code:
@bot.event
async def on_message(message):
if 'test' in message.content:
await edit(message, "testtest")
This is the error:
File "testthing.py", line 67, in on_message
await edit(message, "test")
NameError: name 'edit' is not defined
I would like the bot to edit a message to "testtest" if the message contains the word test, but i just get an error.
Click on one of the servers on the left side of your screen and open a text channel. Hover on a message and click the Edit icon from the options that appear on your screen. Alternatively, you can click the ellipsis and select Edit Message from the menu. Type the new message on the field.
Pressing the arrow key up allows you to edit the last message you've written. But it often happens that there is another message after it, but you want to correct the one above it. In my opinion you should be able to edit the message above by pressing the arrow key up once again.
You can use the Message.edit
coroutine. The arguments must be passed as keyword arguments content
, embed
, or delete_after
. You may only edit messages that you have sent.
await message.edit(content="newcontent")
Here's a solution that worked for me.
@client.command()
async def test(ctx):
message = await ctx.send("hello")
await asyncio.sleep(1)
await message.edit(content="newcontent")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With