首页 > 解决方案 > 如何使用 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)

我该如何解决这个问题?

标签: javascriptdiscorddiscord.js

解决方案


错误清楚地描述了它,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) {
}

推荐阅读