I have an issue with this:
I run the script quite smoothly in the command prompt, but when I type "hello" in the discord server, no replies are coming back. Do you have any idea?
The permission rights are in order for the bot and are as well online. Any suggestion?
console.log("Beep Beep");
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login("TOKEN");
client.on("ready", readyDiscord);
function readyDiscord() {
console.log("ok");
}
client.on("message", gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if (msg.content === "Hello") {
msg.reply("Hi");
}
}
Summarizing:
In Discord.js v14, the message
event was changed to messageCreate
. If your permissions are set up correctly and you have privileged intents enabled for message content, then this is probably the root of your issue. Just change it accordingly in your .on()
event handler registration:
console.log("Beep Beep");
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login("TOKEN");
client.on("ready", readyDiscord);
function readyDiscord() {
console.log("ok");
}
client.on("messageCreate", gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if (msg.content === "Hello") {
msg.reply("Hi");
}
}