在Python中编辑消息



我希望我的bot发送消息并在一段时间后再次处理它我已经试过了:

@client.command()
async def test(ctx):
await ctx.send ('content')
await asyncio.sleep(3)
await message.edit(content="newcontent")

错误信息:

AttributeError: module 'discord.message' has no attribute 'edit'

我使用如下:

  • Python版本:3.7.4
  • discord.py version 1.6.0

您必须首先定义message

@client.command()
async def test(ctx):
message = await ctx.send("content")
await asyncio.sleep(3)
await message.edit(content="newcontent")

您的代码中有一些错误。一:在您的ctx.send和您的消息('content')之间有一个空格。当前代码:

await ctx.send ('content')

应该改成:

await ctx.send('content')

以上内容不需要更改,尽管有人建议这样做。另外,确保定义message:

message = await ctx.send('content')

然后您可以edit消息:

await message.edit('new_content')

最新更新