Discord.js Bot赠品命令:embedSent.reactions.get不是函数

时间:2020-05-29 13:03:36

标签: javascript bots discord

我正在尝试发出一个Discord.js赠品命令来发送嵌入,将其保存到变量embedSent中,然后使用reactions.get()方法在TimeOut之后收集响应,但是我一直收到错误{{1 }}这是我的代码的一部分:

TypeError: embedSent.reactions.get is not a function

1 个答案:

答案 0 :(得分:0)

好吧,将近两个月后,我终于弄明白了。完整的有效命令(DiscordJS v12):

if (command == "giveaway") {
    // !giveaway {time s/m/d} {item}
    const messageArray = message.content.split(" ");
    if (!message.member.hasPermission(["ADMINISTRATOR"])) return message.channel.send("You don't have enough permissions to start a giveaway !")
    var item = "";
    var time;
    var winnerCount;
    for (var i = 1; i < args.length; i++) {
      item += (args[i] + " ");
    }
    time = args[0];
    if (!time) {
      return message.channel.send(`Invalid duration provided`);
    }
    if (!item) {
      item = "No title"
    }
    var embed = new Discord.MessageEmbed();
    embed.setColor(0x3333ff);
    embed.setTitle("New Giveaway !");
    embed.setDescription("**" + item + "**");
    embed.addField(`Duration : `, ms(ms(time), {
      long: true
    }), true);
    embed.setFooter("React to this message with ? to participate !");
    var embedSent = await message.channel.send(embed);
    embedSent.react("?");

    setTimeout(async () => {
      try{
        const peopleReactedBot = await embedSent.reactions.cache.get("?").users.fetch();
        var peopleReacted = peopleReactedBot.array().filter(u => u.id !== client.user.id);
      }catch(e){
        return message.channel.send(`An unknown error happened during th draw of the giveaway **${item}** : `+"`"+e+"`")
      }
      var winner;

      if (peopleReacted.length <= 0) {
        return message.channel.send(`Not enough participants to execute the draw of the giveaway **${item}** :(`);
      } else {
        var index = Math.floor(Math.random() * peopleReacted.length);
        winner = peopleReacted[index];
      }
      if (!winner) {
        message.channel.send(`An unknown error happened during th draw of the giveaway **${item}**`);
      } else {
        console.log(`Giveaway ${item} won by ${winner.toString()}`)
        message.channel.send(`? **${winner.toString()}** has won the giveaway **${item}** ! Congratulations ! ?`);
      }
    }, ms(time));
}

希望对您有所帮助!