Hi i created a discord bot with replit in js. The bot has only one command, its to say pong when we say ping. Here is my code
require('dotenv').config(); // Assurez-vous que le fichier .env est chargé
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
]
});
client.once("ready", () => {
console.log("Discord bot is online!");
});
client.on("messageCreate", message => {
// Log des messages reçus pour déboguer
console.log(`Received message: '${message.content}'`);
// Ignore les messages envoyés par le bot lui-même
if (message.author.bot) {
console.log("Message is from a bot. Ignoring.");
return;
}
console.log("Message is not from a bot.");
const trimmedMessage = message.content.trim();
console.log(`Trimmed message: '${trimmedMessage}'`);
const lowercaseMessage = trimmedMessage.toLowerCase();
console.log(`Lowercase message: '${lowercaseMessage}'`);
if (lowercaseMessage === "ping") {
console.log("Received 'ping' message.");
message.channel.send("pong").then(() => {
console.log("Sent 'pong' in response to 'ping'");
}).catch(err => {
console.error("Failed to send 'pong':", err);
});
} else {
console.log(`Message content '${lowercaseMessage}' is not 'ping'.`);
}
});
// Connexion au bot Discord
client.login(process.env.token).catch(err => {
console.error("Failed to login:", err);
});
I just wanted to do that and its created with chatgpt
Its supposed to say pong in the discord channel but nothing appears and the console say “Message content is not ‘ping'”
New contributor
ethan fait des videos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.