如何使用Discord bot删除频道中的所有邮件

2024-04-26 13:17:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做的是,当发送指定的命令“m!clear”时,bot将删除该通道中的所有消息(或特定数量)。我已经有了if message.content.startswith('m!clear):,但我不知道下一部分该做什么


Tags: 命令消息message数量ifbotcontentclear
1条回答
网友
1楼 · 发布于 2024-04-26 13:17:33

删除所有的信息不是很好。我可以与您共享删除特定数量邮件的代码

@bot.command()
@commands.has_permissions(manage_messages=True) 
#only those with the permission to manage messages can use this command

async def clear(ctx, amount: int):
    await ctx.channel.purge(limit=amount + 1)
    await ctx.send(f"{amount} message(s) got deleted")

要使用此选项,请使用[command][value] i、 e:清除10

相关问题 更多 >