删除discord.py中的先前消息

时间:2019-11-30 18:54:56

标签: discord discord.py

我正在创建discord.py机器人(您不说),并且正在创建say 命令。我已经有一些代码了:

async def say_command(self, ctx):
    msg = ctx.message.content
    prefix_used = ctx.prefix
    alias_used = ctx.invoked_with
    text = msg[len(prefix_used) + len(alias_used):]


    if text == '': #user did not enter text


        await ctx.send(content='You need to specify the text!')

        pass
    else: #user did enter text


        #right here is where I want to place the delete command

        await ctx.send(content=f"**{text}**")

        pass

    return
  

我希望能够删除触发命令的消息。

修改: 我尝试使用await delete(msg,delay=None),但这给了我一个错误:

'delete' is not defined

1 个答案:

答案 0 :(得分:0)

尝试一下:

async def say_command(self, ctx):
    msg = ctx.message.content
    prefix_used = ctx.prefix
    alias_used = ctx.invoked_with
    text = msg[len(prefix_used) + len(alias_used):]


    if text == '': #user did not enter text


        await ctx.send(content='You need to specify the text!')

        pass
    else: #user did enter text


        #right here is where I want to place the delete command

        await ctx.send(content=f"**{text}**")

        await ctx.message.delete() # Deletes the command message

        pass

    return