Discord.py清除命令未清除

时间:2020-10-27 04:56:38

标签: python discord discord.py

我不知道为什么不清除它可能只是我很愚蠢,但是如果有人指出这一点,那将非常感谢


@client.command(aliases=["clean"])
@commands.has_permissions(manage_messages=True)
async def purge(ctx, amount: int):
    authors = {}
    async for message in ctx.channel.history(limit=amount + 1):
        if message.author not in authors:
            authors[message.author] = 1
        else:
            authors[message.author] += 1
        message.delete()

    msg = "\n".join([f"{author}:{amount}" for author, amount in authors.items()])
    await ctx.channel.send(msg)
    

1 个答案:

答案 0 :(得分:0)

感谢Benjin和PaxxPatriot,现在它的工作对于清除命令来说有点慢,但是却需要做些什么

@commands.has_permissions(manage_messages=True)
async def purge(ctx, amount: int):
    authors = {}
    async for message in ctx.channel.history(limit=amount + 1):
        if message.author not in authors:
            authors[message.author] = 1
        else:
            authors[message.author] += 1
        await message.delete()

    msg = "\n".join([f"{author}:{amount}" for author,
                     amount in authors.items()])
    await ctx.channel.send(msg)```