我刚开始用hikari编写代码,我在查看文档时遇到了困难。我不明白如何使我的机器人大量删除/清除消息。
任何帮助都很感激,
a_twoyearold14
发布于 2022-04-14 15:54:51
大规模删除消息需要两个步骤:
前者使用消息完成,后者跨请求的消息返回一个LazyIterator。对不和谐API的一个警告是,超过14天的消息不能大量删除-因此,我们将仅将LazyIterator的返回限制在最后14天:
# Where channel ID is the channel you are deleting the messages from
messages = (
await bot.rest.fetch_messages(channel_id)
.take_until(lambda m: datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=14) > m.created_at)
.limit(count) # Limit the messages to the amount you want deleted
)然后,我们可以将获取的消息传递到消息,以便批量删除它们:
# Where channel ID is the channel you are deleting the messages from
await bot.rest.delete_messages(channel_id, messages)您可以看到使用hikari灯泡这里的完整示例。
https://stackoverflow.com/questions/70976740
复制相似问题