Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My discord bot is not responding even though there is no error

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

const config = require('./config.json');

client.once('ready', () => {
    console.log("go");
})

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

    if(message.content == "ping"){
        message.channel.send("pong");
    }
})

client.login(config.token);

There is no error in the code, but when I type ping, the bot does not respond, does anyone know why?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It’s because you don’t have the GUILD_MESSAGES intent enabled !

Replace that line :

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

with

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

As you can see from the official documentation :

GUILD_MESSAGES intent let us have events and one of them is MESSAGE_CREATE (emits when a message is created (sent))

Guild messages > Message create

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading