python - Discord.py purge 命令中的人员列表和已删除消息的数量
问题描述
你知道怎么做这样的事情吗?我的意思是人员列表和已删除消息的数量:(
来源: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)
解决方案
您可以迭代而不是使用 purge 例如:
@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 - 使用 python/pandas 将数据框展平并加宽?
- django - Django Rest 框架非空约束
- r - GloVe - R 中的下标越界错误
- python - predict_generator 的输出是什么意思?
- python - 如何在python中调用类方法?
- javascript - 选择下拉值后重定向
- tensorflow - Tensorflow 2.x:如何使用 numpy 手动分配卷积权重
- r - R AOV 不会做两个变量之间的交互
- flutter - 如何在 dart 中的 built_value 序列化中将 Date ISO 字符串反序列化为 DateTime 对象?
- java - GrantedAuthority 导致 JSON 映射异常