Search code examples
javascriptdiscorddiscord.jsreplit

Repl.it discord.js bot doesn’t go online


I was hosting a discord.js bot on repl.it and at the beginning it worked fine. I had an easy ping-pong example, which worked too. But now, as I added code, it stopped working. When I run it, the program shows the usual Example app listening at http//local host:3000, but the ready client event doesn’t get triggered, and I don’t get any errors.
I don’t understand what’s the problem.
Here is my code:

const { token } = require('./config.json');
const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => res.send('Hello World!'));

app.listen(port, () => console.log(`Example app listening at http://localhost:${port} `));

const { Client, Events, GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
  ],
});

client.once(Event.ClientReady, () => {
  console.log('Events Ready!');
});

client.on("debug", ( e ) => console.log(e));
client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate', async Message => {
  const msg = Message.content;
  const prefix = msg.substring(0, 2);
  if (prefix != 'k!') { return; }
  const args = msg.substring(2, msg.length).split(' ');
  switch (args[0]) {
    case 'ping':
      Message.channel.send('Pong');
      break;
    case 'repling':
      Message.reply('Replong');
      break;
    case 'beep':
      Message.author.send('boop');
      break;
    default:
      Message.channel.send('command not defined');
  }
  if (args[0] == "ping") {
    Message.channel.send('Pong.');
  }
});

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isCommand()) return;

  if (interaction.commandName === 'slash-ping') {
    await interaction.reply('slash-pong');
  }
});

client.login(token);

And here is the output: repl.it_output

Thanks in advance, Opilite.
UPDATE: ´Now it works, but I would still know why it didn’t worked. And I think that it is randomly working or not working


Solution

  • This might not be the case for you but I got a message similar to that when my bot got rate limited, could this be the case?

    Also repl sometimes has moments where it takes ages to start the bot. I know from experience but it will eventually happen.