![](/img/trans.png)
[英]I'm trying to make a poll command for my discord bot, but it keeps giving me the error: “TypeError: Cannot read property 'push' of undefined”
[英]Trying to make a raffle command for my discord bot but keeps returning the winner undefined
所以我試圖為我的不和諧機器人發出抽獎命令。 我有兩個問題,我想根據誰對此消息做出的反應來使它成為贏家,這是到目前為止我所擁有的
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
是未定義的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.