为什么我的 discord.py 命令不起作用或发送消息

时间:2021-01-16 07:54:49

标签: python-3.x discord discord.py discord.py-rewrite

我有这个编辑狙击命令和事件,如果用户编辑一条消息,它就会狙击它。该事件工作正常并将编辑后的消息发送到私人日志管理通道。但是,当我尝试将其变成一个命令并将其发送到给定的命令通道中时,消息和命令根本不起作用


    @commands.command()
    async def es(self,message_before, message_after):
        embed=discord.Embed(description=f"?**Message sent by** {author} **edited in** {channel}")
        embed.set_author(name= f" ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ {message_before.author.name}#{message_before.author.discriminator}")
        embed.add_field(name="Old message", value=message_before.content, inline=False)
        embed.add_field(name="New message", value=message_after.content, inline=False)
        await message_before.channel.send(embed=embed)
        return

1 个答案:

答案 0 :(得分:1)

你混淆了命令事件

在您的 @Cohenother post 的上一个回答中,他告诉您使用 on_message_edit 事件。此事件 (and many others) 已由 discord.py 库定义,因此它们已提供输入参数。

如果您希望在用户编辑消息时每次发送嵌入,请不要在单独的函数中执行此操作,请将您的代码添加到 on_message_edit 中的代码段中。另一方面,如果您希望能够调用命令(“!es”),例如,谁将检索最后编辑的消息,您将需要创建一个数据库并保存已编辑消息的日志(一个包含 old_messagenew_message 列的表)。

您可以使用 DB Browser for SQLite 创建并手动检查您的数据库,我建议使用异步库,例如 aiosqlite,它与 discord.py

相关问题