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,所以您必须等待它。