TypeError [ERR_INVALID_ARG_TYPE]:“侦听器";参数必须是函数类型 [英] TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function
问题描述
我这里有个小问题:
events.js:200
抛出新的错误.ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^
TypeError [ERR_INVALID_ARG_TYPE]:listener"参数必须是类型功能.接收类型未定义
在 _addListener (events.js:200:11)
在 Client.addListener (events.js:259:10)
在对象.(D:Yoshioindex.js:7:5)
在 Module._compile (internal/modules/cjs/loader.js:689:30)
在 Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
在 Module.load (internal/modules/cjs/loader.js:599:32)
在 tryModuleLoad (internal/modules/cjs/loader.js:538:12)
在 Function.Module._load (internal/modules/cjs/loader.js:530:3)
在 Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
启动时 (internal/bootstrap/node.js:266:19)
events.js:200
throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type undefined
at _addListener (events.js:200:11)
at Client.addListener (events.js:259:10)
at Object. (D:Yoshioindex.js:7:5)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
我搜索了答案,但找不到任何答案,请告诉我该怎么做.
这是我的代码:
I searched for answers but I couldn't find any, please tell me what to do.
Here is my code:
const Discord = require("discord.js");
const TOKEN = "mytoken";
var bot = new Discord.Client();
bot.on("message"), function(message) {
console.log(message.content);
};
bot.login(TOKEN);
推荐答案
从您提交的代码中,您将在将函数作为参数传递之前关闭 on
调用.试试这个:
From the code you submitted, you are closing your on
call before passing the function as an argument. Try this instead:
const Discord = require("discord.js");
const TOKEN = "mytoken"
var bot = new Discord.Client();
/*
* Note the change here, the parenthesis is moved after
* the function declaration so your anonymous function is now
* passed as an argument.
*/
bot.on("message", function(message) {
console.log(message.content);
});
bot.login(TOKEN);
这篇关于TypeError [ERR_INVALID_ARG_TYPE]:“侦听器";参数必须是函数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!