【问题标题】:Unexpected token '.' when running bot on a cloud server意外的标记 '。'在云服务器上运行机器人时
【发布时间】:2021-10-07 21:53:11
【问题描述】:

我设置了一个预制的 Discord 音乐机器人,添加了一些我自己的特殊功能,并且运行正常。我决定将机器人托管在云服务器上,因为它之前只在我的 PC 上本地运行

问题是当我尝试在云服务器上启动机器人时,控制台显示以下日志在下面。我不确定我需要在我的代码上编辑什么来解决这个问题。我还将提供我的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?你必须是above node.js v12
  • 您能否将您的代码缩减为仅与问题相关的代码

标签: javascript discord.js


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-04-16
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    相关资源
    最近更新 更多