用户发送后如何删除命令消息

时间:2021-01-18 00:44:20

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

我需要机器人在发送命令后删除作者的消息

    @commands.command()
    async def dolor(self,ctx):
        await client.delete.message(ctx.message)
        await ctx.send(f"from {ctx.author.name}")
        await ctx.send("https://tenor.com/view/baby-sad-omg-desolated-devastated-gif-9710732")

1 个答案:

答案 0 :(得分:1)

没有client.delete.message()这样的东西。要删除消息,您需要使用 discord.Message 对象中的 delete() 方法。

ctx.message 将为您提供 discord.Message 对象的实例。

因此,您的命令将如下所示:

@commands.command()
async def dolor(self, ctx):
    await ctx.send(f"from {ctx.author.name}")
    await ctx.send("https://tenor.com/view/baby-sad-omg-desolated-devastated-gif-9710732")
    await ctx.message.delete()