【发布时间】:2020-04-06 23:26:25
【问题描述】:
我有一个clear 命令设置,我的想法是删除频道中我硬编码的名称的每条消息,但因为我读到该方法只删除 14 天后的消息,所以我想我会必须以某种方式手动检索所有消息,然后使用 delete 方法删除每一条消息。
我环顾四周,但每个示例要么来自 v1.0 之前,要么不像我那样使用带有上下文的命令。
代码:
@self.discord_bot.command()
async def clear(ctx):
try:
if ctx.channel != self.channel_name:
return
# clear history
# retrieve messages using context ctx
# for each loop that deletes them with self.discord_bot.delete()
except Exception as e:
await ctx.trigger_typing()
await ctx.send("Oops something happened! %s" % str(e))
return
提前致谢!
【问题讨论】:
标签: python-3.x bots discord.py