update guild id in index.js

This commit is contained in:
Ayden Jahola 2024-09-25 23:34:35 +01:00
parent 2600ab8523
commit 697fe198d7
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -9,6 +9,7 @@ const {
const mongoose = require("mongoose");
const fs = require("fs");
const path = require("path");
const ServerSettings = require("./models/ServerSettings");
const client = new Client({
intents: [
@ -18,8 +19,6 @@ const client = new Client({
],
});
const GUILD_ID = process.env.GUILD_ID;
client.commands = new Collection();
// Function to recursively read commands from subdirectories
@ -63,7 +62,17 @@ client.once("ready", async () => {
const rest = new REST({ version: "10" }).setToken(process.env.BOT_TOKEN);
// Fetching the guild ID from MongoDB
let GUILD_ID;
try {
const serverSettings = await ServerSettings.findOne();
if (serverSettings) {
GUILD_ID = serverSettings.guildId;
} else {
console.error("No server settings found in MongoDB.");
return;
}
await rest.put(Routes.applicationGuildCommands(client.user.id, GUILD_ID), {
body: commands,
});