如果我的机器人检测到关键字,我想让我的机器人编辑消息,但我不确定如何编辑消息。我浏览了文档,但似乎无法弄清楚。我在 python 3.6 中使用 discord.py。这是代码:@bot.eventasync 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”,但我只是收到一个错误。
                    
                    
                3 回答
 
                    
                    
                            ITMISS
                            
                                
                            
                        
                        
                                                
                    TA贡献1871条经验 获得超8个赞
您可以使用Message.edit协程。参数必须作为关键字参数传递content,embed或delete_after。您只能编辑已发送的消息。
await message.edit(content="newcontent")
 
                    
                    
                            哔哔one
                            
                                
                            
                        
                        
                                                
                    TA贡献1854条经验 获得超8个赞
这是一个对我有用的解决方案。
@client.command()
async def test(ctx):
message = await ctx.send("hello")
await asyncio.sleep(1)
await message.edit(content="newcontent")
 
                    
                    
                            繁星coding
                            
                                
                            
                        
                        
                                                
                    TA贡献1797条经验 获得超4个赞
你做了这个了吗:
from discord import edit
或这个:
from discord import *
在使用 message.edit 功能之前?
如果你这样做了,问题可能出在你的 discord.py 版本上。试试这个:
print(discord.__version__)
添加回答
举报
0/150
	提交
		取消
	