[英]How to make a bot edit its own message in discord.py
有沒有辦法讓機器人編輯自己的消息? 我試圖尋找答案,但找不到。
這將通過代碼完成。 您需要以某種方式在您的機器人程序中執行它。 例如,為它創建一個執行它的命令,然后你可以刪除它。
channel = bot.get_channel(id_of_the_channel)
message = await channel.fetch_message(id_of_the_message)
# make sure that you change "id_of_the_channel" for the id of the channel (as an integer)
# and make sure to change "id_of_the_message" for the id of the message (as an integer)
# you can get those by enabling Developer Mode in the Appearance settings in discord
# and right-clicking on the channel to get its id, and right-clicking on the message to get
# its id as well.
await message.edit(content="the new content of the message")
基本上就是這樣。 通過您的機器人執行這三行代碼,它將編輯消息。
我用另一種方法嘗試了它並且它有效。 我正在使用 nextcord.py 庫。
你可以這樣做:
@bot.event:
async def on_message(message):
if message.content == "Test!":
ctx = await message.reply("Processing!")
await ctx.edit("Test Successful!")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.