繁体   English   中英

Discord.py清除命令中的人员列表和删除的消息数

[英]Discord.py The list of people and the number of deleted messages in purge command

你知道如何做这样的事情吗? 我的意思是人员列表和已删除邮件的数量: 截屏
(来源: supportstartit.pl

    @bot.command(aliases=["purge"])
    @commands.has_permissions(manage_messages=True)
    async def clear(ctx, amount: int):
        await ctx.channel.purge(limit=amount + 1)
        embed = discord.Embed(title=f"`{amount}` messages were removed.", description="", color=0xff0000)
        await ctx.send(embed=embed, delete_after=2)

您可以迭代而不是使用清除,例如:

@bot.command(aliases=["purge"])
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount: int):
    authors = {}
    async for message in ctx.channel.history(limit=amount):
        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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM