简体   繁体   中英

V13 Discord.JS Bot is not sending messages

This's my code below, I have tried enabling Intents from the developer portal, and I've checked the channel permissions, and my node version is running on v16.14.2, and still, it doesn't send any messages for some reason.

const { Client, Intents } = require("discord.js");
const { token } = require("./config.json");

const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MESSAGES],
});
client.on("ready", () => {
    console.log("Ready");
});

client.on("messageCreate", (message) => {
    if (message === "ping") {
        message.reply({
            content: "pong",
        });
    }
});

client.login(token);

You are comparing an object with a string, the error is in your if() statement:

if(message.content=='ping'){
    message.reply('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