TypeError [ERR_INVALID_ARG_TYPE]:“侦听器”参数的类型必须为Function

Shi*_*ino 2 visual-studio node.js discord.js

我在这里有这个小问题:

events.js:200
引发新错误.ERR_INVALID_ARG_TYPE('listener','Function',listener);
^
TypeError [ERR_INVALID_ARG_TYPE]:“侦听器”参数必须为Function类型。 在Object的 Client.addListener(events.js:259:10)的
_addListener(events.js:200:11)
处接收到的类型未定义
。(D:\ Yoshio \ index.js:7:5)
在Module._compile(内部/模块/cjs/loader.js:689:30)
在Object.Module._extensions..js(内部/模块/ cjs / loader)的.js:700:10)
在Module.load(内部/模块/ CJS / loader.js:599:32)
在tryModuleLoad(内部/模块/ CJS / loader.js:538:12)
在Function.Module._load(内部/模块/cjs/loader.js:530:3)
在启动时在Function.Module.runMain(内部/模块/cjs/loader.js:742:12)
(内部/bootstrap/node.js:266:19 )

我搜索了答案,但找不到任何答案,请告诉我该怎么做。
这是我的代码:

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);
Run Code Online (Sandbox Code Playgroud)

And*_*ely 7

从提交的代码中,您将on在将函数作为参数传递之前关闭调用。尝试以下方法:

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);
Run Code Online (Sandbox Code Playgroud)