kyle13
kyle13
SIASapphire - Imagine a framework
Created by kyle13 on 4/5/2023 in #sapphire-support
Handling deletion of all guild specific slash commands with BulkOverwrite
I've been using BulkOverwrite to manage slash commands for guilds and use the ApplicationCommandRegistryRegisterOptions to specify an array of guildIds to create guild specific commands with registerChatInputCommand. This works great as long as I have at least one guild specific command for a guild. The issue is when II remove a guild id from all the command ApplicationCommandRegistryRegisterOptions then it won't overwrite anything in that guild and so it doesn't delete the removed commands. Below I've included an example of two commands. Assume that previously both commands were registered for guilds ['111','222','333'] specifically. If I make an update to remove guild '222' from the Help Command and guild '333' from both the Ping and Help Command, then guild '222' will properly delete the Help Command, however guild '333' will not be updated and keep both the Help and Ping Command. What is the recommended approach to remove guild specific commands from '333' after an update like this? and can it be done using Sapphire and BulkOverwrite somehow?
export class PingCommand extends Command {
public override async registerApplicationCommands(
registry: Command.Registry
) {

const pingSpecificGuildIds = ['111', '222']; // removed '333'
// an empty guild array will make it global
if (pingSpecificGuildIds.length > 0) {
registry.registerChatInputCommand(
pingCommand,
{ guildIds: pingSpecificGuildIds }
);
}
}
}

export class HelpCommand extends Command {
public override async registerApplicationCommands(
registry: Command.Registry
) {
const helpSpecificGuildIds = ['111']; // removed '222' and '333'
// an empty guild array will make it global
if (helpSpecificGuildIds.length > 0) {
registry.registerChatInputCommand(
helpCommand,
{ guildIds: helpSpecificGuildIds }
);
}
}
export class PingCommand extends Command {
public override async registerApplicationCommands(
registry: Command.Registry
) {

const pingSpecificGuildIds = ['111', '222']; // removed '333'
// an empty guild array will make it global
if (pingSpecificGuildIds.length > 0) {
registry.registerChatInputCommand(
pingCommand,
{ guildIds: pingSpecificGuildIds }
);
}
}
}

export class HelpCommand extends Command {
public override async registerApplicationCommands(
registry: Command.Registry
) {
const helpSpecificGuildIds = ['111']; // removed '222' and '333'
// an empty guild array will make it global
if (helpSpecificGuildIds.length > 0) {
registry.registerChatInputCommand(
helpCommand,
{ guildIds: helpSpecificGuildIds }
);
}
}
8 replies
SIASapphire - Imagine a framework
Created by kyle13 on 3/21/2023 in #sapphire-support
Handling BulkOverwrite Registry Errors
When I encounter this error
[ERROR] ApplicationCommandRegistries(BulkOverwrite) Failed to overwrite guild application commands for guild 1********* DiscordAPIError[50001]: Missing Access
[ERROR] ApplicationCommandRegistries(BulkOverwrite) Failed to overwrite guild application commands for guild 1********* DiscordAPIError[50001]: Missing Access
I want to be able to capture this error and take an action. In this case update my record of guilds to remove the inaccessible guild. I've tried to capture the errors using the error event listener as well as one on commandApplicationCommandRegistryError however neither seems to be called when this error occurs. What is the recommended way to listen for these BulkOverwrite error events? Example listeners which are never called:
import { ApplyOptions } from '@sapphire/decorators';
import { Listener, Events, Command } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
event: Events.CommandApplicationCommandRegistryError,
})
export class ApplicationRegistryError extends Listener<
typeof Events.CommandApplicationCommandRegistryError
> {
public run(error: unknown, command: Command) {
console.error('caught registry error');
console.error(error);
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Listener, Events, Command } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
event: Events.CommandApplicationCommandRegistryError,
})
export class ApplicationRegistryError extends Listener<
typeof Events.CommandApplicationCommandRegistryError
> {
public run(error: unknown, command: Command) {
console.error('caught registry error');
console.error(error);
}
}
import { Events, Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';


@ApplyOptions<Listener.Options>({
event: Events.Error,
})
export class ErrorListener extends Listener {
public run(error: Error) {
console.error('captured error');
console.error(error);
}
}
import { Events, Listener } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';


@ApplyOptions<Listener.Options>({
event: Events.Error,
})
export class ErrorListener extends Listener {
public run(error: Error) {
console.error('captured error');
console.error(error);
}
}
37 replies