diff --git a/index.js b/index.js index 3071b35..1da2506 100644 --- a/index.js +++ b/index.js @@ -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, });