Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py清除命令未清除_Python_Discord_Discord.py - Fatal编程技术网

Python Discord.py清除命令未清除

Python Discord.py清除命令未清除,python,discord,discord.py,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):

我不明白为什么它不清除它可能是我只是愚蠢,但如果有人能指出这将是伟大的感谢


@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)
    

多亏了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)```

也许可以尝试等待消息。delete()
消息。delete()
是一个courotine,所以您必须等待它。