The bot turns online and has its status working. However, when i type commands in like "/ping" or "/beep" the bot does not message anything! I gave the bot admin permissions as well
const { Client, Events, GatewayIntentBits } = require("discord.js");
const dotenv = require("dotenv");
dotenv.config();
const prefix = "/";
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
client.user.setActivity("testing");
});
client.on("message", (message) => {
if (message.content === "/ping") {
message.channel.send("Pong.");
} else if (message.content.startsWith("/beep")) {
message.channel.send("Boop.");
}
});
// Log in to Discord with your client's token
client.login(process.env.TOKEN);
2
Answers
You are missing the
GuildMessages
gateway intent which is required for receiving themessageCreate
event.A few things wrong here.
Intents
All Discord Clients (as of discord.js v13) require you to have intents enabled to receive designated events. In the provided code, you will need the following Intents:
GatewayIntentBits.Guilds
GatewayIntentBits.GuildMessages
GatewayIntentBits.MessageContent
(this must be enabled on the Developer Portal!)Client Activity
In the latest versions of discord.js (presuming you’re on discord.js v14), you will need to change how your client activity is set.
Obviously, put that in your Ready event, and import ActivityType.
Message Event
The Message Event has been deprecated since the release of discord.js v13.
Instead, use the "messageCreate" (
Events.MessageCreate
) event.This is to better to work with the "interactionCreate" (
Events.InteractionCreate
) event for things like Slash Commands.I also recommend switching your prefix to something like "!" or "?" because of Slash Commands.
Hope this helps!