1

my discord.js bot has version 13.1.0, and my node's version is 16.7.0. I entered these commands in the terminal : npm init to create package.json and npm install discord.js to install discord package.

I writed the code in index.js, and I created config.json to put the token there.

When I run then the code it shows me 'Ready!' in the console and being online in Discord. I also can change the status and the activity of the bot without a problem. The problem here is the bot doesn't send or reply to a message.

Here's the code bellow

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

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

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

client.on ('messageCreate', (message) => {
    if (message.content === 'hello') {
        message.reply('Hello')
    };
});

client.login(token);

this's config.json's code just in case.

{
    "token": "my_bot_token!"
}
MunJitso
  • 23
  • 2
  • 10
  • If you put a `console.log("test")` inside your `messageCreate` listener, does anything get logged when a user types a message? – theusaf Aug 26 '21 at 20:04
  • Have you tried changing `messageCreate` to `message` in your `client.on()` event? – WoJo Aug 26 '21 at 20:08
  • @WoJo `message` was changed to `messageCreate` in v 13 https://discordjs.guide/additional-info/changes-in-v13.html#naming-conventions – Andy Bonner Aug 26 '21 at 20:11
  • @AndyBonner aha, must have missed that. Thanks. – WoJo Aug 26 '21 at 20:11
  • i tried this but it doesn't give any result – MunJitso Aug 26 '21 at 20:42
  • 2
    Does this answer your question? "[message event listener not working properly](https://stackoverflow.com/q/64394000/90527)", "[Having trouble sending a message to a channel with Discord.js](https://stackoverflow.com/q/68795635/90527)", "[Discord bot is not replying to messages](https://stackoverflow.com/q/68804831/90527)". – outis Oct 30 '21 at 22:20

1 Answers1

4

The issue is caused by missing intents. To listen to messages, you need to specify the GUILD_MESSAGES flag:

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
theusaf
  • 1,781
  • 1
  • 9
  • 19
  • it worked with this code :)), i have another problem this is just a example to make people understand easily. my another problem is when i tried to add ur answer in my main bot project that contains commands and events handlers but it doesn't work there, even if i turn on `applications.commands` in the OAuth2 of the bot – MunJitso Aug 26 '21 at 20:29
  • If the current issue has been solved the user who answered deserves a checkmark on their answer. Consider posting a new question if you have a new issue – Elitezen Aug 26 '21 at 22:53
  • i posted the other issue now. i got an answer but it doesn't work – MunJitso Aug 27 '21 at 07:50