gpt4 book ai didi

node.js - 类型错误 [ERR_INVALID_ARG_TYPE] : The "listener" argument must be of type Function

转载 作者:行者123 更新时间:2023-12-04 22:55:43 38 4
gpt4 key购买 nike

我这里有这个小问题:

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:\Yoshio\index.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)



我搜索了答案,但找不到任何答案,请告诉我该怎么做。
这是我的代码:
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在将函数作为参数传递之前调用。试试这个:

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);

关于node.js - 类型错误 [ERR_INVALID_ARG_TYPE] : The "listener" argument must be of type Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51898056/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com