编码时输入意外结束(app.js:25)

时间:2018-08-09 16:59:25

标签: javascript discord discord.js

虽然使用discord.js进行编码,但是在我的代码的最后总是存在语法错误

const { Client } = require('discord.js', 'async');
const bot = new Client();
const cfg = require('./config.json');

bot.on('ready', () => {
console.log(Bot Ready on ${bot.guilds.size} servers);

bot.user.setActivity('the member list', {type: 3})

bot.on('message', msg => {
if (msg.author.bot || !msg.content.startsWith(cfg.prefix)) return;
const args = msg.content.slice(cfg.prefix.length).split(' ')
const command = args.shift().toLowerCase();

bot.on(guildMemberAdd, member => {
console.log('User ' + member.user.username + 'has joined the server, adding role')

var role = member.guild.roles.find('name', 'New Member')

member.addRole(role)

console.log(`Args: ${args}\nCommand: ${command}`)
});

bot.login(cfg.token);

这应该为新加入的成员授予“新成员”角色,尽管每当运行代码时,都会引发此错误

C:\Users\Sparxo\Desktop\AutoRole\app.js:25
});
^

SyntaxError: Unexpected end of input
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
[nodemon] app crashed - waiting for file changes before starting...

这显然是我关闭语法的错误,因为bot.login(cfg.token)之后总是存在错误。有帮助吗?

1 个答案:

答案 0 :(得分:0)

您从未用ready关闭});事件。确保始终执行此操作,或者让lint为您检查代码!