mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
Merge pull request #870 from discordeno/application-command-permissions
Application command permissions
This commit is contained in:
17
src/helpers/commands/batch_edit_slash_command_permissions.ts
Normal file
17
src/helpers/commands/batch_edit_slash_command_permissions.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { applicationId } from "../../bot.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */
|
||||
export async function batchEditSlashCommandPermissions(
|
||||
guildId: string,
|
||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[],
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
||||
camelKeysToSnakeCase(options),
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
*/
|
||||
export async function createSlashCommand(
|
||||
options: CreateGlobalApplicationCommand,
|
||||
guildId: string,
|
||||
guildId?: string,
|
||||
) {
|
||||
validateSlashCommands([options], true);
|
||||
|
||||
|
||||
18
src/helpers/commands/edit_slash_command_permissions.ts
Normal file
18
src/helpers/commands/edit_slash_command_permissions.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { applicationId } from "../../bot.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Edits command permissions for a specific command for your application in a guild. */
|
||||
export async function editSlashCommandPermissions(
|
||||
guildId: string,
|
||||
commandId: string,
|
||||
options: ApplicationCommandPermissions[],
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId),
|
||||
{ permissions: camelKeysToSnakeCase(options) },
|
||||
);
|
||||
}
|
||||
15
src/helpers/commands/get_slash_command_permission.ts
Normal file
15
src/helpers/commands/get_slash_command_permission.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { applicationId } from "../../bot.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */
|
||||
export async function getSlashCommandPermission(
|
||||
guildId: string,
|
||||
commandId: string,
|
||||
) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions>(
|
||||
"get",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId),
|
||||
);
|
||||
}
|
||||
12
src/helpers/commands/get_slash_command_permissions.ts
Normal file
12
src/helpers/commands/get_slash_command_permissions.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { applicationId } from "../../bot.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */
|
||||
export async function getSlashCommandPermissions(guildId: string) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions[]>(
|
||||
"get",
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
||||
);
|
||||
}
|
||||
@@ -13,15 +13,24 @@ import { getPins } from "./channels/get_pins.ts";
|
||||
import { isChannelSynced } from "./channels/is_channel_synced.ts";
|
||||
import { startTyping } from "./channels/start_typing.ts";
|
||||
import { swapChannels } from "./channels/swap_channels.ts";
|
||||
import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts";
|
||||
import { createSlashCommand } from "./commands/create_slash_command.ts";
|
||||
import { deleteSlashCommand } from "./commands/delete_slash_command.ts";
|
||||
import { deleteSlashResponse } from "./commands/delete_slash_response.ts";
|
||||
import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts";
|
||||
import { editSlashResponse } from "./commands/edit_slash_response.ts";
|
||||
import { getSlashCommand } from "./commands/get_slash_command.ts";
|
||||
import { getSlashCommands } from "./commands/get_slash_commands.ts";
|
||||
import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts";
|
||||
import { getSlashCommandPermissions } from "./commands/get_slash_command_permissions.ts";
|
||||
import { sendInteractionResponse } from "./commands/send_interaction_response.ts";
|
||||
import { upsertSlashCommand } from "./commands/upsert_slash_command.ts";
|
||||
import { upsertSlashCommands } from "./commands/upsert_slash_commands.ts";
|
||||
import { addDiscoverySubcategory } from "./discovery/add_discovery_subcategory.ts";
|
||||
import { editDiscovery } from "./discovery/edit_discovery.ts";
|
||||
import { getDiscoveryCategories } from "./discovery/get_discovery_categories.ts";
|
||||
import { removeDiscoverySubcategory } from "./discovery/remove_discovery_subcategory.ts";
|
||||
import { validDiscoveryTerm } from "./discovery/valid_discovery_term.ts";
|
||||
import { createEmoji } from "./emojis/create_emoji.ts";
|
||||
import { deleteEmoji } from "./emojis/delete_emoji.ts";
|
||||
import { editEmoji } from "./emojis/edit_emoji.ts";
|
||||
@@ -115,11 +124,6 @@ import { executeWebhook } from "./webhooks/execute_webhook.ts";
|
||||
import { getWebhook } from "./webhooks/get_webhook.ts";
|
||||
import { getWebhooks } from "./webhooks/get_webhooks.ts";
|
||||
import { getWebhookWithToken } from "./webhooks/get_webhook_with_token.ts";
|
||||
import { addDiscoverySubcategory } from "./discovery/add_discovery_subcategory.ts";
|
||||
import { editDiscovery } from "./discovery/edit_discovery.ts";
|
||||
import { getDiscoveryCategories } from "./discovery/get_discovery_categories.ts";
|
||||
import { removeDiscoverySubcategory } from "./discovery/remove_discovery_subcategory.ts";
|
||||
import { validDiscoveryTerm } from "./discovery/valid_discovery_term.ts";
|
||||
|
||||
export {
|
||||
addDiscoverySubcategory,
|
||||
@@ -129,6 +133,7 @@ export {
|
||||
avatarURL,
|
||||
ban,
|
||||
banMember,
|
||||
batchEditSlashCommandPermissions,
|
||||
categoryChildren,
|
||||
channelOverwriteHasPermission,
|
||||
createChannel,
|
||||
@@ -206,6 +211,8 @@ export {
|
||||
getReactions,
|
||||
getRoles,
|
||||
getSlashCommand,
|
||||
getSlashCommandPermission,
|
||||
getSlashCommandPermissions,
|
||||
getSlashCommands,
|
||||
getTemplate,
|
||||
getUser,
|
||||
@@ -272,6 +279,10 @@ export let helpers = {
|
||||
deleteSlashCommand,
|
||||
deleteSlashResponse,
|
||||
editSlashResponse,
|
||||
getSlashCommandPermission,
|
||||
getSlashCommandPermissions,
|
||||
batchEditSlashCommandPermissions,
|
||||
editSlashCommandPermissions,
|
||||
sendInteractionResponse,
|
||||
getSlashCommand,
|
||||
getSlashCommands,
|
||||
|
||||
@@ -148,6 +148,16 @@ export const endpoints = {
|
||||
`${baseEndpoints.BASE_URL}/applications/${applicationId}/commands`,
|
||||
COMMANDS_GUILD: (applicationId: string, guildId: string) =>
|
||||
`${baseEndpoints.BASE_URL}/applications/${applicationId}/guilds/${guildId}/commands`,
|
||||
COMMANDS_PERMISSIONS: (applicationId: string, guildId: string) =>
|
||||
`${endpoints.COMMANDS_GUILD(applicationId, guildId)}/permissions`,
|
||||
COMMANDS_PERMISSION: (
|
||||
applicationId: string,
|
||||
guildId: string,
|
||||
commandId: string,
|
||||
) =>
|
||||
`${
|
||||
endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
}/${commandId}/permissions`,
|
||||
COMMANDS_ID: (applicationId: string, commandId: string) =>
|
||||
`${baseEndpoints.BASE_URL}/applications/${applicationId}/commands/${commandId}`,
|
||||
COMMANDS_GUILD_ID: (
|
||||
|
||||
Reference in New Issue
Block a user