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

449
Visualizações
I'm trying to program my first discord bot but its not responding to the command (javascript)

I've been following a video on how to code commands for beginners. I tried this code but it's not responding to the command I checked the permissions no issues there as well. I copied his code all the same and did not also work.

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

const client = new Client( );

client.once('ready' , () => {
    console.log('bot is online');
    
const token = ' Token ';

});


const PREFIX = '!';


client.on('message ' , message=>{

    let args = message.content.substring(PREFIX.length).split(" ");

    switch(args[0]){
        case 'ping':
            message.reply('pong!');
        break;

    }
})






client.login ( token );
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

It should be

client.on('message', //rest of code

instead of

client.on('message ', //rest of code
about 4 years ago · Juan Pablo Isaza Relatório

0

The first thing I would do is to adjust the permissions in your client's declaration.

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

then I would try changing the event listener, the last version deprecated some old events

try

client.on("messageCreate", (message) => {

  let args = message.content.substring(PREFIX.length).split(" ");

  switch(args[0]){
    case 'ping':
      message.reply('pong!');
    break;

  }
});
about 4 years ago · Juan Pablo Isaza Relatório

0

So, I checked your code right now and since you're only running a few commands and nothing crazily advanced, I'd suggest just using an if statement to check the content of the message and IF It meets the condition to return something, here's the code that I tested and It works, It's a lot simpler and easily modifiable. I'd also suggest adjusting the Intents like Armandas Astrauskas said, and you shouldn't declare stuff inside client methods, like the ready one where you declared the token in, AND if you're using discord.js v13 you'd have to use messageCreate.

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

const client = new Client();
const token = ' Token ';


client.on('ready', () => {
  console.log('bot is online');
});


const PREFIX = '!';


client.on('message', message => {

  if (message.content == `${PREFIX}ping`) {
    message.reply("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