Home > Software design >  Discordbot with Javascript not reacting
Discordbot with Javascript not reacting

Time:11-11

im currently learning to code discordbots with node.js. For some reason the bot goes online but dont react to the commands ive coded. To test reasons ive even took the solution from a tutorial but still the same problem. Does anybody know a solution?

const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
    console.log('BOT ist online');
});

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

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

    if(command === 'ping'){
        message.channel.send('pong!');}
    else if(command == 'youtube'){
        message.channel.send('TEST');}
    });
client.login('Here goes the token');

CodePudding user response:

This is a small fix so I would just comment if I could but I’m not able to yet.

Where you’re doing:

client.on(‘Message’, …)

It should be a lowercase “m” on message like this:

client.on('message', msg => {
  if (msg.content === 'ping') {
     msg.reply('Pong!');
  }
});
  • Related