我在创建一个Discord Bot时遇到了此错误.typeerror [err_invalid_arg_type]



我在键入节点时遇到了此错误。开始程序。很抱歉,如果这是一个愚蠢的问题,但我才开始编码。我的代码怎么了?

这是针对一个不和谐机器人,我还没有在网上看到有关此问题的任何东西。

const discord = require ('discord.js');
var client = new discord.Client();
const token = 'E440dqHpTt1qTHw4iWB3VgXit7_tcUd4';
client.on ("ready"), () => {
    console.log ("ready!");
    client.user.setGame ("prefix tb")
};
const prefix = "tb"
client.on ('message', function(message) {
    if (message.author.bot) return;
    if (message.content.startsWith (prefix + "hello")) {
        message.reply ("Hi! What's up?");
    }
});
client.login (token);

我以为机器人会启动,但我得到了:

 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 checkListener (events.js:54:11)
    at _addListener (events.js:205:3)
    at Client.addListener (events.js:263:10)
    at Object.<anonymous> (E:Discord Botstylerbottylerbot.js:7:8)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)

从我所看到的,这是代码中的简单错别字。只需更改:

// This
client.on ("ready"), () => {
// Should be
client.on ("ready", () => {

您可以使用client.once而不是client =.on所以它变成

    client.once("ready", () => { 

也永远不会启用您的bot的密码,人们可以使用ur bot,并可能将其漏出

最新更新