From 697fe198d778d6ebc962f0437975d571b71358b7 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Wed, 25 Sep 2024 23:34:35 +0100 Subject: [PATCH] update guild id in index.js --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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, });