You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Discord.js交互时触发TypeError: Cannot read properties of undefined (reading 'reduce')

解决Discord.js交互功能报错:Cannot read properties of undefined (reading 'reduce')

错误信息(中文翻译)

未捕获的类型错误 TypeError: 无法读取undefined的属性'reduce'
    在 BaseInteraction (node_modules\discord.js\src\structures\BaseInteraction.js:106:43)
    在 MessageComponentInteraction (node_modules\discord.js\src\structures\MessageComponentInteraction.js:17:5)
    在 ButtonInteraction (node_modules\discord.js\src\structures\ButtonInteraction.js:9:1)
    在 handle (node_modules\discord.js\src\client\actions\InteractionCreate.js:90:25)
    在 module.exports (node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    在 handlePacket (node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
    在 <anonymous> (node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
    在 emit (node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    在 <anonymous> (node_modules\@discordjs\ws\dist\index.js:1190:51)
    在 emit (node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    在 onMessage (node_modules\@discordjs\ws\dist\index.js:1005:14)
    在 processTicksAndRejections (internal/process/task_queues:95:5)

解决方案

  • 匹配Discord.js版本:这个报错核心原因是代码逻辑与安装的Discord.js版本不兼容。比如用了v14的交互写法却装了v13,直接安装对应版本即可:
    • 安装最新稳定版(v14):npm install discord.js@latest
    • 如需v13版本:npm install discord.js@13.17.1
  • 重置依赖环境:依赖缓存或版本冲突也会引发这类问题,执行以下步骤:
    1. 删除本地的node_modules文件夹和package-lock.json文件
    2. 重新安装所有依赖:npm install
  • 检查交互注册逻辑:确保按钮、选择菜单等交互的注册方式符合当前版本要求,比如v14需通过REST和Routes注册,v13则有不同的注册流程,混用会导致交互数据解析异常。

内容的提问来源于stack exchange,提问作者Elitezen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 15:30:00