【问题标题】:Discord.py Purge command not purgingDiscord.py 清除命令未清除
【发布时间】:2020-10-27 21:16:22
【问题描述】:

我不知道为什么它不清除它可能只是我很愚蠢,但如果有人能指出这一点,那就太好了,谢谢


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

【问题讨论】:

  • 也许可以试试await message.delete()
  • message.delete() 是一个courotine,所以你必须等待它。

标签: python discord discord.py


【解决方案1】:

感谢 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)```

【讨论】:

    猜你喜欢
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-04
    • 2021-04-14
    • 2011-10-08
    • 1970-01-01
    相关资源
    最近更新 更多