How come my "message.reply" is not working (Discord.JS)

Viewed 177

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('dotenv').config()
const discord = require('discord.js')
const client = new discord.Client({
    intents: []
    
});


client.login(process.env.TOKEN);


client.on('ready', () => {
    console.log(`${client.user.tag} has logged in`);
});


client.on('message', function(message){
    if(message.content === 'hello') {
        message.reply('hello buddy')
    }
});

The bot in discord has all the permissions required to send messages in the server I am testing it in.

1 Answers

Your bot does not detect messages. You need GUILDS and GUILD_MESSAGES intents

const client = new discord.Client({
    intents: ["GUILDS", "GUILD_MESSAGES"]
})

Also, the message event is deprecated. Use messageCreate instead

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

Note that I used an arrow function. They are cleaner syntax and you should use them in callbacks

Related