如何使用discord.js赠品命令

时间:2020-05-31 18:39:13

标签: javascript discord discord.js

我的代码是:

C:\Users\xdswe\Desktop\Zero\src\commands\Testing\GIveaway.js:42
          if (m.reactions.cache.get("�").count <= 1) {
                                         ^

那是错误消息:

TypeError: Cannot read property 'count' of undefined
    at Timeout._onTimeout (C:\Users\xdswe\Desktop\Zero\src\commands\Testing\GIveaway.js:42:42)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

如何解决该问题?

1 个答案:

答案 0 :(得分:0)

错误清楚地描述了它,m.reactions.cache.get("�")是未定义的,无论哪种方式都不是您获得表情符号数量的方法,使用<cache>.get("")只是使用给定的字符串访问集合

方法如下:

const emoji = m.reactions.cache.find(f => f === "�");
const users = emoji && emoji.users;
const amount = users && users.size;
if(amount && amount <= 1) {
}