From 8785d0c715980189c511b518781deaab6744cb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sat, 21 Aug 2021 17:55:10 +0300 Subject: [PATCH] Updated commands.js --- src/client/commands.js | 54 ++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/client/commands.js b/src/client/commands.js index 5736875..b3605b6 100644 --- a/src/client/commands.js +++ b/src/client/commands.js @@ -1,41 +1,53 @@ const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9'); -const { token } = require('../config.js'); +const { token, version } = require('../config.js'); const fs = require('fs'); const path = require ('path'); module.exports = { - async execute(clientId) { + async execute(client) { const commands = []; const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js")); - // Place your client and guild ids here - const guildId = '530811780893507596'; - for (const file of commandFiles) { - const command = require(`./commands/${file}`); - commands.push(command.data.toJSON()); + const command = require(`./commands/${file}`); + commands.push(command.data.toJSON()); } const rest = new REST({ version: '9' }).setToken(token); (async () => { - try { - console.log('Started refreshing application (/) commands.'); + try { + console.log('Started refreshing application (/) commands.'); - await rest.put( - Routes.applicationCommands(clientId), - { body: commands }, - ); - await rest.put( - Routes.applicationGuildCommands(clientId, guildId), - { body: commands }, - ); + if(version.includes("-dev")){ + await rest.put( + Routes.applicationCommands(client.user.id), + { body: [] }, + ); - console.log('Successfully reloaded application (/) commands.'); - } catch (error) { - console.error(error); - } + let guilds = await client.guilds.fetch(); + guilds.forEach(async guild => { + try { + await rest.put( + Routes.applicationGuildCommands(client.user.id, guild.id), + { body: commands }, + ); + } catch (DiscordAPIError) { + + } + }); + } else { + await rest.put( + Routes.applicationCommands(client.user.id), + { body: commands }, + ); + } + + console.log('Successfully reloaded application (/) commands.'); + } catch (error) { + console.error(error); + } })(); } } \ No newline at end of file