Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
Discord Bot Not Receiving Interactions

I'm a relatively experienced developer (graduated recently), trying to get back into discord bots after I made a few a couple of years ago.

I've been following the guide on discordjs.guide, but even with the basic "hello world" style program, I am already stuck.

The program gives no errors when running, but no interactions come through in the console.

  • When I start the script, the bot switches to "online." Curiously, the bot does not switch back to "offline" until I regenerate the token. Not sure if that is related.
  • I've verified process.env.BOT_TOKEN is the correct value.
  • I've confirmed client.login runs successfully.
  • I've tried DMing the bot directly
  • I've tried sending messages on guild channels
  • I've tried @ing the bot

Is there something super obvious I'm not understanding/seeing? Otherwise, what else should I try as a troubleshooting step?

const { Client, Intents } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

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

client.on('interactionCreate', interaction => {
    console.log(interaction);
});

client.login(process.env.BOT_TOKEN);

package.json:

{
    "name": "timebot",
    "version": "1.0.0",
    "description": "",
    "main": "start.js",
    "scripts": {
        "start": "node -r dotenv/config start.js dotenv_config_path=secrets.env",
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "discord.js": "^13.1.0",
        "dotenv": "^10.0.0"
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Turns out, messages are not classified as "interactions" by discord.js. Additionally, you have to specify the intent to listen for messages, otherwise, the event won't be passed to your bot. Here is the revised code with those two critical changes:

const { Client, Intents } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });

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

client.on('interactionCreate', interaction => {
    console.log(interaction);
});

client.on("messageCreate", message => {
    console.log(message);
});

client.login(process.env.BOT_TOKEN);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda