【问题标题】:Discord Bot Automatic Bulkdelete IssueDiscord Bot 自动批量删除问题
【发布时间】:2019-04-18 09:26:52
【问题描述】:

我正在设置一个 Discord 机器人,它将在 15 分钟的时间间隔内删除特定文本频道中的所有消息,但这些消息不会删除。

Client.on("message", async function(message) {
    if(message.channel.id != "506258018032418817") return;
    setInterval (function () {
        var Trash = message.channel.fetchMessages({ limit: 100 }).then(
        message.channel.bulkDelete(Trash));
      }, 900000); 
});

【问题讨论】:

  • 您是否偶然获得了 Discord API 的链接?如果您不使用await,是否还有理由需要创建函数async?您还在then() 之前缺少.,所以我不确定这是如何工作的。任何控制台错误?
  • 没有错误显示
  • @aug 如果您点击 [discord] 标签,然后点击“了解更多...”,您将找到a link to the Discord API。这适用于大多数标签。
  • @aug 哦,但在这种情况下,这是错误的链接。你会想要Discord.JS documentation, not the Discord API

标签: javascript discord


【解决方案1】:

您正在尝试访问 Trash 变量,但它不包含您认为的内容。 Trash 正在分配 the Promise that represents the end result of the function chain

您应该将传递给then() 的结果用作bulkDelete() 调用的参数。

Client.on("message", async function(message) {
    if(message.channel.id != "506258018032418817") return;
    setInterval (function () {
        message.channel.fetchMessages({ limit: 100 }).then(
           function(deleteThese) { message.channel.bulkDelete(deleteThese); })
      }, 900000); 
});

请记住,此功能的逻辑不合理。伪代码如下:

- 每当有消息发送到此特定频道时 - 排队一个计时器在 15 分钟内发生 - 15分钟后,从频道中删除100条消息

考虑一下如果发生这种情况会发生什么

1:00 Paul talks in channel
--- (timer 1 is started)
1:01 Elizabeth responds
--- (timer 2 is started)
... < time passes > ...
1:14 Charles says something in the channel
... < timer 1 triggers; room is wiped > ...
1:15 Diane says something in response to Charles' deleted message
... < timer 2 triggers; room is wiped > ...
1:16 Charles asks Diane to repeat what she just said

您可能希望更改您的方法以在您的 fetchMessages() 呼叫中消磨时间,以便它仅删除 15 分钟或更早的消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 2021-02-26
    • 2021-11-23
    • 2021-01-28
    • 1970-01-01
    • 2018-05-24
    • 2020-12-03
    相关资源
    最近更新 更多