From 01fb361bdacb35c84ab0a4fad867b8eb3353a6ce Mon Sep 17 00:00:00 2001 From: AverageHelper <1500092+AverageHelper@users.noreply.github.com> Date: Tue, 7 Jun 2022 20:07:42 -0600 Subject: [PATCH] Fix command deployment (#74) * Don't try to set app command permissions * v1.6.1 --- package-lock.json | 4 ++-- package.json | 2 +- src/actions/prepareSlashCommands.ts | 24 +++++++----------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc77b6f0..47f62b67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gamgee", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gamgee", - "version": "1.6.0", + "version": "1.6.1", "license": "LICENSE", "dependencies": { "@averagehelper/job-queue": "^0.9.5", diff --git a/package.json b/package.json index 4d5d9c96..dab03036 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gamgee", - "version": "1.6.0", + "version": "1.6.1", "description": "A Discord bot for managing a song request queue.", "private": true, "scripts": { diff --git a/src/actions/prepareSlashCommands.ts b/src/actions/prepareSlashCommands.ts index e34cbaaf..7f22ed7e 100644 --- a/src/actions/prepareSlashCommands.ts +++ b/src/actions/prepareSlashCommands.ts @@ -1,6 +1,6 @@ import type Discord from "discord.js"; import type { Command, GuildedCommand, GlobalCommand } from "../commands/index.js"; -import { allCommands, resolvePermissions } from "../commands/index.js"; +import { allCommands } from "../commands/index.js"; import { richErrorMessage } from "../helpers/richErrorMessage.js"; import { useLogger } from "../logger.js"; @@ -19,7 +19,6 @@ async function resetCommandsForGuild(guild: Discord.Guild): Promise { logger.debug(`Clearing commands for guild ${guild.id}...`); if (!testMode) { await guild.commands.set([]); // set guild commands - await guild.commands.permissions.set({ fullPermissions: [] }); // set guild commands } logger.debug(`Commands cleared for guild ${guild.id}`); } @@ -65,19 +64,7 @@ async function preparePrivilegedCommands( logger.debug(`Created command '/${cmd.name}' in guild ${guild.id}`); } - if (cmd.permissions) { - const permissions = Array.isArray(cmd.permissions) - ? await resolvePermissions(cmd.permissions, guild) - : await cmd.permissions(guild); - if (appCommand) { - await appCommand.permissions.set({ permissions }); - logger.debug( - `Set permissions for command '/${cmd.name}' (${appCommand.id}) in guild ${guild.id}` - ); - } else { - logger.debug(`Set permissions for command '/${cmd.name}' in guild ${guild.id}`); - } - } + // TODO: Set default permissions successfulPrivilegedPushes += 1; return appCommand; @@ -122,7 +109,8 @@ async function prepareGuildedCommands( guildCommands: Array, client: Discord.Client ): Promise { - const guilds = [...client.guilds.cache.values()]; + const oAuthGuilds = await client.guilds.fetch(); + const guilds = await Promise.all(oAuthGuilds.map(async g => await g.fetch())); logger.debug(`I am in ${guilds.length} guild${pluralOf(guilds)}.`); logger.verbose( `${guildCommands.length} command${pluralOf(guildCommands)} require a guild: ${JSON.stringify( @@ -144,7 +132,9 @@ async function prepareGlobalCommands( logger.debug( `Creating all ${globalCommands.length} global command${pluralOf(globalCommands)} at once...` ); - await client.application?.commands.set(globalCommands); // set global commands + if (!testMode) { + await client.application?.commands.set(globalCommands); // set global commands + } logger.verbose(`Set ${globalCommands.length} global command${pluralOf(globalCommands)}.`); }