0
my code
const Discord = require('discord.js');
const { Client, GatewayIntentBits } = require('discord.js');
const prefix = '$';
const client = new Discord.Client({
'intents': [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages
]
});

client.once('ready', () => {
console.log('- - - - -');
console.log('bot is online!');
console.log('- - - - -');
});

client.on('message', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;

        const args = message.content.split(prefix.length).split(/ +/);
        const command = args.shift().toLowerCase();

        if(command === 'ping'){
        message.channel.send('pong');
    }
    });

client.login('TOKEN');

before i even got my bot online i had a problem with gatewayintentbits and after hours of figuring it out and running my bot it finally got online but when i added my first command it doesnt respond even after chaning prefix and adding multiple gateways i need help

Aloxenツ
  • 3
  • 3

1 Answers1

0

Slash commands are generally recommended instead of text commands nowadays. The event is messageCreate, not message. You probably don't have the message content intent set to true in your Discord Developer Portal. I strongly recommend you follow the official Discord.js guide.

This code should work if you have the message content intent.

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

client.once('ready', () => {
    console.log('- - - - -');
    console.log('bot is online!');
    console.log('- - - - -');
});

client.on('messageCreate', message => {
    if(!message.content.startsWith(prefix) || message.author.bot) return;
 
    const args = message.content.split(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if (command === 'ping'){
        message.channel.send('pong');
    }
});

client.login('TOKEN');

Liz
  • 351
  • 3
  • 9