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

550
Visualizações
Why won't Discord chatbot in JavaScript respond?

I am working on this simple chatbot following the discord tutorial.

The chatbot has logged in to my server... I type in the chat room on Discord 'ping,' but the chatbot does not respond "Pong" as it should.

Below is the main.js code:

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

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

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

  if (interaction.commandName === 'ping') {
      console.log("we got a hello!")
    await interaction.reply('Pong!');
  }
});

client.login('token');

Note: I have a secret token where it has 'token'

In my Terminal it says Logged in as Quote.it#4979! and my bot is online when I view it in the server in Discord.

But nothing happens when in Discord I write in 'ping'. How can I better diagnose what is going on?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I see a couple of problems here, first, it doesn’t look like you are registering the ping command see here, and second, you don’t have the right intents, you need the GUILD_MESSAGES one see here.

Here’s a simple ping pong bot:

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

const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
    partials: ['CHANNEL', 'MESSAGE'],
})

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

client.on('messageCreate', (message) => {
    if (message.content.startsWith('ping')) {
        message.channel.send('pong!')
    }
})

client.login('token')
about 4 years ago · Juan Pablo Isaza 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