首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Discord.js - TypeError:“侦听器”参数必须是一个函数

Discord.js - TypeError:“侦听器”参数必须是一个函数
EN

Stack Overflow用户
提问于 2018-03-03 13:38:25
回答 1查看 1.8K关注 0票数 0

这是我不和谐的机器人代码:

代码语言:javascript
复制
const Discord = require('discord.js');
const client = new Discord.Client();
const token = require('./settings.json').token;

client.on('ready',() => {
    console.log('\n\nI\'m Online, mate.\nVery online, indeed.\n');
});
// Showing (in console) that the bot is online.



var prefix = "-"
client.on('message', message => { // Messaging stuff - Chat commands etc.

    if (!message.content.startsWith(prefix)) return;

    console.log('A command was found.')

    let args = message.content.split(' ').slice(1);
    var argresult = args.join(' ');

    if (message.author.bot) return;
    // If bot is the author (prevent selfbot.)



    if (message.content.startsWith(prefix + 'moffa')) { // Checks if bot is online and shows latency.
        message.channel.send(`**MOFFA!!** \`${Date.now() - message.createdTimestamp} ms delay.\``);
    } else



    if (message.content.startsWith(prefix + 'moos')) { // Cross-server messaging.
        client.channels.get('censored').send('Cross-channel typing is working, yes.');
        message.channel.send('Look in <#censored>.')
    } else



    if (message.content.startsWith(prefix + 'sg')) { // Set game.
        if (!argresult) argresult = null;
        client.user.setActivity(argresult)
        message.channel.send('Set `' + argresult + '` as activity.')
    } else



    if (message.content.startsWith(prefix + 'ss')) { // Set status.
        if(!argresult) argresult = 'online';
        client.user.setStatus(argresult);
        message.channel.send('Updated status.')
    } else



    if (message.content.startsWith(prefix + 'fnname')) { // Sends censored's name on Fortnite.
        message.channel.send('`censored` is <@!censored>\'s name on Fortnite');
    } else



    if (message.content.startsWith(prefix + 'commands')) { // Shows a message with all commands. Update manually.
        message.channel.send('All the current commands are: `moffa`, `fnname` & `commands`. Ex. use: `' + prefix + 'moffa`.');
    }
});


client.login(token);

我知道这个错误:

代码语言:javascript
复制
PS C:\Users\censored\Documents\Code\nodejs\discord bot 2> nodemon
[nodemon] 1.17.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
events.js:239
    throw new TypeError('"listener" argument must be a function');
    ^

TypeError: "listener" argument must be a function
    at _addListener (events.js:239:11)
    at Client.addListener (events.js:297:10)
    at Object.<anonymous> (C:\Users\censored\Documents\Code\nodejs\discord bot 2\app.js:7:8)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
[nodemon] app crashed - waiting for file changes before starting...

它没有指定错误在哪里,也没有指定如何修复错误。

我正在使用Atom (最新版本)。Nodemon允许我在每次刷新机器人时绕开和关闭终端。它工作得很好,直到我尝试制作一个丰富的embed命令。当我删除命令时,我得到了这个错误。嗯,我也在做的时候拿到了。

的帮助将不胜感激。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-03 13:49:32

这部分错误清楚地说明了错误发生在第七行。

代码语言:javascript
复制
    at Object.<anonymous> (C:\Users\censored\Documents\Code\nodejs\discord bot 2\app.js:7:8)

在第7行有client.on(''),它需要第二个参数作为函数。

而且,在这一行中也没有您正在收听的事件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49084740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档