删除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

gtopds 回答:删除discord.py中的先前消息

尝试一下:

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
本文链接:https://www.f2er.com/3001610.html

大家都在问