Search code examples
javascriptdiscorddiscord.js

my "message.reply" not working (Discord.JS)


So I am learning discord.Js and I am trying to figure out why my message.reply function is not working. I created an event for the bot to listen to messages and when a message with the content of "hello" is sent it should reply with "hello buddy" here is the code :

// Require the necessary discord.js classes
    const { Client, GatewayIntentBits } = require('discord.js');
    const { token } = require('./config.json');
    
    // Create a new client instance
    const client = new Client({ intents: [GatewayIntentBits.Guilds] });
    
    // When the client is ready, run this code (only once)
    client.once('ready', () => {
        console.log('The Bot is ready');
    
    
    
    
    });
    
    
    client.on('messageCreate', (message) => {
        if(message.content === 'hello') {
            console.log('hello buddy')
        }
    })
    
    // Login to Discord with your client's token
    client.login(token);

Solution

  • You need the GuildMessages intent. Remplace this line :

        const client = new Client({ intents: [GatewayIntentBits.Guilds] });
    

    by :

        const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
    

    PS : I suggest you add the GuildMembers event too