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);
我收到此错误:
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是允许我每次刷新机器人时绕过必须打开和关闭终端的东西。 它工作正常,直到我尝试制作丰富的嵌入命令。 当我删除命令时,我收到了这个错误。 好吧,我在制作它时也得到了它。
帮助将不胜感激。谢谢!
答案 0 :(得分:1)
这部分错误清楚地表明错误发生在第七行。
at Object.<anonymous> (C:\Users\censored\Documents\Code\nodejs\discord bot 2\app.js:7:8)
你在第7行有client.on('')
,它需要第二个参数作为函数。
此外,您没有在该行中收听的事件。