gpt4 book ai didi

python - Discord.py purge 命令中的人员列表和已删除消息数

转载 作者:行者123 更新时间:2023-12-01 07:24:37 30 4
gpt4 key购买 nike

你知道如何做这样的事情吗?我的意思是人员列表和已删除消息的数量:

4 messages were removed.

Qbiczeg#9999: 3
Bot#2275: 1
    @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)

关于python - Discord.py purge 命令中的人员列表和已删除消息数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57516325/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com