因此,我像往常一样制作了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");
答案 0 :(得分:1)
将此代码放入Visual Studio代码中会立即出现此错误
您似乎已删除文件底部的})
。我建议使用vscode,因为它可以告诉您有关这些错误的信息。
固定代码
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");