【问题标题】:How to execute a command when the timer is up定时器到时如何执行命令
【发布时间】:2019-05-25 11:07:34
【问题描述】:

我最近一直在处理我在这里找到的代码: Discord.js reply to message then wait for reply

我想知道当计时器关闭而没有任何响应时,脚本是否有任何方法可以运行命令。

我尝试将命令放在收集器的代码块之外 我试过输入if (timer > 10000),但没有用。

if (command === 'spec') {
  message.author.send("See or Change?");
  const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, {
    time: 10000
  });
  console.log(collector);
  collector.on('collect', message => {
    if (message.content == "See") {
      message.channel.send("You Want To See Someones Spec OK!");
    } else if (message.content == "Change") {
      message.channel.send("You Want To Change Your Spec OK!");
    }
  });
}

当时间结束时,我希望脚本更改使用它的用户的昵称。

【问题讨论】:

    标签: timer bots discord discord.js


    【解决方案1】:

    您可以收听收集器的end event 并检查收集到的消息的大小。

    collector.on('end', collected => {
      if (collected.size === 0) {
        // do something
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多