Javascript 编码时输入意外结束(app.js:25)
当使用discord.js进行编码时,在我的代码末尾总是有语法错误Javascript 编码时输入意外结束(app.js:25),javascript,discord,discord.js,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.setActivi
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)之后总是有一个错误。有什么帮助吗?您从未用
}关闭ready
事件代码>。一定要经常这样做,或者找一根绳子帮你检查代码 这意味着括号不匹配。告诉你的编辑缩进代码,你可能会看到问题。你缺少与bot.on('message'
和bot.on('ready'
)匹配的}
。打字问题与主题无关,应该标记并关闭,而不是回答。哦,我知道了,我不熟悉堆栈溢出,我道歉