Hello, I am new to starting a discord bot project with the slash commands. I am trying to use some code from an old bot of mine to try and set the presence on my new bot. When launching, I get the console message and my bot goes online… status does not set.
The documentation I have been following:
Discord documentation
Here is my code below:
botpresence.cjs
const {
Discord,
Client,
Intents,
GatewayIntentBits,
ActivityType,
} = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
],
});
module.exports.namedCjsExport = function namedCjsExport() {
client.once("ready", () => {
client.user.setPresence("Watching Dev", { type: "WATCHING" });
setInterval(() => {
client.user.setPresence("Watching Dev", { type: "WATCHING" });
}, 60000);
});
};
console.log("Bot is online!");
client.login(
"TOKEN"
);
app.js
import defaultCjsExport, { namedCjsExport } from './botpresence.cjs';
namedCjsExport()
import "dotenv/config";
import express from "express";
import { InteractionType, InteractionResponseType } from "discord-interactions";
import {
VerifyDiscordRequest,
getRandomEmoji,
DiscordRequest,
} from "./utils.js";
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json({ verify: VerifyDiscordRequest(process.env.PUBLIC_KEY) }));
app.post("/interactions", async function (req, res) {
const { type, id, data } = req.body;
if (type === InteractionType.PING) {
return res.send({ type: InteractionResponseType.PONG });
}
if (type === InteractionType.APPLICATION_COMMAND) {
const { name } = data;
if (name === "test") {
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Finally online and responding " + getRandomEmoji(),
},
});
}
if (name === "test2") {
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Going in for a second command",
},
});
}
}
});
app.listen(PORT, () => {
console.log("Listening on port", PORT);
});