所以我试图为我的不和谐机器人发出抽奖命令。我有两个问题,我想根据谁对此消息做出的反应来使它成为赢家,这是到目前为止我所拥有的

const discord = require("discord.js")
const bot = new discord.Client();

module.exports.run = async (bot, message, args) => {
    if (!message.member.hasPermission("MANAGE_CHANNELS")) return message.reply("sorry you dont have permission to use this command"); {
      const embed = new discord.RichEmbed()
        .setTitle('Raffle')
        .addField('React to the message with a thumbs up to enter!', "Time for some fun!")

      message.channel.send(embed).then(function (message) {
        message.react('👍')

      });

      bot.on('messageReactionAdd', (reaction, user) => {
        const user1 = reaction.random

        const embed1 = new discord.RichEmbed()
          .setTitle('Winner!!')
          .addField(`${user1}`, "you are the winner!!")


        message.channel.send(embed1);

        });

    }
}

module.exports.help = {
    name: "Raffle",
    name: "raffle"
}


因此,user1会提前返回不确定的感谢,而且我对JavaScript还是陌生的

最佳答案

在代码中,将user1设置为reaction.random

const user1 = reaction.random


reaction.random不是MessageReaction的有效方法,因此,在发送消息时,user1是未定义的。

关于javascript - 尝试为我的Discord机器人发出抽奖命令,但始终返回未定义的获胜者,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55187144/

10-12 15:11