mirror of
https://github.com/discordjs/discord.js.git
synced 2026-09-17 08:47:27 +00:00
feat: add per-request dispatcher, headers and rejectOnRateLimit
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type Locale,
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
type RESTPutAPIApplicationGuildCommandsResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { BaseRequestOptions, RequestOptions } from '../util/types.js';
|
||||
|
||||
export class ApplicationCommandsAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -43,12 +44,14 @@ export class ApplicationCommandsAPI {
|
||||
public async getGlobalCommands(
|
||||
applicationId: Snowflake,
|
||||
query: RESTGetAPIApplicationCommandsQuery = {},
|
||||
{ auth, locale, signal }: Pick<RequestData, 'auth' | 'signal'> & { locale?: Locale } = {},
|
||||
{ auth, dispatcher, headers, locale, rejectOnRateLimit, signal }: RequestOptions & { locale?: Locale } = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationCommands(applicationId), {
|
||||
auth,
|
||||
headers: locale ? { 'X-Discord-Locale': locale } : {},
|
||||
headers: locale ? { ...headers, 'X-Discord-Locale': locale } : headers,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationCommandsResult>;
|
||||
}
|
||||
@@ -64,11 +67,14 @@ export class ApplicationCommandsAPI {
|
||||
public async createGlobalCommand(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPostAPIApplicationCommandsJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.applicationCommands(applicationId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIApplicationCommandsResult>;
|
||||
}
|
||||
@@ -84,10 +90,13 @@ export class ApplicationCommandsAPI {
|
||||
public async getGlobalCommand(
|
||||
applicationId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationCommand(applicationId, commandId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationCommandResult>;
|
||||
}
|
||||
@@ -105,11 +114,14 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
body: RESTPatchAPIApplicationCommandJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.applicationCommand(applicationId, commandId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIApplicationCommandResult>;
|
||||
}
|
||||
@@ -125,9 +137,15 @@ export class ApplicationCommandsAPI {
|
||||
public async deleteGlobalCommand(
|
||||
applicationId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.applicationCommand(applicationId, commandId), { auth, signal });
|
||||
await this.rest.delete(Routes.applicationCommand(applicationId, commandId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,11 +159,14 @@ export class ApplicationCommandsAPI {
|
||||
public async bulkOverwriteGlobalCommands(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPutAPIApplicationCommandsJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.put(Routes.applicationCommands(applicationId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPutAPIApplicationCommandsResult>;
|
||||
}
|
||||
@@ -163,12 +184,14 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
query: RESTGetAPIApplicationGuildCommandsQuery = {},
|
||||
{ auth, locale, signal }: Pick<RequestData, 'auth' | 'signal'> & { locale?: Locale } = {},
|
||||
{ auth, dispatcher, headers, locale, rejectOnRateLimit, signal }: RequestOptions & { locale?: Locale } = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationGuildCommands(applicationId, guildId), {
|
||||
auth,
|
||||
headers: locale ? { 'X-Discord-Locale': locale } : {},
|
||||
headers: locale ? { ...headers, 'X-Discord-Locale': locale } : headers,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationGuildCommandsResult>;
|
||||
}
|
||||
@@ -186,11 +209,14 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
body: RESTPostAPIApplicationGuildCommandsJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.applicationGuildCommands(applicationId, guildId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIApplicationGuildCommandsResult>;
|
||||
}
|
||||
@@ -208,10 +234,13 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationGuildCommand(applicationId, guildId, commandId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationGuildCommandResult>;
|
||||
}
|
||||
@@ -231,11 +260,14 @@ export class ApplicationCommandsAPI {
|
||||
guildId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
body: RESTPatchAPIApplicationGuildCommandJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.applicationGuildCommand(applicationId, guildId, commandId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIApplicationGuildCommandResult>;
|
||||
}
|
||||
@@ -253,9 +285,15 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId), { auth, signal });
|
||||
await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,11 +309,14 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
body: RESTPutAPIApplicationGuildCommandsJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.put(Routes.applicationGuildCommands(applicationId, guildId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPutAPIApplicationGuildCommandsResult>;
|
||||
}
|
||||
@@ -293,10 +334,13 @@ export class ApplicationCommandsAPI {
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationCommandPermissions(applicationId, guildId, commandId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationCommandPermissionsResult>;
|
||||
}
|
||||
@@ -312,10 +356,13 @@ export class ApplicationCommandsAPI {
|
||||
public async getGuildCommandsPermissions(
|
||||
applicationId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.guildApplicationCommandsPermissions(applicationId, guildId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIGuildApplicationCommandsPermissionsResult>;
|
||||
}
|
||||
@@ -337,12 +384,14 @@ export class ApplicationCommandsAPI {
|
||||
guildId: Snowflake,
|
||||
commandId: Snowflake,
|
||||
body: RESTPutAPIApplicationCommandPermissionsJSONBody,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.put(Routes.applicationCommandPermissions(applicationId, guildId, commandId), {
|
||||
headers: { Authorization: `Bearer ${userToken.replace('Bearer ', '')}` },
|
||||
headers: { ...headers, Authorization: `Bearer ${userToken.replace('Bearer ', '')}` },
|
||||
auth: false,
|
||||
body,
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPutAPIApplicationCommandPermissionsResult>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIApplicationActivityInstanceResult,
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
type RESTPostAPIApplicationEmojiResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class ApplicationsAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -25,8 +26,14 @@ export class ApplicationsAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/application#get-current-application}
|
||||
* @param options - The options for fetching the application
|
||||
*/
|
||||
public async getCurrent({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.currentApplication(), { auth, signal }) as Promise<RESTGetCurrentApplicationResult>;
|
||||
public async getCurrent({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.currentApplication(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetCurrentApplicationResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,11 +45,14 @@ export class ApplicationsAPI {
|
||||
*/
|
||||
public async editCurrent(
|
||||
body: RESTPatchCurrentApplicationJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.currentApplication(), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchCurrentApplicationResult>;
|
||||
}
|
||||
@@ -54,9 +64,15 @@ export class ApplicationsAPI {
|
||||
* @param applicationId - The id of the application to fetch the emojis of
|
||||
* @param options - The options for fetching the emojis
|
||||
*/
|
||||
public async getEmojis(applicationId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getEmojis(
|
||||
applicationId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationEmojis(applicationId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationEmojisResult>;
|
||||
}
|
||||
@@ -72,10 +88,13 @@ export class ApplicationsAPI {
|
||||
public async getEmoji(
|
||||
applicationId: Snowflake,
|
||||
emojiId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationEmoji(applicationId, emojiId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationEmojiResult>;
|
||||
}
|
||||
@@ -91,11 +110,14 @@ export class ApplicationsAPI {
|
||||
public async createEmoji(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPostAPIApplicationEmojiJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.applicationEmojis(applicationId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIApplicationEmojiResult>;
|
||||
}
|
||||
@@ -113,11 +135,14 @@ export class ApplicationsAPI {
|
||||
applicationId: Snowflake,
|
||||
emojiId: Snowflake,
|
||||
body: RESTPatchAPIApplicationEmojiJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.applicationEmoji(applicationId, emojiId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIApplicationEmojiResult>;
|
||||
}
|
||||
@@ -133,9 +158,15 @@ export class ApplicationsAPI {
|
||||
public async deleteEmoji(
|
||||
applicationId: Snowflake,
|
||||
emojiId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.applicationEmoji(applicationId, emojiId), { auth, signal });
|
||||
await this.rest.delete(Routes.applicationEmoji(applicationId, emojiId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,10 +180,13 @@ export class ApplicationsAPI {
|
||||
public async getActivityInstance(
|
||||
applicationId: Snowflake,
|
||||
instanceId: string,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationActivityInstance(applicationId, instanceId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationActivityInstanceResult>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTDeleteAPIChannelResult,
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
type RESTPutAPIChannelRecipientJSONBody,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js';
|
||||
|
||||
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
|
||||
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
|
||||
@@ -63,12 +64,15 @@ export class ChannelsAPI {
|
||||
public async createMessage(
|
||||
channelId: Snowflake,
|
||||
{ files, ...body }: CreateMessageOptions,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.channelMessages(channelId), {
|
||||
auth,
|
||||
files,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIChannelMessageResult>;
|
||||
}
|
||||
@@ -86,12 +90,15 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ files, ...body }: EditMessageOptions,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.channelMessage(channelId, messageId), {
|
||||
auth,
|
||||
files,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIChannelMessageResult>;
|
||||
}
|
||||
@@ -119,11 +126,14 @@ export class ChannelsAPI {
|
||||
messageId: Snowflake,
|
||||
emoji: string,
|
||||
query: RESTGetAPIChannelMessageReactionUsersQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelMessageReactionUsersResult>;
|
||||
}
|
||||
@@ -149,10 +159,13 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
emoji: string,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -180,10 +193,13 @@ export class ChannelsAPI {
|
||||
messageId: Snowflake,
|
||||
emoji: string,
|
||||
userId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelMessageUserReaction(channelId, messageId, encodeURIComponent(emoji), userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -199,9 +215,15 @@ export class ChannelsAPI {
|
||||
public async deleteAllMessageReactions(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId), { auth, signal });
|
||||
await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,10 +247,13 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
emoji: string,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -254,10 +279,13 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
emoji: string,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.put(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -269,8 +297,17 @@ export class ChannelsAPI {
|
||||
* @param channelId - The id of the channel
|
||||
* @param options - The options for fetching the channel
|
||||
*/
|
||||
public async get(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.channel(channelId), { auth, signal }) as Promise<RESTGetAPIChannelResult>;
|
||||
public async get(
|
||||
channelId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channel(channelId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,12 +321,15 @@ export class ChannelsAPI {
|
||||
public async edit(
|
||||
channelId: Snowflake,
|
||||
body: RESTPatchAPIChannelJSONBody,
|
||||
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.channel(channelId), {
|
||||
auth,
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIChannelResult>;
|
||||
}
|
||||
@@ -303,9 +343,16 @@ export class ChannelsAPI {
|
||||
*/
|
||||
public async delete(
|
||||
channelId: Snowflake,
|
||||
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.delete(Routes.channel(channelId), { auth, signal, reason }) as Promise<RESTDeleteAPIChannelResult>;
|
||||
return this.rest.delete(Routes.channel(channelId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTDeleteAPIChannelResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,11 +366,14 @@ export class ChannelsAPI {
|
||||
public async getMessages(
|
||||
channelId: Snowflake,
|
||||
query: RESTGetAPIChannelMessagesQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelMessages(channelId), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelMessagesResult>;
|
||||
}
|
||||
@@ -335,8 +385,11 @@ export class ChannelsAPI {
|
||||
* @param channelId - The id of the channel to show the typing indicator in
|
||||
* @param options - The options for showing the typing indicator
|
||||
*/
|
||||
public async showTyping(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
await this.rest.post(Routes.channelTyping(channelId), { auth, signal });
|
||||
public async showTyping(
|
||||
channelId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.post(Routes.channelTyping(channelId), { auth, dispatcher, headers, rejectOnRateLimit, signal });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,11 +403,14 @@ export class ChannelsAPI {
|
||||
public async getPins(
|
||||
channelId: Snowflake,
|
||||
query: RESTGetAPIChannelMessagesPinsQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelMessagesPins(channelId), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelMessagesPinsResult>;
|
||||
}
|
||||
@@ -370,9 +426,16 @@ export class ChannelsAPI {
|
||||
public async pinMessage(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
await this.rest.put(Routes.channelMessagesPin(channelId, messageId), { auth, reason, signal });
|
||||
await this.rest.put(Routes.channelMessagesPin(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,9 +449,16 @@ export class ChannelsAPI {
|
||||
public async deleteMessage(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelMessage(channelId, messageId), { auth, reason, signal });
|
||||
await this.rest.delete(Routes.channelMessage(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -402,9 +472,17 @@ export class ChannelsAPI {
|
||||
public async bulkDeleteMessages(
|
||||
channelId: Snowflake,
|
||||
messageIds: Snowflake[],
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
): Promise<void> {
|
||||
await this.rest.post(Routes.channelBulkDelete(channelId), { auth, reason, body: { messages: messageIds }, signal });
|
||||
await this.rest.post(Routes.channelBulkDelete(channelId), {
|
||||
auth,
|
||||
body: { messages: messageIds },
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,10 +496,13 @@ export class ChannelsAPI {
|
||||
public async getMessage(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelMessage(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelMessageResult>;
|
||||
}
|
||||
@@ -437,10 +518,13 @@ export class ChannelsAPI {
|
||||
public async crosspostMessage(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.channelMessageCrosspost(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIChannelMessageCrosspostResult>;
|
||||
}
|
||||
@@ -456,9 +540,16 @@ export class ChannelsAPI {
|
||||
public async unpinMessage(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelMessagesPin(channelId, messageId), { auth, reason, signal });
|
||||
await this.rest.delete(Routes.channelMessagesPin(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -472,12 +563,15 @@ export class ChannelsAPI {
|
||||
public async followAnnouncements(
|
||||
channelId: Snowflake,
|
||||
webhookChannelId: Snowflake,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.post(Routes.channelFollowers(channelId), {
|
||||
auth,
|
||||
body: { webhook_channel_id: webhookChannelId },
|
||||
reason,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIChannelFollowersResult>;
|
||||
}
|
||||
@@ -493,12 +587,15 @@ export class ChannelsAPI {
|
||||
public async createInvite(
|
||||
channelId: Snowflake,
|
||||
body: RESTPostAPIChannelInviteJSONBody,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.post(Routes.channelInvites(channelId), {
|
||||
auth,
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIChannelInviteResult>;
|
||||
}
|
||||
@@ -510,8 +607,17 @@ export class ChannelsAPI {
|
||||
* @param channelId - The id of the channel to fetch invites from
|
||||
* @param options - The options for fetching the invites
|
||||
*/
|
||||
public async getInvites(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.channelInvites(channelId), { auth, signal }) as Promise<RESTGetAPIChannelInvitesResult>;
|
||||
public async getInvites(
|
||||
channelId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelInvites(channelId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelInvitesResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,11 +634,14 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
body: RESTPostAPIChannelThreadsJSONBody,
|
||||
messageId?: Snowflake,
|
||||
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.post(Routes.threads(channelId, messageId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
reason,
|
||||
}) as Promise<RESTPostAPIChannelThreadsResult>;
|
||||
@@ -549,7 +658,7 @@ export class ChannelsAPI {
|
||||
public async createForumThread(
|
||||
channelId: Snowflake,
|
||||
{ message, ...optionsBody }: StartForumThreadOptions,
|
||||
{ auth, signal, reason }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
const { files, ...messageBody } = message;
|
||||
|
||||
@@ -563,6 +672,9 @@ export class ChannelsAPI {
|
||||
files,
|
||||
body,
|
||||
reason,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIChannelThreadsResult>;
|
||||
}
|
||||
@@ -581,11 +693,14 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
archivedStatus: 'private' | 'public',
|
||||
query: RESTGetAPIChannelThreadsArchivedQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelThreads(channelId, archivedStatus), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
|
||||
}
|
||||
@@ -601,11 +716,14 @@ export class ChannelsAPI {
|
||||
public async getJoinedPrivateArchivedThreads(
|
||||
channelId: Snowflake,
|
||||
query: RESTGetAPIChannelThreadsArchivedQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelJoinedArchivedThreads(channelId), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
|
||||
}
|
||||
@@ -621,12 +739,15 @@ export class ChannelsAPI {
|
||||
public async createWebhook(
|
||||
channelId: Snowflake,
|
||||
body: RESTPostAPIChannelWebhookJSONBody,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.post(Routes.channelWebhooks(channelId), {
|
||||
auth,
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIChannelWebhookResult>;
|
||||
}
|
||||
@@ -638,9 +759,15 @@ export class ChannelsAPI {
|
||||
* @param channelId - The id of the channel
|
||||
* @param options - The options for fetching the webhooks
|
||||
*/
|
||||
public async getWebhooks(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getWebhooks(
|
||||
channelId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.channelWebhooks(channelId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIChannelWebhooksResult>;
|
||||
}
|
||||
@@ -658,12 +785,15 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
overwriteId: Snowflake,
|
||||
body: RESTPutAPIChannelPermissionJSONBody,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
await this.rest.put(Routes.channelPermission(channelId, overwriteId), {
|
||||
auth,
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -679,11 +809,14 @@ export class ChannelsAPI {
|
||||
public async deletePermissionOverwrite(
|
||||
channelId: Snowflake,
|
||||
overwriteId: Snowflake,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelPermission(channelId, overwriteId), {
|
||||
auth,
|
||||
reason,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -699,11 +832,14 @@ export class ChannelsAPI {
|
||||
public async sendSoundboardSound(
|
||||
channelId: Snowflake,
|
||||
body: RESTPostAPISoundboardSendSoundJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.post(Routes.sendSoundboardSound(channelId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -721,11 +857,14 @@ export class ChannelsAPI {
|
||||
channelId: Snowflake,
|
||||
userId: Snowflake,
|
||||
body: RESTPutAPIChannelRecipientJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.put(Routes.channelRecipient(channelId, userId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -741,10 +880,13 @@ export class ChannelsAPI {
|
||||
public async removeGroupDMRecipient(
|
||||
channelId: Snowflake,
|
||||
userId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.channelRecipient(channelId, userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import { Routes, type RESTGetAPIGatewayBotResult, type RESTGetAPIGatewayResult } from 'discord-api-types/v10';
|
||||
import type { BaseRequestOptions, RequestOptions } from '../util/types.js';
|
||||
|
||||
export class GatewayAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -12,9 +13,12 @@ export class GatewayAPI {
|
||||
* @see {@link https://discord.com/developers/docs/events/gateway#get-gateway}
|
||||
* @param options - The options for fetching the gateway information
|
||||
*/
|
||||
public async get({ signal }: Pick<RequestData, 'signal'> = {}) {
|
||||
public async get({ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}) {
|
||||
return this.rest.get(Routes.gateway(), {
|
||||
auth: false,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIGatewayResult>;
|
||||
}
|
||||
@@ -25,9 +29,12 @@ export class GatewayAPI {
|
||||
* @see {@link https://discord.com/developers/docs/events/gateway#get-gateway-bot}
|
||||
* @param options - The options for fetching the gateway information
|
||||
*/
|
||||
public async getBot({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getBot({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.gatewayBot(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIGatewayBotResult>;
|
||||
}
|
||||
|
||||
+505
-108
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
InteractionResponseType,
|
||||
Routes,
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
type RESTPostAPIInteractionCallbackWithResponseResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { BaseRequestOptions } from '../util/types.js';
|
||||
import type { WebhooksAPI } from './webhook.js';
|
||||
|
||||
export interface CreateInteractionResponseOptions
|
||||
@@ -53,7 +54,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: CreateInteractionResponseOptions & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -69,7 +70,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: CreateInteractionResponseOptions & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -85,14 +86,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: CreateInteractionResponseOptions,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async reply(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ files, with_response, ...data }: CreateInteractionResponseOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -102,6 +103,9 @@ export class InteractionsAPI {
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
data,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -121,7 +125,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: CreateInteractionDeferResponseOptions & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -137,7 +141,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body?: CreateInteractionDeferResponseOptions & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -153,14 +157,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body?: CreateInteractionDeferResponseOptions,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async defer(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ with_response, ...data }: CreateInteractionDeferResponseOptions = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -169,6 +173,9 @@ export class InteractionsAPI {
|
||||
type: InteractionResponseType.DeferredChannelMessageWithSource,
|
||||
data,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -188,7 +195,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: RESTPostAPIInteractionCallbackQuery & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -204,7 +211,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body?: RESTPostAPIInteractionCallbackQuery & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -220,14 +227,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body?: RESTPostAPIInteractionCallbackQuery,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async deferMessageUpdate(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ with_response }: RESTPostAPIInteractionCallbackQuery = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -235,6 +242,9 @@ export class InteractionsAPI {
|
||||
body: {
|
||||
type: InteractionResponseType.DeferredMessageUpdate,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -254,9 +264,14 @@ export class InteractionsAPI {
|
||||
applicationId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: CreateInteractionFollowUpResponseOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.webhooks.execute(applicationId, interactionToken, { ...body, wait: true }, { signal });
|
||||
return this.webhooks.execute(
|
||||
applicationId,
|
||||
interactionToken,
|
||||
{ ...body, wait: true },
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,9 +290,12 @@ export class InteractionsAPI {
|
||||
interactionToken: string,
|
||||
callbackData: EditInteractionResponseOptions,
|
||||
messageId?: Snowflake | '@original',
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.webhooks.editMessage(applicationId, interactionToken, messageId ?? '@original', callbackData, {
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -293,14 +311,14 @@ export class InteractionsAPI {
|
||||
public async getOriginalReply(
|
||||
applicationId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.webhooks.getMessage(
|
||||
applicationId,
|
||||
interactionToken,
|
||||
'@original',
|
||||
{},
|
||||
{ signal },
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal },
|
||||
) as Promise<RESTGetAPIWebhookWithTokenMessageResult>;
|
||||
}
|
||||
|
||||
@@ -318,9 +336,15 @@ export class InteractionsAPI {
|
||||
applicationId: Snowflake,
|
||||
interactionToken: string,
|
||||
messageId?: Snowflake | '@original',
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
await this.webhooks.deleteMessage(applicationId, interactionToken, messageId ?? '@original', {}, { signal });
|
||||
await this.webhooks.deleteMessage(
|
||||
applicationId,
|
||||
interactionToken,
|
||||
messageId ?? '@original',
|
||||
{},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +360,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -352,7 +376,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -368,14 +392,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateInteractionUpdateMessageResponseOptions,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async updateMessage(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ files, with_response, ...data }: CreateInteractionUpdateMessageResponseOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -385,6 +409,9 @@ export class InteractionsAPI {
|
||||
type: InteractionResponseType.UpdateMessage,
|
||||
data,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -404,7 +431,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateAutocompleteResponseOptions & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -420,7 +447,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateAutocompleteResponseOptions & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -436,14 +463,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateAutocompleteResponseOptions,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async createAutocompleteResponse(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ with_response, ...data }: CreateAutocompleteResponseOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -452,6 +479,9 @@ export class InteractionsAPI {
|
||||
type: InteractionResponseType.ApplicationCommandAutocompleteResult,
|
||||
data,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -471,7 +501,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateModalResponseOptions & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -487,7 +517,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateModalResponseOptions & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -503,14 +533,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
callbackData: CreateModalResponseOptions,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async createModal(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ with_response, ...data }: CreateModalResponseOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -519,6 +549,9 @@ export class InteractionsAPI {
|
||||
type: InteractionResponseType.Modal,
|
||||
data,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -538,7 +571,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body: RESTPostAPIInteractionCallbackQuery & { with_response: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
|
||||
|
||||
/**
|
||||
@@ -554,7 +587,7 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body?: RESTPostAPIInteractionCallbackQuery & { with_response?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<undefined>;
|
||||
|
||||
/**
|
||||
@@ -570,14 +603,14 @@ export class InteractionsAPI {
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
body?: RESTPostAPIInteractionCallbackQuery,
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>;
|
||||
|
||||
public async launchActivity(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ with_response }: RESTPostAPIInteractionCallbackQuery = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
query: makeURLSearchParams({ with_response }),
|
||||
@@ -585,6 +618,9 @@ export class InteractionsAPI {
|
||||
body: {
|
||||
type: InteractionResponseType.LaunchActivity,
|
||||
},
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTDeleteAPIInviteResult,
|
||||
type RESTGetAPIInviteQuery,
|
||||
type RESTGetAPIInviteResult,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js';
|
||||
|
||||
export class InvitesAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -22,11 +23,14 @@ export class InvitesAPI {
|
||||
public async get(
|
||||
code: string,
|
||||
query: RESTGetAPIInviteQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.invite(code), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIInviteResult>;
|
||||
}
|
||||
@@ -38,7 +42,17 @@ export class InvitesAPI {
|
||||
* @param code - The invite code
|
||||
* @param options - The options for deleting the invite
|
||||
*/
|
||||
public async delete(code: string, { auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {}) {
|
||||
return this.rest.delete(Routes.invite(code), { auth, reason, signal }) as Promise<RESTDeleteAPIInviteResult>;
|
||||
public async delete(
|
||||
code: string,
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.delete(Routes.invite(code), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTDeleteAPIInviteResult>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIEntitlementsQuery,
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
type RESTPostAPIEntitlementResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class MonetizationAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -25,8 +26,17 @@ export class MonetizationAPI {
|
||||
* @param applicationId - The application id to fetch SKUs for
|
||||
* @param options - The options for fetching the SKUs.
|
||||
*/
|
||||
public async getSKUs(applicationId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.skus(applicationId), { auth, signal }) as Promise<RESTGetAPISKUsResult>;
|
||||
public async getSKUs(
|
||||
applicationId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.skus(applicationId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPISKUsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,10 +50,13 @@ export class MonetizationAPI {
|
||||
public async getSKUSubscriptions(
|
||||
skuId: Snowflake,
|
||||
query: RESTGetAPISKUSubscriptionsQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.skuSubscriptions(skuId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
query: makeURLSearchParams(query),
|
||||
}) as Promise<RESTGetAPISKUSubscriptionsResult>;
|
||||
@@ -60,10 +73,13 @@ export class MonetizationAPI {
|
||||
public async getSKUSubscription(
|
||||
skuId: Snowflake,
|
||||
subscriptionId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.skuSubscription(skuId, subscriptionId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPISKUSubscriptionResult>;
|
||||
}
|
||||
@@ -79,10 +95,13 @@ export class MonetizationAPI {
|
||||
public async getEntitlements(
|
||||
applicationId: Snowflake,
|
||||
query: RESTGetAPIEntitlementsQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.entitlements(applicationId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
query: makeURLSearchParams(query),
|
||||
}) as Promise<RESTGetAPIEntitlementsResult>;
|
||||
@@ -99,10 +118,13 @@ export class MonetizationAPI {
|
||||
public async getEntitlement(
|
||||
applicationId: Snowflake,
|
||||
entitlementId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.entitlement(applicationId, entitlementId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIEntitlementResult>;
|
||||
}
|
||||
@@ -118,11 +140,14 @@ export class MonetizationAPI {
|
||||
public async createTestEntitlement(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPostAPIEntitlementJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.entitlements(applicationId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIEntitlementResult>;
|
||||
}
|
||||
@@ -138,9 +163,15 @@ export class MonetizationAPI {
|
||||
public async deleteTestEntitlement(
|
||||
applicationId: Snowflake,
|
||||
entitlementId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.entitlement(applicationId, entitlementId), { auth, signal });
|
||||
await this.rest.delete(Routes.entitlement(applicationId, entitlementId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,8 +185,14 @@ export class MonetizationAPI {
|
||||
public async consumeEntitlement(
|
||||
applicationId: Snowflake,
|
||||
entitlementId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.post(Routes.consumeEntitlement(applicationId, entitlementId), { auth, signal });
|
||||
await this.rest.post(Routes.consumeEntitlement(applicationId, entitlementId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { type RequestData, type REST, makeURLSearchParams } from '@discordjs/rest';
|
||||
import { type REST, makeURLSearchParams } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
RouteBases,
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type RESTPostOAuth2TokenRevocationQuery,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { BaseRequestOptions, RequestOptions } from '../util/types.js';
|
||||
|
||||
export class OAuth2API {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -41,15 +42,18 @@ export class OAuth2API {
|
||||
*/
|
||||
public async tokenExchange(
|
||||
body: RESTPostOAuth2AccessTokenURLEncodedData,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.oauth2TokenExchange(), {
|
||||
body: makeURLSearchParams<RESTPostOAuth2AccessTokenURLEncodedData>(body),
|
||||
passThroughBody: true,
|
||||
headers: {
|
||||
...headers,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
auth: false,
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostOAuth2AccessTokenResult>;
|
||||
}
|
||||
@@ -63,15 +67,18 @@ export class OAuth2API {
|
||||
*/
|
||||
public async refreshToken(
|
||||
body: RESTPostOAuth2RefreshTokenURLEncodedData,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.oauth2TokenExchange(), {
|
||||
body: makeURLSearchParams<RESTPostOAuth2RefreshTokenURLEncodedData>(body),
|
||||
passThroughBody: true,
|
||||
headers: {
|
||||
...headers,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
auth: false,
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostOAuth2RefreshTokenResult>;
|
||||
}
|
||||
@@ -87,15 +94,18 @@ export class OAuth2API {
|
||||
*/
|
||||
public async getToken(
|
||||
body: RESTPostOAuth2ClientCredentialsURLEncodedData,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.oauth2TokenExchange(), {
|
||||
body: makeURLSearchParams(body),
|
||||
passThroughBody: true,
|
||||
headers: {
|
||||
...headers,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
auth: false,
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostOAuth2ClientCredentialsResult>;
|
||||
}
|
||||
@@ -106,9 +116,18 @@ export class OAuth2API {
|
||||
* @see {@link https://discord.com/developers/docs/topics/oauth2#get-current-bot-application-information}
|
||||
* @param options - The options for the current bot application information request
|
||||
*/
|
||||
public async getCurrentBotApplicationInformation({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getCurrentBotApplicationInformation({
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.oauth2CurrentApplication(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIOAuth2CurrentApplicationResult>;
|
||||
}
|
||||
@@ -119,9 +138,18 @@ export class OAuth2API {
|
||||
* @see {@link https://discord.com/developers/docs/topics/oauth2#get-current-authorization-information}
|
||||
* @param options - The options for the current authorization information request
|
||||
*/
|
||||
public async getCurrentAuthorizationInformation({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getCurrentAuthorizationInformation({
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.oauth2CurrentAuthorization(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIOAuth2CurrentAuthorizationResult>;
|
||||
}
|
||||
@@ -139,16 +167,19 @@ export class OAuth2API {
|
||||
applicationId: Snowflake,
|
||||
applicationSecret: string,
|
||||
body: RESTPostOAuth2TokenRevocationQuery,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
await this.rest.post(Routes.oauth2TokenRevocation(), {
|
||||
body: makeURLSearchParams(body),
|
||||
passThroughBody: true,
|
||||
headers: {
|
||||
...headers,
|
||||
Authorization: `Basic ${btoa(`${applicationId}:${applicationSecret}`)}`,
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
auth: false,
|
||||
dispatcher,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIPollAnswerVotersQuery,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type RESTPostAPIPollExpireResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class PollAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -27,10 +28,13 @@ export class PollAPI {
|
||||
messageId: Snowflake,
|
||||
answerId: number,
|
||||
query: RESTGetAPIPollAnswerVotersQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.pollAnswerVoters(channelId, messageId, answerId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
query: makeURLSearchParams(query),
|
||||
}) as Promise<RESTGetAPIPollAnswerVotersResult>;
|
||||
@@ -47,10 +51,13 @@ export class PollAPI {
|
||||
public async expirePoll(
|
||||
channelId: Snowflake,
|
||||
messageId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.expirePoll(channelId, messageId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIPollExpireResult>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIApplicationRoleConnectionMetadataResult,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type RESTPutAPIApplicationRoleConnectionMetadataJSONBody,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class RoleConnectionsAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -21,10 +22,13 @@ export class RoleConnectionsAPI {
|
||||
*/
|
||||
public async getMetadataRecords(
|
||||
applicationId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.applicationRoleConnectionMetadata(applicationId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIApplicationRoleConnectionMetadataResult>;
|
||||
}
|
||||
@@ -40,11 +44,14 @@ export class RoleConnectionsAPI {
|
||||
public async updateMetadataRecords(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPutAPIApplicationRoleConnectionMetadataJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPutAPIApplicationRoleConnectionMetadataResult>;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import { Routes, type RESTGetAPISoundboardDefaultSoundsResult } from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class SoundboardSoundsAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -12,9 +13,18 @@ export class SoundboardSoundsAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/soundboard#list-default-soundboard-sounds}
|
||||
* @param options - The options for fetching the soundboard default sounds.
|
||||
*/
|
||||
public async getSoundboardDefaultSounds({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getSoundboardDefaultSounds({
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.soundboardDefaultSounds(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPISoundboardDefaultSoundsResult>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import {
|
||||
type Snowflake,
|
||||
type RESTGetAPIStageInstanceResult,
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
type RESTPostAPIStageInstanceResult,
|
||||
Routes,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js';
|
||||
|
||||
export class StageInstancesAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -23,12 +24,15 @@ export class StageInstancesAPI {
|
||||
*/
|
||||
public async create(
|
||||
body: RESTPostAPIStageInstanceJSONBody,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.post(Routes.stageInstances(), {
|
||||
auth,
|
||||
body,
|
||||
reason,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIStageInstanceResult>;
|
||||
}
|
||||
@@ -40,8 +44,17 @@ export class StageInstancesAPI {
|
||||
* @param channelId - The id of the channel
|
||||
* @param options - The options for fetching the stage instance
|
||||
*/
|
||||
public async get(channelId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.stageInstance(channelId), { auth, signal }) as Promise<RESTGetAPIStageInstanceResult>;
|
||||
public async get(
|
||||
channelId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.stageInstance(channelId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIStageInstanceResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +68,15 @@ export class StageInstancesAPI {
|
||||
public async edit(
|
||||
channelId: Snowflake,
|
||||
body: RESTPatchAPIStageInstanceJSONBody,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.stageInstance(channelId), {
|
||||
auth,
|
||||
body,
|
||||
reason,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIStageInstanceResult>;
|
||||
}
|
||||
@@ -74,8 +90,15 @@ export class StageInstancesAPI {
|
||||
*/
|
||||
public async delete(
|
||||
channelId: Snowflake,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.stageInstance(channelId), { auth, reason, signal });
|
||||
await this.rest.delete(Routes.stageInstance(channelId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIStickerPackResult,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type RESTGetStickerPacksResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class StickersAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -19,8 +20,17 @@ export class StickersAPI {
|
||||
* @param packId - The id of the sticker pack
|
||||
* @param options - The options for fetching the sticker pack
|
||||
*/
|
||||
public async getStickerPack(packId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.stickerPack(packId), { auth, signal }) as Promise<RESTGetAPIStickerPackResult>;
|
||||
public async getStickerPack(
|
||||
packId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.stickerPack(packId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIStickerPackResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,8 +39,14 @@ export class StickersAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/sticker#list-sticker-packs}
|
||||
* @param options - The options for fetching the sticker packs
|
||||
*/
|
||||
public async getStickers({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.stickerPacks(), { auth, signal }) as Promise<RESTGetStickerPacksResult>;
|
||||
public async getStickers({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.stickerPacks(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetStickerPacksResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +56,16 @@ export class StickersAPI {
|
||||
* @param stickerId - The id of the sticker
|
||||
* @param options - The options for fetching the sticker
|
||||
*/
|
||||
public async get(stickerId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.sticker(stickerId), { auth, signal }) as Promise<RESTGetAPIStickerResult>;
|
||||
public async get(
|
||||
stickerId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.sticker(stickerId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIStickerResult>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIChannelThreadMemberQuery,
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type RESTGetAPIChannelThreadMembersResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions } from '../util/types.js';
|
||||
|
||||
export class ThreadsAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -20,8 +21,17 @@ export class ThreadsAPI {
|
||||
* @param threadId - The id of the thread to join
|
||||
* @param options - The options for joining the thread
|
||||
*/
|
||||
public async join(threadId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
await this.rest.put(Routes.threadMembers(threadId, '@me'), { auth, signal });
|
||||
public async join(
|
||||
threadId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.put(Routes.threadMembers(threadId, '@me'), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,9 +45,15 @@ export class ThreadsAPI {
|
||||
public async addMember(
|
||||
threadId: Snowflake,
|
||||
userId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.put(Routes.threadMembers(threadId, userId), { auth, signal });
|
||||
await this.rest.put(Routes.threadMembers(threadId, userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,8 +63,17 @@ export class ThreadsAPI {
|
||||
* @param threadId - The id of the thread to leave
|
||||
* @param options - The options for leaving the thread
|
||||
*/
|
||||
public async leave(threadId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
await this.rest.delete(Routes.threadMembers(threadId, '@me'), { auth, signal });
|
||||
public async leave(
|
||||
threadId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.threadMembers(threadId, '@me'), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,9 +87,15 @@ export class ThreadsAPI {
|
||||
public async removeMember(
|
||||
threadId: Snowflake,
|
||||
userId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.threadMembers(threadId, userId), { auth, signal });
|
||||
await this.rest.delete(Routes.threadMembers(threadId, userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +111,7 @@ export class ThreadsAPI {
|
||||
threadId: Snowflake,
|
||||
userId: Snowflake,
|
||||
query: RESTGetAPIChannelThreadMemberQuery & { with_member: true },
|
||||
options?: Pick<RequestData, 'auth' | 'signal'>,
|
||||
options?: RequestOptions,
|
||||
): Promise<Required<Pick<RESTGetAPIChannelThreadMemberResult, 'member'>> & RESTGetAPIChannelThreadMemberResult>;
|
||||
|
||||
/**
|
||||
@@ -96,17 +127,20 @@ export class ThreadsAPI {
|
||||
threadId: Snowflake,
|
||||
userId: Snowflake,
|
||||
query?: RESTGetAPIChannelThreadMemberQuery,
|
||||
options?: Pick<RequestData, 'auth' | 'signal'>,
|
||||
options?: RequestOptions,
|
||||
): Promise<RESTGetAPIChannelThreadMemberResult>;
|
||||
|
||||
public async getMember(
|
||||
threadId: Snowflake,
|
||||
userId: Snowflake,
|
||||
query: RESTGetAPIChannelThreadMemberQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.threadMembers(threadId, userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
query: makeURLSearchParams(query),
|
||||
});
|
||||
@@ -123,10 +157,13 @@ export class ThreadsAPI {
|
||||
public async getMembers(
|
||||
threadId: Snowflake,
|
||||
query: RESTGetAPIChannelThreadMembersQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.threadMembers(threadId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
query: makeURLSearchParams(query),
|
||||
}) as Promise<RESTGetAPIChannelThreadMembersResult>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPICurrentUserApplicationRoleConnectionResult,
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
type RESTPutAPICurrentUserApplicationRoleConnectionResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js';
|
||||
|
||||
export class UsersAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -30,8 +31,14 @@ export class UsersAPI {
|
||||
* @param userId - The id of the user to fetch
|
||||
* @param options - The options for fetching the user
|
||||
*/
|
||||
public async get(userId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.user(userId), { auth, signal }) as Promise<RESTGetAPIUserResult>;
|
||||
public async get(userId: Snowflake, { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.user(userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIUserResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,8 +47,14 @@ export class UsersAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/user#get-current-user}
|
||||
* @param options - The options for fetching the current user
|
||||
*/
|
||||
public async getCurrent({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.user('@me'), { auth, signal }) as Promise<RESTGetAPICurrentUserResult>;
|
||||
public async getCurrent({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.user('@me'), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPICurrentUserResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,11 +66,14 @@ export class UsersAPI {
|
||||
*/
|
||||
public async getGuilds(
|
||||
query: RESTGetAPICurrentUserGuildsQuery = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.userGuilds(), {
|
||||
auth,
|
||||
query: makeURLSearchParams(query),
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPICurrentUserGuildsResult>;
|
||||
}
|
||||
@@ -69,8 +85,11 @@ export class UsersAPI {
|
||||
* @param guildId - The id of the guild
|
||||
* @param options - The options for leaving the guild
|
||||
*/
|
||||
public async leaveGuild(guildId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
await this.rest.delete(Routes.userGuild(guildId), { auth, signal });
|
||||
public async leaveGuild(
|
||||
guildId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.userGuild(guildId), { auth, dispatcher, headers, rejectOnRateLimit, signal });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,9 +101,16 @@ export class UsersAPI {
|
||||
*/
|
||||
public async edit(
|
||||
body: RESTPatchAPICurrentUserJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.user('@me'), { auth, body, signal }) as Promise<RESTPatchAPICurrentUserResult>;
|
||||
return this.rest.patch(Routes.user('@me'), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPICurrentUserResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,9 +120,15 @@ export class UsersAPI {
|
||||
* @param guildId - The id of the guild
|
||||
* @param options - The options for fetching the guild member
|
||||
*/
|
||||
public async getGuildMember(guildId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getGuildMember(
|
||||
guildId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.userGuildMember(guildId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetCurrentUserGuildMemberResult>;
|
||||
}
|
||||
@@ -112,12 +144,15 @@ export class UsersAPI {
|
||||
public async editCurrentGuildMember(
|
||||
guildId: Snowflake,
|
||||
body: RESTPatchAPICurrentGuildMemberJSONBody = {},
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.guildMember(guildId, '@me'), {
|
||||
auth,
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIGuildMemberResult>;
|
||||
}
|
||||
@@ -129,10 +164,16 @@ export class UsersAPI {
|
||||
* @param userId - The id of the user to open a DM channel with
|
||||
* @param options - The options for opening the DM
|
||||
*/
|
||||
public async createDM(userId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async createDM(
|
||||
userId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.userChannels(), {
|
||||
auth,
|
||||
body: { recipient_id: userId },
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>;
|
||||
}
|
||||
@@ -143,8 +184,14 @@ export class UsersAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/user#get-user-connections}
|
||||
* @param options - The options for fetching the user's connections
|
||||
*/
|
||||
public async getConnections({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.userConnections(), { auth, signal }) as Promise<RESTGetAPICurrentUserConnectionsResult>;
|
||||
public async getConnections({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.userConnections(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPICurrentUserConnectionsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,10 +203,13 @@ export class UsersAPI {
|
||||
*/
|
||||
public async getApplicationRoleConnection(
|
||||
applicationId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.userApplicationRoleConnection(applicationId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPICurrentUserApplicationRoleConnectionResult>;
|
||||
}
|
||||
@@ -175,11 +225,14 @@ export class UsersAPI {
|
||||
public async updateApplicationRoleConnection(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.put(Routes.userApplicationRoleConnection(applicationId), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPutAPICurrentUserApplicationRoleConnectionResult>;
|
||||
}
|
||||
@@ -193,10 +246,13 @@ export class UsersAPI {
|
||||
*/
|
||||
public async deleteApplicationRoleConnection(
|
||||
applicationId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.userApplicationRoleConnection(applicationId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RequestData, REST } from '@discordjs/rest';
|
||||
import type { REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type Snowflake,
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
|
||||
type RESTPatchAPIGuildVoiceStateUserResult,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js';
|
||||
|
||||
export class VoiceAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
@@ -22,8 +23,14 @@ export class VoiceAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/voice#list-voice-regions}
|
||||
* @param options - The options for fetching the voice regions
|
||||
*/
|
||||
public async getVoiceRegions({ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
return this.rest.get(Routes.voiceRegions(), { auth, signal }) as Promise<RESTGetAPIVoiceRegionsResult>;
|
||||
public async getVoiceRegions({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) {
|
||||
return this.rest.get(Routes.voiceRegions(), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIVoiceRegionsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,10 +42,13 @@ export class VoiceAPI {
|
||||
public async getUserVoiceState(
|
||||
guildId: Snowflake,
|
||||
userId: Snowflake,
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.guildVoiceState(guildId, userId), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIGuildVoiceStateUserResult>;
|
||||
}
|
||||
@@ -49,9 +59,15 @@ export class VoiceAPI {
|
||||
* @see {@link https://discord.com/developers/docs/resources/voice#get-current-user-voice-state}
|
||||
* @param options - The options for fetching user voice state
|
||||
*/
|
||||
public async getVoiceState(guildId: Snowflake, { auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {}) {
|
||||
public async getVoiceState(
|
||||
guildId: Snowflake,
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.guildVoiceState(guildId, '@me'), {
|
||||
auth,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIGuildVoiceStateCurrentMemberResult>;
|
||||
}
|
||||
@@ -69,12 +85,15 @@ export class VoiceAPI {
|
||||
guildId: Snowflake,
|
||||
userId: Snowflake,
|
||||
body: RESTPatchAPIGuildVoiceStateUserJSONBody,
|
||||
{ auth, reason, signal }: Pick<RequestData, 'auth' | 'reason' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.guildVoiceState(guildId, userId), {
|
||||
auth,
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIGuildVoiceStateUserResult>;
|
||||
}
|
||||
@@ -90,11 +109,14 @@ export class VoiceAPI {
|
||||
public async editVoiceState(
|
||||
guildId: Snowflake,
|
||||
body: RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody = {},
|
||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||
{ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.guildVoiceState(guildId, '@me'), {
|
||||
auth,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPatchAPIGuildVoiceStateCurrentMemberResult>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type RawFile, type REST } from '@discordjs/rest';
|
||||
import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIWebhookWithTokenMessageQuery,
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
type RESTDeleteAPIWebhookWithTokenMessageQuery,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { BaseRequestOptions, BaseRequestOptionsWithReason } from '../util/types.js';
|
||||
|
||||
export type CreateWebhookMessageOptions = RESTPostAPIWebhookWithTokenJSONBody &
|
||||
RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] };
|
||||
@@ -41,9 +42,12 @@ export class WebhooksAPI {
|
||||
*/
|
||||
public async get(
|
||||
id: Snowflake,
|
||||
{ token, signal }: Pick<RequestData, 'signal'> & { token?: string | undefined } = {},
|
||||
{ token, dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions & { token?: string | undefined } = {},
|
||||
) {
|
||||
return this.rest.get(Routes.webhook(id, token), {
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
auth: !token,
|
||||
}) as Promise<RESTGetAPIWebhookResult>;
|
||||
@@ -61,11 +65,21 @@ export class WebhooksAPI {
|
||||
public async edit(
|
||||
id: Snowflake,
|
||||
body: RESTPatchAPIWebhookJSONBody,
|
||||
{ token, reason, signal }: Pick<RequestData, 'reason' | 'signal'> & { token?: string | undefined } = {},
|
||||
{
|
||||
token,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}: BaseRequestOptionsWithReason & { token?: string | undefined } = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.webhook(id, token), {
|
||||
reason,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
auth: !token,
|
||||
}) as Promise<RESTPatchAPIWebhookResult>;
|
||||
@@ -81,10 +95,20 @@ export class WebhooksAPI {
|
||||
*/
|
||||
public async delete(
|
||||
id: Snowflake,
|
||||
{ token, reason, signal }: Pick<RequestData, 'reason' | 'signal'> & { token?: string | undefined } = {},
|
||||
{
|
||||
token,
|
||||
dispatcher,
|
||||
headers,
|
||||
reason,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}: BaseRequestOptionsWithReason & { token?: string | undefined } = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.webhook(id, token), {
|
||||
reason,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
auth: !token,
|
||||
});
|
||||
@@ -103,7 +127,7 @@ export class WebhooksAPI {
|
||||
id: Snowflake,
|
||||
token: string,
|
||||
body: CreateWebhookMessageOptions & { wait: true },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<RESTPostAPIWebhookWithTokenWaitResult>;
|
||||
|
||||
/**
|
||||
@@ -119,7 +143,7 @@ export class WebhooksAPI {
|
||||
id: Snowflake,
|
||||
token: string,
|
||||
body: CreateWebhookMessageOptions & { wait?: false },
|
||||
options?: Pick<RequestData, 'signal'>,
|
||||
options?: BaseRequestOptions,
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
@@ -135,13 +159,16 @@ export class WebhooksAPI {
|
||||
id: Snowflake,
|
||||
token: string,
|
||||
{ wait, thread_id, with_components, files, ...body }: CreateWebhookMessageOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.post(Routes.webhook(id, token), {
|
||||
query: makeURLSearchParams({ wait, thread_id, with_components }),
|
||||
files,
|
||||
body,
|
||||
auth: false,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIWebhookWithTokenWaitResult | void>;
|
||||
}
|
||||
@@ -161,12 +188,15 @@ export class WebhooksAPI {
|
||||
token: string,
|
||||
body: unknown,
|
||||
query: RESTPostAPIWebhookWithTokenSlackQuery = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
await this.rest.post(Routes.webhookPlatform(id, token, 'slack'), {
|
||||
query: makeURLSearchParams(query),
|
||||
body,
|
||||
auth: false,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
@@ -186,11 +216,14 @@ export class WebhooksAPI {
|
||||
token: string,
|
||||
body: unknown,
|
||||
query: RESTPostAPIWebhookWithTokenGitHubQuery = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
await this.rest.post(Routes.webhookPlatform(id, token, 'github'), {
|
||||
query: makeURLSearchParams(query),
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
auth: false,
|
||||
});
|
||||
@@ -211,11 +244,14 @@ export class WebhooksAPI {
|
||||
token: string,
|
||||
messageId: Snowflake,
|
||||
query: RESTGetAPIWebhookWithTokenMessageQuery = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.get(Routes.webhookMessage(id, token, messageId), {
|
||||
query: makeURLSearchParams(query),
|
||||
auth: false,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
}) as Promise<RESTGetAPIWebhookWithTokenMessageResult>;
|
||||
}
|
||||
@@ -235,12 +271,15 @@ export class WebhooksAPI {
|
||||
token: string,
|
||||
messageId: Snowflake,
|
||||
{ thread_id, with_components, files, ...body }: EditWebhookMessageOptions,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
return this.rest.patch(Routes.webhookMessage(id, token, messageId), {
|
||||
query: makeURLSearchParams({ thread_id, with_components }),
|
||||
auth: false,
|
||||
body,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
files,
|
||||
}) as Promise<RESTPatchAPIWebhookWithTokenMessageResult>;
|
||||
@@ -261,11 +300,14 @@ export class WebhooksAPI {
|
||||
token: string,
|
||||
messageId: Snowflake,
|
||||
query: RESTDeleteAPIWebhookWithTokenMessageQuery = {},
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
{ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.webhookMessage(id, token, messageId), {
|
||||
query: makeURLSearchParams(query),
|
||||
auth: false,
|
||||
dispatcher,
|
||||
headers,
|
||||
rejectOnRateLimit,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './files.js';
|
||||
export type * from './types.js';
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { RequestData } from '@discordjs/rest';
|
||||
|
||||
/**
|
||||
* Per-request options accepted by API methods that do not take alternate authorization
|
||||
*/
|
||||
export type BaseRequestOptions = Pick<RequestData, 'dispatcher' | 'headers' | 'rejectOnRateLimit' | 'signal'>;
|
||||
|
||||
/**
|
||||
* Per-request options accepted by API methods that take an audit log reason but no alternate authorization
|
||||
*/
|
||||
export type BaseRequestOptionsWithReason = BaseRequestOptions & Pick<RequestData, 'reason'>;
|
||||
|
||||
/**
|
||||
* Per-request options accepted by API methods
|
||||
*/
|
||||
export type RequestOptions = BaseRequestOptions & Pick<RequestData, 'auth'>;
|
||||
|
||||
/**
|
||||
* Per-request options accepted by API methods that take an audit log reason
|
||||
*/
|
||||
export type RequestOptionsWithReason = Pick<RequestData, 'reason'> & RequestOptions;
|
||||
@@ -321,7 +321,7 @@ export interface RequestData {
|
||||
/**
|
||||
* The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request.
|
||||
*/
|
||||
dispatcher?: Agent;
|
||||
dispatcher?: Agent | undefined;
|
||||
/**
|
||||
* Files to be attached to this request
|
||||
*/
|
||||
@@ -329,7 +329,7 @@ export interface RequestData {
|
||||
/**
|
||||
* Additional headers to add to this request
|
||||
*/
|
||||
headers?: Record<string, string>;
|
||||
headers?: Record<string, string> | undefined;
|
||||
/**
|
||||
* Whether to pass-through the body property directly to `fetch()`.
|
||||
* <warn>This only applies when files is NOT present</warn>
|
||||
|
||||
Reference in New Issue
Block a user