![](/img/trans.png)
[英]Discord.js Reaction collector failing if no user reacts with first reaction. Cannot read property 'count' of undefined
[英]cannot read property 'count' of undefined discord.js
我正在使用 discord.js 的第 12 版,並且正在制作贈品命令。
let embed = new Discord.MessageEmbed()
.setTitle('Giveaway!')
.setAuthor('Hosted by ' + message.author.username, message.author.avatarURL())
.setDescription('The prize is **' + prize + '**!')
.setTimestamp(Date.now() + ms(args[1]))
.setColor("BLUE")
let m = await channel.send(embed)
m.react("🎉")
setTimeout(() => {
if (m.reactions.cache.get("🎉").count <= 1) {
message.channel.send(`Reactions: ${m.reactions.cache.get("🎉").count}`);
return err('Not enough people reacted!')
}
那是我的代碼,我得到這個錯誤:
if (m.reactions.cache.get("🎉").count <= 1) {
^
TypeError: Cannot read property 'count' of undefined
at Timeout._onTimeout (C:\Users\abhir\Downloads\Tada!\index.js:38:48)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
細節:
操作系統:Windows 家庭 64 位 Node.JS 版本:12 Discord.JS 版本:12.0.0
您應該嘗試在超時完成后重新獲取消息:
let m = await channel.send(embed);
m.react("🎉");
setTimeout(() => {
const message = channel.messages.cache.get(m.id);
const reactions = message.reactions.cache.get("🎉");
if (!reactions) return message.channel.send('No reactions found.');
if (reactions.count <= 1) {
message.channel.send(`Reactions: ${reactions.count}`);
return err('Not enough people reacted!');
}
// Do your stuff
希望這能解決您的問題:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.