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

开发Discord Bot运行报“discord is not refined”及ERR_INVALID_ARG_TYPE错误怎么办

报错根因

你的代码中client.once方法的参数括号位置书写错误:原写法client.once('ready'), () => {将once方法所需的「事件名」「回调函数」两个参数用逗号拆分为了独立表达式,导致once方法仅接收到事件名字符串参数,未收到回调函数参数,因此抛出The "listener" argument must be of type function. Received undefined错误。你提到的“discord is not refined”属于拼写误读,实际就是该语法错误对应的运行提示。

修复方案

将client.once的右括号移动到回调函数的外侧,把两个参数都包裹进方法的入参括号内即可,修正后的完整代码如下:

const Discord = require("discord.js");

const client = new Discord.Client();

client.once('ready', () => {
    console.log('HelloMyFriend is online!');
});

client.login('<token>');

修改后重新运行启动命令,即可正常触发ready事件打印上线日志,完成机器人启动测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.20 09:45:08