Skip to content

plugin-gateway: port ApplicationCommandManager and ApplicationCommandPermissionsManager (discord.js parity) #209

Closed

Description

@RedStar071

Context

Split out of #207, which tracks the ApplicationCommand structure itself. This issue tracks the managers that create, fetch and edit application commands and their permissions, ported from discord.js (main):

None of them exists in @wolfstar/plugin-gateway. They depend on client.application (#208) for the application ID and on the ApplicationCommand structure (#207).

Proposal

ApplicationCommandManager (client.application.commands)

A cached manager of ApplicationCommands, global by default, with an optional guildId on every method:

  • fetch(options?): one command by ID (cache, force, guildId), or every command (guildId, locale sent as X-Discord-Locale, withLocalizations).
  • create(command, guildId?): POST to the commands route.
  • set(commands, guildId?): bulk overwrite with PUT, returning the new collection.
  • edit(command, data, guildId?) and delete(command, guildId?).
  • permissions: the permissions manager below.
  • commandPath({ id, guildId }) picks among applicationCommands, applicationCommand, applicationGuildCommands and applicationGuildCommand.
  • static transformCommand(command): camel-cased ApplicationCommandData to the API payload (localizations, options, default_member_permissions, integration_types, contexts, handler). It also accepts a builder through toJSON().
  • Types: ApplicationCommandResolvable, ApplicationCommandDataResolvable, FetchApplicationCommandOptions.

GuildApplicationCommandManager (guild.commands)

The same manager with the guild fixed, and its own permissions manager.

ApplicationCommandPermissionsManager

Reachable from three places, which decide which of guild and command the options must carry: application.commands.permissions, guild.commands.permissions and command.permissions.

  • fetch({ guild, command }): the permissions of one command, or of every command of the guild as a collection keyed by command ID.
  • set({ guild, command, permissions, token }): replaces them.
  • add({ guild, command, permissions, token }): merges into the existing ones.
  • remove({ guild, command, users, roles, channels, token }).
  • has({ guild, command, permissionId, permissionType }).
  • permissionsPath(guildId, commandId?) picks between applicationCommandPermissions and guildApplicationCommandsPermissions.
  • Types: ApplicationCommandPermissions, the edit/remove/has option types, RolePermissionConstant and ChannelPermissionConstant (the @everyone and "all channels" IDs derived from the guild ID).

The writes (set, add, remove) need a bearer token: discord.js sends them with auth: false and an Authorization: Bearer <token> header, because Discord refuses the bot token there. fetch and has use the bot token.

Errors

New GatewayError codes for the cases discord.js throws: ApplicationCommandPermissionsTokenMissing, GlobalCommandPermissions (permissions need a guild), GuildUncachedEntityResolve (resolving a role or channel without the guild), and the InvalidType/InvalidElement type errors for bad resolvables.

Events

APPLICATION_COMMAND_PERMISSIONS_UPDATE is the only gateway event in this area. Check whether plugin-gateway already emits applicationCommandPermissionsUpdate, and with which payload.

Questions

  • Cache. discord.js caches commands in the manager, but no gateway event keeps that cache in sync (commands have no create/update/delete dispatch). Cached through @wolfstar/plugin-cache (new entity type), or fetch-only?
  • Framework overlap. @wolfstar/http-framework registers commands on its own. set() is a bulk overwrite, so it would delete whatever the framework registered. Decide whether the manager is read-mostly here, or documented as an alternative to the framework's registration.
  • Resolving roles and channels. remove and has resolve roles and channels through the guild's caches in discord.js. With an asynchronous cache this cannot be synchronous: accept IDs and structures only, or fetch through the managers?
  • Bearer token. Is the permissions write path worth porting at all, given it needs an OAuth2 token with applications.commands.permissions.update that a bot process normally does not have?

Out of scope

The ApplicationCommand structure and ApplicationEmoji (#207), ClientApplication (#208), and interaction structures.

Activity

  1. pullfrog commented on Oct 5, 2026

    @pullfrog
    Contributor

    This run croaked 😵

    The workflow encountered an error before any progress could be reported. Please check the link below for details.

    Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions