【发布时间】:2020-07-22 17:57:17
【问题描述】:
每当我运行我的机器人代码时,我都会收到 SyntaxError: Unexpected end of input。
我没有看到任何开括号,所以我想知道你们中是否有人能看到这个问题。
我的代码如下:
const request = require('request');
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
if (msg.author.bot) return;
if (msg.content === `${prefix}ping`) {
msg.reply('Pong!');
}
if (msg.content === `${prefix}rule`) {
msg.reply('rules are not yet implemented, check out https://5thsrd.org/ for rules in the meantime');
}
if (msg.content.startswith(`${prefix}spell`)) {
request(`http://www.dnd5eapi.co/api/spells/${args}`, { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
else if (command === 'spell')
msg.channel.send(`Name: ${body.name}`);
msg.channel.send(`${body.desc}`);
msg.channel.send(`At Higher Levels: ${body.higher_level}`)
if (msg.content.startsWith(`${prefix}class`)) {
request(`http://www.dnd5eapi.co/api/classes/${args}`, { json: true }, (err, res, body) => {
if (err) { return console.log(err); }
else if (command === 'class')
msg.channel.send(`Name: ${body.name}`);
msg.channel.send(`Hit Dice:${body.hit_die}`);
msg.channel.send(`Proficiency Options: ${body.proficiency_choices}`);
msg.channel.send(`Starting Equipment: ${body.starting_equipment}`);
msg.channel.send(`Proficiencies: ${body.proficiencies}`);
msg.channel.send(`Subclasses: ${body.subclasses}`);
});
}
})
}
});
client.login(token);
【问题讨论】:
标签: javascript node.js discord.js