奇怪 "count property undefined"
weird "count property undefined"
我需要这方面的帮助,老实说,我已经放弃了,因为它应该有用。我不知道这是 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.
如果没有人做出反应,reactions.get(live)
和 reactions.get(rmke)
将是未定义的,因为您的机器人在 awaitReactions
之前做出反应,因此不会被计算在内。
处理此问题的最简单方法是:
reactions.get(live) ? reactions.get(live).count : 0
我需要这方面的帮助,老实说,我已经放弃了,因为它应该有用。我不知道这是 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.
如果没有人做出反应,reactions.get(live)
和 reactions.get(rmke)
将是未定义的,因为您的机器人在 awaitReactions
之前做出反应,因此不会被计算在内。
处理此问题的最简单方法是:
reactions.get(live) ? reactions.get(live).count : 0