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

463
Visualizações
Discord Bot Doesn't reply back (Node.js)

I'ven struggling creating a bot for my discord server so i used the initial code for the discord bot from discordjs.guide and added a simple command to respond to "ping", i wanted to prove what i did wrong before... but i get no response from the bot. I already give it permissions with the invite link and with a role, someone can tell me what's wrong with the code? I installed discord.js and dotenv

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

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

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', function(msg){
    if(msg.content === 'ping'){
        msg.reply('pong');
    }
});

// Login to Discord with your client's token
client.login(token);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your code is missing the GUILD_MESSAGES intent. Simply add it into your intents and your bot should respond to messages. Pay in mind that discord is removing message intents after April 30th so you'd need to go into https://discord.com/developers and into the bot section, turn on message intents.

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

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

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', function(msg){
    if(msg.content === 'ping'){
        msg.reply('pong');
    }
});

// Login to Discord with your client's token
client.login(token);

Pay in mind that discord is removing message intents after April 30th so you'd need to go into https://discord.com/developers and into the bot section, turn on message intents.

about 4 years ago · Juan Pablo Isaza Relatório

0

it's because the client.on("message") has been deprecated

And you should define on your discord client the GUILD_MESSAGES as this

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

and the event to receive the message on your server would be

client.on('messageCreate', function(msg){
    if(msg.content === 'ping'){
        msg.reply('pong');
    }
});

Docs of "messageCreate" event

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