简体   繁体   English

如何让机器人在 discord.py 中编辑其消息?

[英]How to make a bot edit its message in discord.py?

I've tried looking at other solutions but they havent worked for me.我试过查看其他解决方案,但它们对我不起作用。 What im trying to do is make the bot edit its own message at a slight delay.我试图做的是让机器人稍微延迟编辑自己的消息。

  if message.content.startswith('(dev)messageedit'):
    await message.channel.send('old message')
    time.sleep(1)
    await message.edit('new message')

The error im getting is:我得到的错误是:

TypeError: edit() takes 1 positional argument but 2 were given

It would be great if you could help me!如果你能帮助我就太好了!

If you take a look at the docs, you'll see that you need to specify what you are editing in the message.如果您查看文档,您会发现您需要在消息中指定您正在编辑的内容。 In your case that would be the content .在您的情况下,这将是content

https://discordpy.readthedocs.io/en/master/api.html?highlight=edit#discord.Message.edit https://discordpy.readthedocs.io/en/master/api.html?highlight=edit#discord.Message.edit

await message.edit(content='new message')

I am not sure from your question if you want to edit the message you send first with old_message , but if you do, you would also need to define it first:我不确定您的问题是否要编辑您首先使用old_message发送的消息,但如果您这样做,您还需要先定义它:

old_message = await message.channel.send('old message')

await old_message.edit(content='new message')

Also, sidenote, I would recommend using asyncio.sleep instead of time.sleep , since time.sleep is blocking your bot from doing other things.此外,阿里纳斯,我会建议使用asyncio.sleep代替time.sleep ,因为time.sleep从做其他事情阻止你的机器人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM