收集结束时的消息

时间:2019-02-03 03:30:23

标签: discord.js

我正在尝试为我的机器人创建一个琐事命令,因此我希望使其能够在收集时间达到“ Times up”之后发送一条消息。
这是我到目前为止写的:

const Discord = require("discord.js")
exports.run = async(client, message, args) => {
  const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, {
    time: 10000
  });
  number = 1;
  var random = Math.floor(Math.random() * (number - 1 + 1)) + 1;
  switch (random) {
    case 1:
      {
        message.channel.send("Case 1");
        collector.on('collect', message => {
          if (message.content == "1") {
            return message.channel.send("Correct!");
          } else {
            message.channel.send("wrong!");
          }
        });
        collector.on('end', message => {
          message.channel.send("times up!")
        });
      }
  }
};

当我这样做时,它说结束事件的发送未定义。

我也在下面尝试过此方法,但是它什么也没做:

const Discord = require("discord.js")
exports.run = async(client, message, args) => {
  const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, {
    time: 10000
  });
  number = 1;
  var random = Math.floor(Math.random() * (number - 1 + 1)) + 1;
  switch (random) {
    case 1:
      {
        message.channel.send("Case 1");

        collector.on('collect', message => {
          if (message.content == "1") {
            return message.channel.send("correct!");
          } else {
            message.channel.send("wrong!");
          }
        });
        collector.stop('end', message => {
          message.channel.send("times up!");
        });
      }
  }
};

我最后尝试的是这个,但是我得到了.stop不确定的内容:

const Discord = require("discord.js")
exports.run = async(client, message, args) => {
  const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, {
    time: 10000
  });
  number = 1;
  var random = Math.floor(Math.random() * (number - 1 + 1)) + 1;
  switch (random) {
    case 1:
      {
        message.channel.send("Case 1");
        collector.on('collect', message => {
          if (message.content == "1") {
            return message.channel.send("correct!");
          } else {
            message.channel.send("wrong!");
          }
        }).stop(["times up"]);
      }
  }
};

此外,在“更正!”之后,我如何才能停止收藏?点吗?

1 个答案:

答案 0 :(得分:0)

尝试使用:

collector.on('end', (collected, reason) => {
          message.channel.send("times up!")
        });

就像在文档中一样:https://discord.js.org/#/docs/main/stable/class/MessageCollector?scrollTo=e-end