编辑机器人的消息就像你滑动页面一样,discord.py

问题描述

我想通过另一个命令创建一个编辑机器人旧消息的命令,例如:

user: !cmds
bot: *commands list*

user: !next
bot: *edits old message into a new one*

我自己尝试过很多次,但每次都失败了,谁能帮帮我?

我是如何做到的:

@client.command
async def test():
  embed=discord.Embed(title="Page1")
  await ctx.send(embed=embed)

@client.event
async def on_command(message):
    embed2=discord.Embed(title="Page2")
    await client.process_commands(message)
    if message.content == '$next':
        await message.edit(content=embed2)

解决方法

每当调用命令时都会调用 on_command 事件,您没有注册 next 命令,即一秒,on_command 不需要 {{1} } 参数,它需要 message(Context)。

实现您所要求的一个想法是拥有一个带有引用上一条消息的实例变量的 cog,然后在调用 ctx 命令时对其进行编辑。

next

我猜你可以使用全局变量或机器人变量来实现,但在我看来,这是最好的方法。