問題描述
如果我的機器人檢測到關鍵字,我想讓我的機器人編輯消息,但我不確定如何編輯消息.
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.
我查看了文檔,但似乎無法弄清楚.我在 python 3.6 中使用 discord.py.
I've looked through the documentation but can't seem to figure it out. I'm using discord.py with python 3.6.
這是代碼:
@bot.event
async def on_message(message):
if 'test' in message.content:
await edit(message, "testtest")
這是錯誤:
File "testthing.py", line 67, in on_message
await edit(message, "test")
NameError: name 'edit' is not defined
如果消息包含單詞 test,我希望機器人將消息編輯為testtest",但我只是收到一個錯誤.
I would like the bot to edit a message to "testtest" if the message contains the word test, but i just get an error.
推薦答案
您可以使用 Message.edit
協程.參數必須作為關鍵字參數 content
、embed
或 delete_after
傳遞.您只能編輯已發送的消息.
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")
這篇關于如何在 discord.py 中編輯消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!