【发布时间】:2020-11-07 05:46:17
【问题描述】:
所以,我像往常一样制作了我的 Discord 机器人,而就在这一刻,这个问题开始无缘无故地出现。它说问题是由行尾引起的,这是我的令牌所在的位置。我不知道到底是什么原因造成的。我什至查看了官方 Discord 文档中的代码,一切都应该是正确的。也许我打错字什么的,不知道。我什至多次重新生成令牌本身并检查它是否正确,但它似乎不起作用。
const fs = require('fs');
const Discord = require('discord.js');
const Client = new Discord.Client();
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
const cooldowns = new Discord.Collection();
Client.on('ready', ()=>{
console.log("ready to go");
});
Client.on('message', message =>{
if (!message.content.startsWith("e!") || message.author.bot) return;
const args = message.content.slice("e!".length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.channel.send('An error happened while trying to execute that command. Consult the owner of the bot for possible fixes.');
}
Client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(ch => ch.name === 'general');
if (!channel) return;
channel.send(`Welcome to the server, ${member}`);
})
Client.login("My token");
【问题讨论】:
-
您能否将完整的错误消息及其堆栈跟踪添加到问题中?
-
SyntaxError: Unexpected end of input [90m at wrapSafe (internal/modules/cjs/loader.js:1054:16)[39m [90m at Module._compile (internal/modules/cjs/loader. js:1102:27)[39m [90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m [90m at Module.load (internal/modules/cjs/loader .js:986:32)[39m [90m 在 Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m [90m 在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main .js:71:12)[39m [90m at internal/main/run_main_module.js:17:47[39md
-
这似乎是库本身的问题,我不确定,因为我对 javascript 很陌生
标签: javascript node.js discord.js