chore: Slash Commands typings (#44)

Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
Vlad Frangu
2020-12-19 01:03:22 +02:00
committed by GitHub
parent c2f0deeebd
commit 91cf0d31d7
19 changed files with 934 additions and 531 deletions

View File

@@ -1,7 +1,7 @@
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes
*/
export enum RESTJSONErrorCodes {
export const enum RESTJSONErrorCodes {
GeneralError,
UnknownAccount = 10001,
@@ -61,6 +61,8 @@ export enum RESTJSONErrorCodes {
FeatureTemporarilyDisabledServerSide,
UserBannedFromThisGuild,
ThisMessageWasAlreadyCrossposted = 40033,
MissingAccess = 50001,
InvalidAccountType,
CannotExecuteActionOnDMChannel,
@@ -106,7 +108,7 @@ export enum RESTJSONErrorCodes {
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#rpc-rpc-error-codes
*/
export enum RPCErrorCodes {
export const enum RPCErrorCodes {
UnknownError = 1000,
InvalidPayload = 4000,
@@ -131,7 +133,7 @@ export enum RPCErrorCodes {
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#rpc-rpc-close-event-codes
*/
export enum RPCCloseEventCodes {
export const enum RPCCloseEventCodes {
InvalidClientID = 4000,
InvalidOrigin,
RateLimited,

913
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -29,18 +29,18 @@
"node": ">=12"
},
"devDependencies": {
"@commitlint/cli": "^9.1.2",
"@commitlint/config-angular": "^9.1.2",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"eslint": "^7.8.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-angular": "^11.0.0",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"eslint": "^7.15.0",
"eslint-config-marine": "^7.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"lint-staged": "^10.3.0",
"prettier": "^2.1.1",
"typescript": "^4.0.2"
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.3.0",
"husky": "^4.3.6",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"typescript": "^4.1.3"
},
"repository": {
"type": "git",

View File

@@ -12,7 +12,8 @@
"removeComments": false,
"target": "ES2020",
"importsNotUsedAsValues": "error",
"strictNullChecks": true
"strictNullChecks": true,
"preserveConstEnums": true
},
"exclude": [
"node_modules",

View File

@@ -16,6 +16,7 @@ import type {
GatewayVoiceState,
InviteTargetUserType,
PresenceUpdateStatus,
APIApplicationCommandInteraction,
} from '../payloads';
export const GatewayVersion = '8';
@@ -23,7 +24,7 @@ export const GatewayVersion = '8';
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes
*/
export enum GatewayOPCodes {
export const enum GatewayOPCodes {
Dispatch,
Heartbeat,
Identify,
@@ -41,7 +42,7 @@ export enum GatewayOPCodes {
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes
*/
export enum GatewayCloseCodes {
export const enum GatewayCloseCodes {
UnknownError = 4000,
UnknownOpCode,
DecodeError,
@@ -62,7 +63,7 @@ export enum GatewayCloseCodes {
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-opcodes
*/
export enum VoiceOPCodes {
export const enum VoiceOPCodes {
Identify,
SelectProtocol,
Ready,
@@ -81,7 +82,7 @@ export enum VoiceOPCodes {
/**
* https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes
*/
export enum VoiceCloseCodes {
export const enum VoiceCloseCodes {
UnknownOpCode = 4001,
NotAuthenticated = 4003,
@@ -102,7 +103,7 @@ export enum VoiceCloseCodes {
/**
* https://discord.com/developers/docs/topics/gateway#list-of-intents
*/
export enum GatewayIntentBits {
export const enum GatewayIntentBits {
GUILDS = 1 << 0,
GUILD_MEMBERS = 1 << 1,
GUILD_BANS = 1 << 2,
@@ -123,7 +124,7 @@ export enum GatewayIntentBits {
/**
* https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
*/
export enum GatewayDispatchEvents {
export const enum GatewayDispatchEvents {
Ready = 'READY',
Resumed = 'RESUMED',
ChannelCreate = 'CHANNEL_CREATE',
@@ -144,6 +145,7 @@ export enum GatewayDispatchEvents {
GuildRoleCreate = 'GUILD_ROLE_CREATE',
GuildRoleUpdate = 'GUILD_ROLE_UPDATE',
GuildRoleDelete = 'GUILD_ROLE_DELETE',
InteractionCreate = 'INTERACTION_CREATE',
InviteCreate = 'INVITE_CREATE',
InviteDelete = 'INVITE_DELETE',
MessageCreate = 'MESSAGE_CREATE',
@@ -194,6 +196,7 @@ export type GatewayDispatchPayload =
| GatewayGuildMembersChunkDispatch
| GatewayGuildRoleModifyDispatch
| GatewayGuildRoleDeleteDispatch
| GatewayInteractionCreateDispatch
| GatewayInviteCreateDispatch
| GatewayInviteDeleteDispatch
| GatewayMessageCreateDispatch
@@ -424,6 +427,14 @@ export type GatewayGuildRoleDeleteDispatch = DataPayload<
}
>;
/**
* https://discord.com/developers/docs/topics/gateway#interaction-create
*/
export type GatewayInteractionCreateDispatch = DataPayload<
GatewayDispatchEvents.InteractionCreate,
APIApplicationCommandInteraction
>;
/**
* https://discord.com/developers/docs/topics/gateway#invite-create
*/

View File

@@ -41,7 +41,7 @@ export interface APIAuditLogEntry {
/**
* https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
*/
export enum AuditLogEvent {
export const enum AuditLogEvent {
GUILD_UPDATE = 1,
CHANNEL_CREATE = 10,
@@ -154,7 +154,7 @@ export interface APIAuditLogOptions {
role_name?: string;
}
export enum AuditLogOptionsType {
export const enum AuditLogOptionsType {
Role = '0',
Member = '1',
}

View File

@@ -40,7 +40,7 @@ export interface APIChannel extends APIPartialChannel {
/**
* https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
export enum ChannelType {
export const enum ChannelType {
GUILD_TEXT = 0,
DM,
GUILD_VOICE,
@@ -85,7 +85,7 @@ export interface APIMessage {
/**
* https://discord.com/developers/docs/resources/channel#message-object-message-types
*/
export enum MessageType {
export const enum MessageType {
DEFAULT,
RECIPIENT_ADD,
RECIPIENT_REMOVE,
@@ -137,7 +137,7 @@ export interface APIMessageReference {
/**
* https://discord.com/developers/docs/resources/channel#message-object-message-activity-types
*/
export enum MessageActivityType {
export const enum MessageActivityType {
JOIN = 1,
SPECTATE,
LISTEN,
@@ -147,12 +147,13 @@ export enum MessageActivityType {
/**
* https://discord.com/developers/docs/resources/channel#message-object-message-flags
*/
export enum MessageFlags {
export const enum MessageFlags {
CROSSPOSTED = 1 << 0,
IS_CROSSPOST = 1 << 1,
SUPPRESS_EMBEDS = 1 << 2,
SOURCE_MESSAGE_DELETED = 1 << 3,
URGENT = 1 << 4,
EPHEMERAL = 1 << 6,
}
/**
@@ -172,7 +173,7 @@ export interface APISticker {
/**
* https://discord.com/developers/docs/resources/channel#message-object-message-sticker-format-types
*/
export enum StickerFormatType {
export const enum StickerFormatType {
PNG = 1,
APNG,
LOTTIE,
@@ -197,7 +198,7 @@ export interface APIOverwrite {
deny: string;
}
export enum OverwriteType {
export const enum OverwriteType {
Role,
Member,
}
@@ -228,7 +229,7 @@ export interface APIEmbed {
* https://discord.com/developers/docs/resources/channel#embed-object-embed-types
* @deprecated *Embed types should be considered deprecated and might be removed in a future API version*
*/
export enum EmbedType {
export const enum EmbedType {
Rich = 'rich',
Image = 'image',
Video = 'video',

View File

@@ -42,7 +42,7 @@ export interface GatewayPresenceUpdate {
client_status?: GatewayPresenceClientStatus;
}
export enum PresenceUpdateStatus {
export const enum PresenceUpdateStatus {
DoNotDisturb = 'dnd',
Idle = 'idle',
Invisible = 'invisible',
@@ -78,7 +78,7 @@ export interface GatewayActivity {
/**
* https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
*/
export enum ActivityType {
export const enum ActivityType {
Game,
Streaming,
Listening,
@@ -124,7 +124,7 @@ export type GatewayActivitySecrets = Partial<Record<'join' | 'spectate' | 'match
/**
* https://discord.com/developers/docs/topics/gateway#activity-object-activity-flags
*/
export enum ActivityFlags {
export const enum ActivityFlags {
INSTANCE = 1 << 0,
JOIN = 1 << 1,
SPECTATE = 1 << 2,

View File

@@ -88,7 +88,7 @@ export interface APIGuild extends APIPartialGuild {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
*/
export enum GuildDefaultMessageNotifications {
export const enum GuildDefaultMessageNotifications {
ALL_MESSAGES,
ONLY_MENTIONS,
}
@@ -96,7 +96,7 @@ export enum GuildDefaultMessageNotifications {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-explicit-content-filter-level
*/
export enum GuildExplicitContentFilter {
export const enum GuildExplicitContentFilter {
DISABLED,
MEMBERS_WITHOUT_ROLES,
ALL_MEMBERS,
@@ -105,7 +105,7 @@ export enum GuildExplicitContentFilter {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-mfa-level
*/
export enum GuildMFALevel {
export const enum GuildMFALevel {
NONE,
ELEVATED,
}
@@ -113,7 +113,7 @@ export enum GuildMFALevel {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-verification-level
*/
export enum GuildVerificationLevel {
export const enum GuildVerificationLevel {
NONE,
LOW,
MEDIUM,
@@ -124,7 +124,7 @@ export enum GuildVerificationLevel {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-premium-tier
*/
export enum GuildPremiumTier {
export const enum GuildPremiumTier {
NONE,
TIER_1,
TIER_2,
@@ -134,7 +134,7 @@ export enum GuildPremiumTier {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags
*/
export enum GuildSystemChannelFlags {
export const enum GuildSystemChannelFlags {
SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0,
SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1,
}
@@ -142,7 +142,7 @@ export enum GuildSystemChannelFlags {
/**
* https://discord.com/developers/docs/resources/guild#guild-object-guild-features
*/
export enum GuildFeature {
export const enum GuildFeature {
ANIMATED_ICON = 'ANIMATED_ICON',
BANNER = 'BANNER',
COMMERCE = 'COMMERCE',
@@ -254,7 +254,7 @@ export interface APIGuildIntegration {
/**
* https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
*/
export enum IntegrationExpireBehavior {
export const enum IntegrationExpireBehavior {
RemoveRole,
Kick,
}
@@ -290,7 +290,7 @@ export interface APIBan {
/**
* https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options
*/
export enum GuildWidgetStyle {
export const enum GuildWidgetStyle {
Banner1 = 'banner1',
Banner2 = 'banner2',
Banner3 = 'banner3',

View File

@@ -3,6 +3,7 @@ export * from './channel';
export * from './emoji';
export * from './gateway';
export * from './guild';
export * from './interactions';
export * from './invite';
export * from './oauth2';
export * from './permissions';

180
v8/payloads/interactions.ts Normal file
View File

@@ -0,0 +1,180 @@
import type { APIGuildMember, APIUser, MessageFlags } from './';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../rest';
/**
* https://discord.com/developers/docs/interactions/slash-commands#applicationcommand
*/
export interface APIApplicationCommand {
id: string;
application_id: string;
name: string;
description: string;
options?: APIApplicationCommandOption[];
}
interface APIApplicationCommandOptionBase {
type:
| ApplicationCommandOptionType.BOOLEAN
| ApplicationCommandOptionType.USER
| ApplicationCommandOptionType.CHANNEL
| ApplicationCommandOptionType.ROLE;
name: string;
description: string;
default?: boolean;
required?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption
*/
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase;
/**
* This type is exported as a way to make it stricter for you when you're writing your commands.
*
* If the option is a `SUB_COMMAND` or `SUB_COMMAND_GROUP` type, this nested options will be the parameters
*/
export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
type: ApplicationCommandOptionType.SUB_COMMAND | ApplicationCommandOptionType.SUB_COMMAND_GROUP;
options?: APIApplicationCommandOption[];
}
/**
* This type is exported as a way to make it stricter for you when you're writing your commands.
*
* In contrast to {@see APIApplicationCommandSubCommandOptions}, these types cannot have an `options` array,
* but they can have a `choices` one
*/
export interface APIApplicationCommandArgumentOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
type: ApplicationCommandOptionType.STRING | ApplicationCommandOptionType.INTEGER;
choices?: APIApplicationCommandOptionChoice[];
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype
*/
export const enum ApplicationCommandOptionType {
SUB_COMMAND = 1,
SUB_COMMAND_GROUP,
STRING,
INTEGER,
BOOLEAN,
USER,
CHANNEL,
ROLE,
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice
*/
export interface APIApplicationCommandOptionChoice {
name: string;
value: string | number;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction
*/
export interface APIInteraction {
id: string;
type: InteractionType;
data?: APIApplicationCommandInteractionData;
guild_id: string;
channel_id: string;
member: APIGuildMember & { user: APIUser };
token: string;
version: 1;
}
/**
* Like {@see APIInteraction}, only with the `data` property always present
*/
export type APIApplicationCommandInteraction = Required<APIInteraction>;
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-interactiontype
*/
export const enum InteractionType {
Ping = 1,
ApplicationCommand,
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondata
*/
export interface APIApplicationCommandInteractionData {
id: string;
name: string;
options?: APIApplicationCommandInteractionDataOption[];
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption
*/
export interface APIApplicationCommandInteractionDataOption {
name: string;
/**
* The value returned here depends on the `ApplicationCommandOptionType` type of the option with the name
* that matches this interface's `name`.
*
* You will need to manually cast this to the appropriate type based on the returned data.
*/
value?: unknown;
options?: APIApplicationCommandInteractionDataOption[];
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-interaction-response
*/
export type APIInteractionResponse =
| APIInteractionResponsePong
| APIInteractionResponseAcknowledge
| APIInteractionResponseAcknowledgeWithSource
| APIInteractionResponseChannelMessage
| APIInteractionResponseChannelMessageWithSource;
export type APIInteractionResponsePong = InteractionResponsePayload<APIInteractionResponseType.Pong>;
export type APIInteractionResponseAcknowledge = InteractionResponsePayload<APIInteractionResponseType.Acknowledge>;
export type APIInteractionResponseAcknowledgeWithSource = InteractionResponsePayload<APIInteractionResponseType.AcknowledgeWithSource>;
export type APIInteractionResponseChannelMessage = InteractionResponsePayload<
APIInteractionResponseType.ChannelMessage,
true
>;
export type APIInteractionResponseChannelMessageWithSource = InteractionResponsePayload<
APIInteractionResponseType.ChannelMessageWithSource,
true
>;
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-interactionresponsetype
*/
export const enum APIInteractionResponseType {
Pong = 1,
Acknowledge,
ChannelMessage,
ChannelMessageWithSource,
AcknowledgeWithSource,
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-interactionapplicationcommandcallbackdata
*/
export type APIInteractionApplicationCommandCallbackData = Omit<
RESTPostAPIWebhookWithTokenJSONBody,
'username' | 'avatar_url'
> & { flags?: MessageFlags };
/**
* @internal
*/
interface InteractionResponsePayload<T extends APIInteractionResponseType, D = false> {
type: T;
data?: D extends true ? APIInteractionApplicationCommandCallbackData : never;
}

View File

@@ -23,7 +23,7 @@ export interface APIInvite {
/**
* https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
*/
export enum InviteTargetUserType {
export const enum InviteTargetUserType {
STREAM = 1,
}

View File

@@ -27,7 +27,7 @@ export interface APITeamMember {
/**
* https://discord.com/developers/docs/topics/teams#data-models-membership-state-enum
*/
export enum TeamMemberMembershipState {
export const enum TeamMemberMembershipState {
INVITED = 1,
ACCEPTED,
}

View File

@@ -26,7 +26,7 @@ export interface APIUser {
/**
* https://discord.com/developers/docs/resources/user#user-object-user-flags
*/
export enum UserFlags {
export const enum UserFlags {
None = 0,
DiscordEmployee = 1 << 0,
PartneredServerOwner = 1 << 1,
@@ -46,7 +46,7 @@ export enum UserFlags {
/**
* https://discord.com/developers/docs/resources/user#user-object-premium-types
*/
export enum UserPremiumType {
export const enum UserPremiumType {
None,
NitroClassic,
Nitro,
@@ -67,7 +67,7 @@ export interface APIConnection {
visibility: ConnectionVisibility;
}
export enum ConnectionVisibility {
export const enum ConnectionVisibility {
None,
Everyone,
}

View File

@@ -23,7 +23,7 @@ export interface APIWebhook {
application_id: string | null;
}
export enum WebhookType {
export const enum WebhookType {
Incoming = 1,
ChannelFollower,
}

View File

@@ -18,7 +18,7 @@ import type {
/**
* https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mention-types
*/
export enum AllowedMentionsTypes {
export const enum AllowedMentionsTypes {
Everyone = 'everyone',
Role = 'roles',
User = 'users',
@@ -200,12 +200,19 @@ export interface RESTPutAPIChannelRecipientJSONBody {
export type RESTPutAPIChannelRecipientResult = unknown;
export type RESTDeleteAPIChannelRecipientResult = unknown;
// TODO: Docs updated once https://github.com/discord/discord-api-docs/pull/1692/files is merged
/**
* https://discord.com/developers/docs/resources/channel#crosspost-message
*/
export type RESTPostAPIChannelMessageCrosspostResult = APIMessage;
/**
* https://discord.com/developers/docs/resources/channel#follow-news-channel
*/
export interface RESTPostAPIChannelFollowersJSONBody {
webhook_channel_id: string;
}
/**
* https://discord.com/developers/docs/resources/channel#follow-news-channel
*/
export type RESTPostAPIChannelFollowersResult = APIFollowedChannel;

View File

@@ -173,7 +173,7 @@ export interface RESTPatchAPIGuildMemberJSONBody {
channel_id?: string | null;
}
export type RESTPatchAPIGuildMemberResult = never;
export type RESTPatchAPIGuildMemberResult = APIGuildMember;
/**
* https://discord.com/developers/docs/resources/guild#modify-current-user-nick

View File

@@ -3,6 +3,7 @@ export * from './channel';
export * from './emoji';
export * from './gateway';
export * from './guild';
export * from './interactions';
export * from './invite';
export * from './oauth2';
export * from './template';
@@ -22,8 +23,8 @@ export const Routes = {
/**
* Route for:
* - GET `/channels/{channel.id}`
* - PATCH `/channels/{channel.id}`
* - GET `/channels/{channel.id}`
* - PATCH `/channels/{channel.id}`
* - DELETE `/channels/{channel.id}`
*/
channel(channelID: string) {
@@ -32,7 +33,7 @@ export const Routes = {
/**
* Route for:
* - GET `/channels/{channel.id}/messages`
* - GET `/channels/{channel.id}/messages`
* - POST `/channels/{channel.id}/messages`
*/
channelMessages(channelID: string) {
@@ -41,8 +42,8 @@ export const Routes = {
/**
* Route for:
* - GET `/channels/{channel.id}/messages/{message.id}`
* - PATCH `/channels/{channel.id}/messages/{message.id}`
* - GET `/channels/{channel.id}/messages/{message.id}`
* - PATCH `/channels/{channel.id}/messages/{message.id}`
* - DELETE `/channels/{channel.id}/messages/{message.id}`
*/
channelMessage(channelID: string, messageID: string) {
@@ -53,13 +54,13 @@ export const Routes = {
* Route for:
* - POST `/channels/{channel.id}/messages/{message.id}/crosspost`
*/
channelCrosspost(channelID: string, messageID: string) {
channelMessageCrosspost(channelID: string, messageID: string) {
return `/channels/${channelID}/messages/${messageID}/crosspost`;
},
/**
* Route for:
* - PUT `/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me`
* - PUT `/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me`
* - DELETE `/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me`
*
* **Note**: You need to URL encode the emoji yourself.
@@ -80,12 +81,12 @@ export const Routes = {
/**
* Route for:
* - GET `/channels/{channel.id}/messages/{message.id}/reactions/{emoji}`
* - GET `/channels/{channel.id}/messages/{message.id}/reactions/{emoji}`
* - DELETE `/channels/{channel.id}/messages/{message.id}/reactions/{emoji}`
*
* **Note**: You need to URL encode the emoji yourself.
*/
channelMessageSpecificReaction(channelID: string, messageID: string, emoji: string) {
channelMessageReaction(channelID: string, messageID: string, emoji: string) {
return `/channels/${channelID}/messages/${messageID}/reactions/${emoji}`;
},
@@ -94,7 +95,7 @@ export const Routes = {
* - DELETE `/channels/{channel.id}/messages/{message.id}/reactions`
*/
channelMessageAllReactions(channelID: string, messageID: string) {
return `/channels/${channelID}/messages/${messageID}`;
return `/channels/${channelID}/messages/${messageID}/reactions`;
},
/**
@@ -107,19 +108,19 @@ export const Routes = {
/**
* Route for:
* - PUT `/channels/{channel.id}/permissions/{overwrite.id}`
* - PUT `/channels/{channel.id}/permissions/{overwrite.id}`
* - DELETE `/channels/{channel.id}/permissions/{overwrite.id}`
*/
channelPermissions(channelID: string, overwriteID: string) {
channelPermission(channelID: string, overwriteID: string) {
return `/channels/${channelID}/permissions/${overwriteID}`;
},
/**
* Route for:
* - GET `/channels/{channel.id}/invites`
* - GET `/channels/{channel.id}/invites`
* - POST `/channels/{channel.id}/invites`
*/
channelInvite(channelID: string) {
channelInvites(channelID: string) {
return `/channels/${channelID}/invites`;
},
@@ -149,7 +150,7 @@ export const Routes = {
/**
* Route for:
* - PUT `/channels/{channel.id}/pins/{message.id}`
* - PUT `/channels/{channel.id}/pins/{message.id}`
* - DELETE `/channels/{channel.id}/pins/{message.id}`
*/
channelPin(channelID: string, messageID: string) {
@@ -158,7 +159,7 @@ export const Routes = {
/**
* Route for:
* - PUT `/channels/{channel.id}/recipients/{user.id}`
* - PUT `/channels/{channel.id}/recipients/{user.id}`
* - DELETE `/channels/{channel.id}/recipients/{user.id}`
*/
channelRecipient(channelID: string, userID: string) {
@@ -167,7 +168,7 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/emojis`
* - GET `/guilds/{guild.id}/emojis`
* - POST `/guilds/{guild.id}/emojis`
*/
guildEmojis(guildID: string) {
@@ -176,8 +177,8 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/emojis/{emoji.id}`
* - PATCH `/guilds/{guild.id}/emojis/{emoji.id}`
* - GET `/guilds/{guild.id}/emojis/{emoji.id}`
* - PATCH `/guilds/{guild.id}/emojis/{emoji.id}`
* - DELETE `/guilds/{guild.id}/emojis/{emoji.id}`
*/
guildEmoji(guildID: string, emojiID: string) {
@@ -194,8 +195,8 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}`
* - PATCH `/guilds/{guild.id}`
* - GET `/guilds/{guild.id}`
* - PATCH `/guilds/{guild.id}`
* - DELETE `/guilds/{guild.id}`
*/
guild(guildID: string) {
@@ -212,8 +213,8 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/channels`
* - POST `/guilds/{guild.id}/channels`
* - GET `/guilds/{guild.id}/channels`
* - POST `/guilds/{guild.id}/channels`
* - PATCH `/guilds/{guild.id}/channels`
*/
guildChannels(guildID: string) {
@@ -222,9 +223,9 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/members/{user.id}`
* - PUT `/guilds/{guild.id}/members/{user.id}`
* - PATCH `/guilds/{guild.id}/members/{user.id}`
* - GET `/guilds/{guild.id}/members/{user.id}`
* - PUT `/guilds/{guild.id}/members/{user.id}`
* - PATCH `/guilds/{guild.id}/members/{user.id}`
* - DELETE `/guilds/{guild.id}/members/{user.id}`
*/
guildMember(guildID: string, userID: string) {
@@ -257,7 +258,7 @@ export const Routes = {
/**
* Route for:
* - PUT `/guilds/{guild.id}/members/{user.id}/roles/{role.id}`
* - PUT `/guilds/{guild.id}/members/{user.id}/roles/{role.id}`
* - DELETE `/guilds/{guild.id}/members/{user.id}/roles/{role.id}`
*/
guildMemberRole(guildID: string, memberID: string, roleID: string) {
@@ -274,8 +275,8 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/bans/{user.id}`
* - PUT `/guilds/{guild.id}/bans/{user.id}`
* - GET `/guilds/{guild.id}/bans/{user.id}`
* - PUT `/guilds/{guild.id}/bans/{user.id}`
* - DELETE `/guilds/{guild.id}/bans/{user.id}`
*/
guildBan(guildID: string, userID: string) {
@@ -284,8 +285,8 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/roles`
* - POST `/guilds/{guild.id}/roles`
* - GET `/guilds/{guild.id}/roles`
* - POST `/guilds/{guild.id}/roles`
* - PATCH `/guilds/{guild.id}/roles`
*/
guildRoles(guildID: string) {
@@ -294,7 +295,7 @@ export const Routes = {
/**
* Route for:
* - PATCH `/guilds/{guild.id}/roles/{role.id}`
* - PATCH `/guilds/{guild.id}/roles/{role.id}`
* - DELETE `/guilds/{guild.id}/roles/{role.id}`
*/
guildRole(guildID: string, roleID: string) {
@@ -303,7 +304,7 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/prune`
* - GET `/guilds/{guild.id}/prune`
* - POST `/guilds/{guild.id}/prune`
*/
guildPrune(guildID: string) {
@@ -328,7 +329,7 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/integrations`
* - GET `/guilds/{guild.id}/integrations`
* - POST `/guilds/{guild.id}/integrations`
*/
guildIntegrations(guildID: string) {
@@ -337,7 +338,7 @@ export const Routes = {
/**
* Route for:
* - PATCH `/guilds/{guild.id}/integrations/{integration.id}`
* - PATCH `/guilds/{guild.id}/integrations/{integration.id}`
* - DELETE `/guilds/{guild.id}/integrations/{integration.id}`
*/
guildIntegration(guildID: string, integrationID: string) {
@@ -354,7 +355,7 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/widget`
* - GET `/guilds/{guild.id}/widget`
* - PATCH `/guilds/{guild.id}/widget`
*/
guildWidgetSettings(guildID: string) {
@@ -365,7 +366,7 @@ export const Routes = {
* Route for:
* - GET `/guilds/{guild.id}/widget.json`
*/
guildWidget(guildID: string) {
guildWidgetJSON(guildID: string) {
return `/guilds/${guildID}/widget.json`;
},
@@ -387,7 +388,7 @@ export const Routes = {
/**
* Route for:
* - GET `/invites/{invite.code}`
* - GET `/invites/{invite.code}`
* - DELETE `/invites/{invite.code}`
*/
invite(code: string) {
@@ -396,7 +397,7 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/templates/{template.code}`
* - GET `/guilds/templates/{template.code}`
* - POST `/guilds/templates/{template.code}`
*/
template(code: string) {
@@ -405,7 +406,7 @@ export const Routes = {
/**
* Route for:
* - GET `/guilds/{guild.id}/templates`
* - GET `/guilds/{guild.id}/templates`
* - POST `/guilds/{guild.id}/templates`
*/
guildTemplates(guildID: string) {
@@ -414,8 +415,8 @@ export const Routes = {
/**
* Route for:
* - PUT `/guilds/{guild.id}/templates/{template.code}`
* - PATCH `/guilds/{guild.id}/templates/{template.code}`
* - PUT `/guilds/{guild.id}/templates/{template.code}`
* - PATCH `/guilds/{guild.id}/templates/{template.code}`
* - DELETE `/guilds/{guild.id}/templates/{template.code}`
*/
guildTemplate(guildID: string, code: string) {
@@ -424,9 +425,11 @@ export const Routes = {
/**
* Route for:
* - GET `/users/@me`
* - GET `/users/{user.id}`
* - GET `/users/@me`
* - GET `/users/{user.id}`
* - PATCH `/users/@me`
*
* @param [userID='@me'] The user ID, defaulted to `@me`
*/
user(userID = '@me') {
return `/users/${userID}`;
@@ -474,10 +477,10 @@ export const Routes = {
/**
* Route for:
* - GET `/channels/{channel.id}/webhooks`
* - POST `/channels/{channel.id}/webhooks`
* - GET `/channels/{channel.id}/webhooks`
*/
channelWebhook(channelID: string) {
channelWebhooks(channelID: string) {
return `/channels/${channelID}/webhooks`;
},
@@ -491,13 +494,15 @@ export const Routes = {
/**
* Route for:
* - GET `/webhooks/{webhook.id}`
* - GET `/webhooks/{webhook.id}/{webhook.token}`
* - PATCH `/webhooks/{webhook.id}`
* - PATCH `/webhooks/{webhook.id}/{webhook.token}`
* - GET `/webhooks/{webhook.id}`
* - GET `/webhooks/{webhook.id}/{webhook.token}`
* - PATCH `/webhooks/{webhook.id}`
* - PATCH `/webhooks/{webhook.id}/{webhook.token}`
* - DELETE `/webhooks/{webhook.id}`
* - DELETE `/webhooks/{webhook.id}/{webhook.token}`
* - POST `/webhooks/{webhook.id}/{webhook.token}`
* - POST `/webhooks/{webhook.id}/{webhook.token}`
*
* - POST `/webhooks/{application.id}/{interaction.token}`
*/
webhook(webhookID: string, webhookToken?: string) {
const parts = ['', 'webhooks', webhookID];
@@ -509,8 +514,25 @@ export const Routes = {
/**
* Route for:
* - POST `/webhooks/{webhook.id}/{webhook.token}/slack`
* - PATCH `/webhooks/{webhook.id}/{webhook.token}/messages/@original`
* - PATCH `/webhooks/{webhook.id}/{webhook.token}/messages/{message.id}`
* - DELETE `/webhooks/{webhook.id}/{webhook.token}/messages/@original`
* - DELETE `/webhooks/{webhook.id}/{webhook.token}/messages/{message.id}`
*
* - PATCH `/webhooks/{application.id}/{interaction.token}/messages/@original`
* - PATCH `/webhooks/{application.id}/{interaction.token}/messages/{message.id}`
* - DELETE `/webhooks/{application.id}/{interaction.token}/messages/{message.id}`
*
* @param [messageID='@original'] The message ID to change, defaulted to `@original`
*/
webhookMessage(webhookID: string, webhookToken: string, messageID = '@original') {
return `/webhooks/${webhookID}/${webhookToken}/messages/${messageID}`;
},
/**
* Route for:
* - POST `/webhooks/{webhook.id}/{webhook.token}/github`
* - POST `/webhooks/{webhook.id}/{webhook.token}/slack`
*/
webhookPlatform(webhookID: string, webhookToken: string, platform: 'github' | 'slack') {
return `/webhooks/${webhookID}/${webhookToken}/${platform}`;
@@ -539,4 +561,46 @@ export const Routes = {
oauth2CurrentApplication() {
return `/oauth2/applications/@me`;
},
/**
* Route for:
* - GET `/applications/{application.id}/commands`
* - POST `/applications/{application.id}/commands`
*/
applicationCommands(applicationID: string) {
return `/applications/${applicationID}/commands`;
},
/**
* - PATCH `/applications/{application.id}/commands/{command.id}`
* - DELETE `/applications/{application.id}/commands/{command.id}`
*/
applicationCommand(applicationID: string, commandID: string) {
return `/applications/${applicationID}/commands/${commandID}`;
},
/**
* Route for:
* - GET `/applications/{application.id}/guilds/{guild.id}/commands`
* - POST `/applications/{application.id}/guilds/{guild.id}/commands`
*/
applicationGuildCommands(applicationID: string, guildID: string) {
return `/applications/${applicationID}/guilds/${guildID}/commands`;
},
/**
* - PATCH `/applications/{application.id}/guilds/{guild.id}/commands/{command.id}`
* - DELETE `/applications/{application.id}/guilds/{guild.id}/commands/{command.id}`
*/
applicationGuildCommand(applicationID: string, guildID: string, commandID: string) {
return `/applications/${applicationID}/guilds/${guildID}/commands/${commandID}`;
},
/**
* Route for:
* - POST `/interactions/{interaction.id}/{interaction.token}/callback`
*/
interactionCallback(interactionID: string, interactionToken: string) {
return `/interactions/${interactionID}/${interactionToken}/callback`;
},
};

77
v8/rest/interactions.ts Normal file
View File

@@ -0,0 +1,77 @@
import type { APIApplicationCommand, APIInteractionResponse } from '../payloads';
/**
* https://discord.com/developers/docs/interactions/slash-commands#get-global-application-commands
*/
export type RESTGetAPIApplicationCommandsResult = APIApplicationCommand[];
/**
* https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command
*/
export type RESTPostAPIApplicationCommandsJSONBody = Omit<APIApplicationCommand, 'id' | 'application_id'>;
/**
* https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command
*/
export type RESTPostAPIApplicationCommandsResult = APIApplicationCommand;
/**
* https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command
*/
export type RESTPatchAPIApplicationCommandJSONBody = Partial<RESTPostAPIApplicationCommandsJSONBody>;
/**
* https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command
*/
export type RESTPatchAPIApplicationCommandResult = APIApplicationCommand;
/**
* https://discord.com/developers/docs/interactions/slash-commands#get-guild-application-commands
*/
export type RESTGetAPIApplicationGuildCommandsResult = APIApplicationCommand[];
/**
* https://discord.com/developers/docs/interactions/slash-commands#create-guild-application-command
*/
export type RESTPostAPIApplicationGuildCommandsJSONBody = RESTPostAPIApplicationCommandsJSONBody;
/**
* https://discord.com/developers/docs/interactions/slash-commands#create-guild-application-command
*/
export type RESTPostAPIApplicationGuildCommandsResult = APIApplicationCommand;
/**
* https://discord.com/developers/docs/interactions/slash-commands#edit-guild-application-command
*/
export type RESTPatchAPIApplicationGuildCommandJSONBody = Partial<RESTPostAPIApplicationCommandsJSONBody>;
/**
* https://discord.com/developers/docs/interactions/slash-commands#edit-guild-application-command
*/
export type RESTPatchAPIApplicationGuildCommandResult = APIApplicationCommand;
/**
* https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
*/
export type RESTPostAPIInteractionCallbackJSONBody = APIInteractionResponse;
/**
* https://discord.com/developers/docs/interactions/slash-commands#create-interaction-response
*/
export type RESTPostAPIInteractionCallbackFormDataBody =
| {
/**
* JSON stringified message body
*/
payload_json?: string;
/**
* The file contents
*/
file: unknown;
}
| (RESTPostAPIInteractionCallbackJSONBody & {
/**
* The file contents
*/
file: unknown;
});