Home > Software engineering >  Ping test for a javascript discord bot
Ping test for a javascript discord bot

Time:06-12

enter image description here

I have use this javascript program for my discord bot but when I use the command "!ping" in discord, the bot don't reply

Even if it is online, it does not work

I don't know what I can do for change this

Can I have help ?

CodePudding user response:

In my own bot, i use this code

// A chaque message sur le Discord.
client.on('message', async message => {
    //Définition des variables
    let member = message.author.member;
    if (message.content.startsWith("!ping")) {
        // On envoi un MP avec le Bot
        message.channel.send(`Pong`);
        message.delete();
    }
}

This code is actually ok and use in 3 bots on 5 discords for me. The difference between my code and your, is the

client.on('message', async message =>

CodePudding user response:

The message event has been changed to messageCreate, try changing it to that, also you should use message.member instead of message.author.member. If that doesn't fix anything then the issue is most likely with the startup.

E.g.

client.on('messageCreate', async message => {
    if (message.content === "!ping") {
        message.channel.send(`Pong`);
    }
}
  • Related