javascript - 如何使用 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)
我该如何解决这个问题?
解决方案
错误清楚地描述了它,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) {
}
推荐阅读
- python - Web 或代理服务器可以在没有 User-Agent 的情况下检测请求者的操作系统吗?
- javascript - 如果在创建新文档时有一个抛出异常,则回滚两个文档中的持久性?
- python - 将 sounddevice 导入 python 崩溃
- python - 根据指定列中的字符串值条目是否包含子字符串来分隔熊猫数据框
- python-3.x - IDLE 表示每个打印语句末尾的双引号是无效的语法。怎么了?
- mysql - MySql 备份最近更新/插入的数据
- docker - 两个 docker 容器无法通信
- github - github 操作 - npm 安装失败,退出代码 1
- laravel - Laravel - 注册后重定向到带有数据的路由
- github - “Fetch”的 DataPower SSL 配置导致“无法获取 SSL 配置文件”