0

I set up a pre-made Discord Music bot, added some of my own special features and it's been moderately working. I decided to host the bot on a cloud server, because it was only running locally on my PC before

The problem is when I try to start the bot on the cloud server, the console shows the following logs down below. I'm not sure what I need to edit on my code to resolve this issue. I am also going to provide my index.js code.

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);

This is the error message:

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
Toasty
  • 1,850
  • 1
  • 6
  • 21
MrScoloink
  • 29
  • 2
  • 2
    What version of node.js are you on? You must be [above node.js v12](https://stackoverflow.com/questions/59574047/how-to-use-optional-chaining-in-node-js-12) – MrMythical Oct 07 '21 at 12:35
  • 1
    Could you reduce your code to only what's relevant to the problem – Elitezen Oct 07 '21 at 12:35

1 Answers1

1

Remembered the answer to this thanks to MrMythical. When I was first making the bot, I forgot that I came across this same error because I was using the recommended version of Node.js (Version 12.7) instead of the latest version (Version 16.7). I just upgraded to the latest version and it resolved the issue. Booted up no problem. Thanks!

MrScoloink
  • 29
  • 2