删除discord.py中的消息Discord bot

我用Python 3.6 IDLE编写了一个机器人,我想添加一个 purge 命令,但我不知道如何添加它 . 有些人可以帮我提供任何示例或建议我会很高兴谢谢 .

回答(2)

2 years ago

@bot.command(pass_context=True)
async def purge(ctx, amount):
    await bot.purge_from(ctx.message.channel, limit=amount)

相当肯定会有用 .

2 years ago

@client.command(pass_context = True, aliases=['Clear'])
async def clear(ctx, number):
    mgs = [] #Empty list to put all the messages in the log
    number = int(number) #Converting the amount of messages to delete to an 
    integer
    async for x in client.logs_from(ctx.message.channel, limit = number):
        mgs.append(x)
    await client.delete_messages(mgs)