My bot is online everything is fine, code doesn't have a problem but won't respond to me?

Hello, I created A discord bot everything is working fine, the bot is online
but doesn’t respond to command his prefix is ‘C!’. the command is
‘C!ping’ and he should respond with ‘pong!’ but he doesn’t. I am using node.js
The code:
const Discord = require(‘discord.js’);

const client = new Discord.Client();

const prefix = ‘C!’;

client.once(‘ready’, () => {

console.log(‘Chill Lounge is online!!’);

});

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(‘MY TOKEN’);

if(message.content.startsWith(prefix) || message.author.bot) return;

This means that if the message does begin with the prefix, it’ll return and nothing will happen. You want to check if the message doesn’t begin with the prefix:

if(!message.content.startsWith(prefix) || message.author.bot) return;

Notice the !: this means not and should make everything work fine.

it Works now Thank you! but Another thing is wrong now when do the command he responds 5 times ‘pong!’

Intenta resetear el token, y vuelve a intentar

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.