说实话,我需要帮助,因为我已经放弃了,因为它应该起作用。我不知道这是discord.js错误还是其他原因,但我找不到问题所在。
const Discord = require('discord.js');
const live = "";
const rmke = "";
module.exports.run = async(bot, message, args) => {
let msg = await message.channel.send("Vote! LIVE RMK ");
await msg.react(live);
await msg.react(rmke);
const reactions = await msg.awaitReactions(reaction => reaction.emoji.name === live || reaction.emoji.name === rmke, {
time: 15000
});
let embed = new Discord.RichEmbed()
.setTitle("Ready")
.setDescription("Results")
.addField("LIVE!", `${live}: ${reactions.get(live).count -1 }`)
.addField("RMK!", `${rmke}: ${reactions.get(rmke).count -1 }`);
message.channel.send({
embed: embed
});
}
module.exports.help = {
name: "vta"
}
(node:8592) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'count' of undefined
at Object.module.exports.run (C:\Users\user\Documents\Mod9z\commands\vota.js:16:60)
(node:8592) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8592) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
答案 0 :(得分:2)
如果没有人做出反应reactions.get(live)
,并且reactions.get(rmke)
将是不确定的,因为您的机器人在awaitReactions
之前做出了反应,因此不会被计算在内。
最简单的解决方法是:
reactions.get(live) ? reactions.get(live).count : 0