How do I do to make my bot say something?

Viewed 37

so my code is like that and i wanted to do something that says "pong" when we say "ping". I don't understand why it doesn't work and I'm a begginner, ty !

require('dotenv').config();

const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
    ]
})

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

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

client.login(process.env.DISCORD_TOKEN);
1 Answers

You need to add GatewayIntentBits.GuildMessages to your intents

require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages
    ]
})

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

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

client.login(process.env.DISCORD_TOKEN);

Also you need to enable message content intent But I recommend you to switch to slash commands

Related