在云服务器上运行机器人时意外的令牌'.'



我设置了一个预制的Discord Music bot我给它添加了一些我自己的特殊功能,效果还算不错。我决定将bot托管在云服务器上,因为在

之前它只在我的PC上本地运行问题是当我尝试在云服务器上启动bot时,控制台在下面显示以下日志. 我不确定我需要编辑我的代码来解决这个问题。我还将提供我的index.js代码。
const fs = require('fs');
const Discord = require('discord.js');
const Client = require('./client/Client');
const {token} = require('./config.json');
const {Player} = require('discord-player');
const client = new 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);
}
console.log(client.commands);
const player = new Player(client);
player.on('error', (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`);
});
player.on('connectionError', (queue, error) => {
console.log(`[${queue.guild.name}] Error emitted from the connection: ${error.message}`);
});
player.on('trackStart', (queue, track) => {
queue.metadata.send(`🎶 | Started playing: **${track.title}** in **${queue.connection.channel.name}**!`);
});
player.on('trackAdd', (queue, track) => {
queue.metadata.send(`🎶 | Track **${track.title}** queued!`);
});
player.on('botDisconnect', queue => {
queue.metadata.send('❌ | I was manually disconnected from the voice channel, clearing queue!');
});
player.on('channelEmpty', queue => {
queue.metadata.send('❌ | Nobody is in the voice channel, leaving...');
});
player.on('queueEnd', queue => {
queue.metadata.send('✅ | Queue finished!');
});
client.once('ready', async () => {
console.log('Ready!');
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('Disconnect!');
});
client.on("messageCreate", async (message) => {
if (message.author.bot || !message.guild) return;
if (!client.application?.owner) await client.application?.fetch();
if (message.content === "!deploy" && message.author.id === client.application?.owner?.id) {
await message.guild.commands.set(client.commands).then(() => {
message.reply("Deployed!");
})
.catch((err) => {
message.reply("Could not deploy commands! Make sure the bot has the application.commands permission!");
console.error(err)
});
}
});
client.on('interactionCreate', async interaction => {
const command = client.commands.get(interaction.commandName.toLowerCase());
try {
if (interaction.commandName == 'ban' || interaction.commandName == 'userinfo') {
command.execute(interaction, client);
} else {
command.execute(interaction, player);
}
} catch (error) {
console.error(error);
interaction.followUp({
content: 'There was an error trying to execute that command!',
});
}
});
client.login(token);

这是错误信息:

06.10 21:15:05 [PebbleHost] Received start command
06.10 21:15:05 [PebbleHost] Loading server properties
06.10 21:15:05 [PebbleHost] Starting server!
06.10 21:15:05 [PebbleHost] Loaded config for "NodeJS Bot"
06.10 21:15:05 [PebbleHost] JAR file not found, copying from global JAR directory
06.10 21:15:05 [PebbleHost] Failed to copy jarfile from global JAR directory
06.10 21:15:05 [PebbleHost] Server executable "node" not found, server startup might fail!
06.10 21:15:06 [PebbleHost] Updating eula.txt file
06.10 21:15:06 [Server] Startup 9896dd7d06c465a4660b1a527c7c5e3ea260d00cbf5ad463253ca373e2533630
06.10 21:15:08 [PebbleHost Loader] Checking if 'npm start' command is set up in package.json
06.10 21:15:08 [PebbleHost Loader] Didn't find a start command - will use the main file index.js
06.10 21:15:08 [PebbleHost Loader] ----------------------------------------------
06.10 21:15:08 [Server] Startup /index.js:67
06.10 21:15:08 [Server] Startup if (!client.application?.owner) await client.application?.fetch();
06.10 21:15:08 [Server] Startup ^
06.10 21:15:08 [Server] Startup SyntaxError: Unexpected token '.'
06.10 21:15:08 [Server] Startup at wrapSafe (internal/modules/cjs/loader.js:1047:16)
06.10 21:15:08 [Server] Startup at Module._compile (internal/modules/cjs/loader.js:1097:27)
06.10 21:15:08 [Server] Startup at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
06.10 21:15:08 [Server] Startup at Module.load (internal/modules/cjs/loader.js:977:32)
06.10 21:15:08 [Server] Startup at Function.Module._load (internal/modules/cjs/loader.js:877:14)
06.10 21:15:08 [Server] Startup at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
06.10 21:15:08 [Server] Startup at internal/main/run_main_module.js:18:47
06.10 21:15:09 [PebbleHost] Server shut down (running)
06.10 21:15:09 [PebbleHost] Not restarting crashed server.
06.10 21:15:09 [PebbleHost] Server stopped

感谢神话先生,我记得这个问题的答案了。当我第一次制作机器人时,我忘记了我遇到了同样的错误,因为我使用的是推荐版本的Node.js(版本12.7)而不是最新版本(版本16.7)。我只是升级到最新版本,它解决了问题。启动没有问题。谢谢!

最新更新