【发布时间】:2020-10-23 03:45:08
【问题描述】:
我使用的是 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 Home 64 位 Node.JS 版本:12 Discord.JS 版本:12.0.0
【问题讨论】:
-
变量
m是一个新创建的消息对象,它在某个通道中发送。您还没有编写任何检索反应的逻辑。您正在引用缓存,但那是旧的。在创建消息时,它没有任何反应。因此,当您尝试找到它时,它不会返回任何内容。 -
虽然我有一个 setTimeout(),所以 1 分钟后它应该只会触发。
-
没关系。变量
m是创建消息时的消息对象。它没有任何反应。您需要刷新该变量以反映其当前状态。这是一个协程,您没有在代码中执行另一个await语句。我对 discord.js 不太熟悉,因此无法为您提供完整的解决方案,但我知道您至少缺少另一个await语句,该语句从特定消息中检索当前反应。 -
我试过了,还是不行。
标签: javascript caching discord discord.js typeerror