简体   繁体   中英

Discord bot does not respond to my messages (js)

Recently, I have made a Discord bot using node.js and VS Code . I can see my bot being online. However, it does not respond to my messages . (The bot has the required permissions.)
I could not understand the problem, I would be so delighted if you gave me a hand.

Here is my bot.js code

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


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

client.on('message' , message => {
    if(message === 'ping') {
        message.channel.send('Pong!');
    }
})

client.login(config.token);

Here is my config.json code

{
 "token": "I wrote my token in here"
}

Your code dosent work because your not checking for message.content which holds the message's content.

It should be somthing like this:

client.on('message' , message => {
    if(message.content === 'ping') {
        message.channel.send('Pong!');
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM