UNPKG

disci

Version:

A HTTP Request handler for discord interactions

1,062 lines (1,045 loc) 33 kB
import { EventEmitter } from 'eventemitter3'; import { Snowflake, APIUser, MessageFlags, ChannelFlags, WebhookType, APIWebhook, ChannelType, APIChannel, APITextChannel, APIDMChannel, APIThreadChannel, ThreadAutoArchiveDuration, AllowedMentionsTypes, APIEmbed, APIActionRowComponent, APIMessageActionRowComponent, APIMessage, GuildFeature, APIGuild, GuildIconFormat, APIGuildMember, InteractionType, ApplicationCommandType, APIApplicationCommandAutocompleteInteraction, APIApplicationCommandOptionChoice, APIMessageComponentInteraction, APIInteraction, LocaleString, APIInteractionResponse, APIApplicationCommandInteractionDataOption, APIApplicationCommandInteractionDataBasicOption, APIInteractionDataResolvedGuildMember, APIApplicationCommandInteraction, APIChatInputApplicationCommandInteraction, APIMessageApplicationCommandInteraction, APIUserApplicationCommandInteraction } from 'discord-api-types/v10'; import { Snowflake as Snowflake$1 } from 'discord-api-types/globals'; interface RestClient { makeRequest: <T>(method: string, path: string, opts: RESTCommonOptions) => Promise<T>; authToken: string | null; rootUrl: string; } interface RESTClientOptions { /** * Client token, alternatively provide it with \<rest\>.setToken */ token?: string; authPrefix?: "bot"; rootUrl?: string; } interface RESTFile { /** * Content-Type of the file */ contentType?: string; /** * The actual data for the file */ data: Buffer | Uint8Array | boolean | number | string; /** * An explicit key to use for key of the formdata field for this file. * When not provided, the index of the file in the files array is used in the form `files[${index}]`. * If you wish to alter the placeholder snowflake, you must provide this property in the same form (`files[${placeholder}]`) */ key?: string; /** * The name of the file */ name: string; } interface RESTCommonOptions { headers?: Record<string, string>; body?: Record<string, unknown>; query?: Record<string, unknown> | URLSearchParams; /** * Files to be attached to this request */ files?: RESTFile[]; /** * Whether to append JSON data to form data instead of `payload_json` when sending files */ appendBodyToForm?: boolean; /** * If this request needs the `Authorization` header */ auth?: boolean; /** * Reason to show in the audit logs * */ reason?: string; } /** * Default rest handler, built for serverLess Environments without any rate limit checks */ declare class Rest implements RestClient { authPrefix: string; authToken: string | null; rootUrl: string; /** * for support of serverless and other platforms */ constructor(_opts: RESTClientOptions); /** * Set the current active token, request may fail if this is not set * @param token * @returns */ setToken(token: string): this; makeRequest<T>(method: string, path: string, opts?: RESTCommonOptions): Promise<T>; get<T>(path: string, opts?: RESTCommonOptions): Promise<T>; post<T>(path: string, opts?: RESTCommonOptions): Promise<T>; put<T>(path: string, opts?: RESTCommonOptions): Promise<T>; patch<T>(path: string, opts?: RESTCommonOptions): Promise<T>; delete<T>(path: string, opts?: RESTCommonOptions): Promise<T>; private getUrl; get authHeader(): string; getRequest(path: string, method: string, options?: RESTCommonOptions): { init: RequestInit; url: string; }; } /** * Base Interface for other structures to implement on. * All toplevel structures MUST implement this structure */ interface IBase { /** * The InteractionHandler that initialised this structure */ readonly handler: InteractionHandler; } /** * Partial Class for accessing Discord Api with minimal data */ declare class PartialUser implements IBase { /** * The handler than initiated this class */ handler: InteractionHandler; /** * The user's id */ id: Snowflake; constructor(handler: InteractionHandler, data: { id: string; }); /** * Fetch the user this partial belongs to */ fetch(): Promise<User>; toString(): string; } /** * Represents a Discord user * https://discord.com/developers/docs/resources/user#user-object */ declare class User extends PartialUser { apiData: APIUser; /** * The username of this user.Not unique */ username: string; /** * Create a new user from discord data * @param apiData - data from discord api */ constructor(handler: InteractionHandler, apiData: APIUser); /** * Tag of this user. * @deprecated tag is no longer relevant */ get tag(): string; } type BitFieldResolvable = bigint | bigint[] | number | number[] | BitField | BitField[]; /** * Utility structure to help with bitfield creation and manipulation */ declare abstract class BitField { static Flags: unknown; static None: bigint; bitfield: bigint; /** * Create a new Bitfield Instance * @param baseBits - Base bits to institate the class with */ constructor(baseBits?: BitFieldResolvable); /** * Adds bits to the bitfield * @param bits New bits to add * @returns */ add(bits: BitFieldResolvable[]): BitField; /** * Removes bits from the bitfield * @param bits bits to remove * @returns */ remove(bits: BitFieldResolvable[]): BitField; /** * checks if all bits are present in the bitfield * @param bits bits to check * @returns */ has(bits: BitFieldResolvable): boolean; equals(bit: BitFieldResolvable): boolean; static resolve(bit: BitFieldResolvable): bigint; } declare class PermissionsBitField extends BitField { static Flags: { readonly CreateInstantInvite: bigint; readonly KickMembers: bigint; readonly BanMembers: bigint; readonly Administrator: bigint; readonly ManageChannels: bigint; readonly ManageGuild: bigint; readonly AddReactions: bigint; readonly ViewAuditLog: bigint; readonly PrioritySpeaker: bigint; readonly Stream: bigint; readonly ViewChannel: bigint; readonly SendMessages: bigint; readonly SendTTSMessages: bigint; readonly ManageMessages: bigint; readonly EmbedLinks: bigint; readonly AttachFiles: bigint; readonly ReadMessageHistory: bigint; readonly MentionEveryone: bigint; readonly UseExternalEmojis: bigint; readonly ViewGuildInsights: bigint; readonly Connect: bigint; readonly Speak: bigint; readonly MuteMembers: bigint; readonly DeafenMembers: bigint; readonly MoveMembers: bigint; readonly UseVAD: bigint; readonly ChangeNickname: bigint; readonly ManageNicknames: bigint; readonly ManageRoles: bigint; readonly ManageWebhooks: bigint; readonly ManageEmojisAndStickers: bigint; readonly UseApplicationCommands: bigint; readonly RequestToSpeak: bigint; readonly ManageEvents: bigint; readonly ManageThreads: bigint; readonly CreatePublicThreads: bigint; readonly CreatePrivateThreads: bigint; readonly UseExternalStickers: bigint; readonly SendMessagesInThreads: bigint; readonly UseEmbeddedActivities: bigint; readonly ModerateMembers: bigint; }; [Symbol.iterator](): Generator<string, void, undefined>; get array(): string[]; } declare class MessageFlagsBitField extends BitField { static Flags: typeof MessageFlags; } declare class ChannelFlagsBitField extends BitField { static Flags: typeof ChannelFlags; } declare class WebhookPartial implements IBase { /** * The handler than initiated this class */ handler: InteractionHandler; /** * The id of the webhook */ id: Snowflake$1; /** * The secure token of the webhook */ token?: string; constructor(handler: InteractionHandler, data: { id: string; token?: string; }); /** * Fetch the webhook this id belongs to */ fetch(): Promise<Webhook>; } declare class Webhook extends WebhookPartial { /** *The type of the webhook * *See https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types */ type: WebhookType; /** * Owner of this webhook */ owner: User | null; /** * The application that created this werbhook */ applicationId: string | null; constructor(handler: InteractionHandler, data: APIWebhook); /** * Gets a message that was sent by this webhook. */ fetchMessage(messageId: string | "@original", { threadId }?: { threadId?: string; }): Promise<Message>; /** * * @param messageId id of the message to edit * @param newMessage new data to edit */ editReply(messageId: string, newMessage: CreateMessageParams): Promise<Message>; /** * Sends a message with this webhook. */ send(messageData: CreateMessageParams, { threadId }?: { threadId?: string; }): Promise<Message>; } /** * BaseChannel for all other classes */ declare class GenericPartialChannel implements IBase { handler: InteractionHandler; /** * Id of this channel */ id: Snowflake; constructor(handler: InteractionHandler, data: { id: string; }); toString(): string; /** * TimeStamp of when this channel was created */ get createdTimestamp(): number; /** * The time the channel was created */ get createdAt(): Date; /** * Fetch the channel represented by the partial */ fetch(): Promise<BaseChannel | null>; } declare class BaseChannel extends GenericPartialChannel { /** * Type of this channel */ type: ChannelType; /** * Name of this channel */ name?: string | null; flags: ChannelFlagsBitField; /** * * @param handler * @param apiChannel */ constructor(handler: InteractionHandler, apiChannel: APIChannel); isGuildChannel(): this is GuildTextChannel; isTextBased(): this is BaseTextChannel; isThreadChannel(): this is ThreadChannel; } /** * Base for all text channels */ declare class BaseTextChannel extends BaseChannel { constructor(handler: InteractionHandler, apiChannel: APITextChannel | APIDMChannel); } declare class GuildTextChannel extends BaseTextChannel { type: ChannelType; guildId: string; nsfw: boolean; constructor(handler: InteractionHandler, apiChannel: APITextChannel); } declare class ThreadChannel extends BaseChannel { rawThread: APIThreadChannel; /** * ID of the Parent channel of this thread */ parentId: string | null; /** * Parent channel of this thread */ parent?: GenericPartialChannel; /** * ID of the thread creator */ ownerId: string | null; /** * The thread creator as a user */ owner?: PartialUser; /** * Number of messages (not including the initial message or deleted messages) in a thread * */ messageCount: number; /** * Total count of messages ever sent in this thread */ totalSentMessages: number | null; /** * Whether the thread is archived */ archived: boolean; /** * Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080 */ autoArchiveDuration: ThreadAutoArchiveDuration; /** * Whether the thread is locked; when a thread is locked, only users with `MANAGE_THREADS` can unarchive it */ locked: boolean; /** * Whether non-moderators can add other non-moderators to the thread; only available on private threads */ invitable: boolean; archivedTimeStamp: string; constructor(handler: InteractionHandler, apiThread: APIThreadChannel); get archivedAt(): Date; get createdAt(): Date; } type EmojiResolvable = string | { name: string; id: string; }; /** * @link https://discord.com/developers/docs/resources/channel#allowed-mentions-object */ interface AllowedMentions { parse?: AllowedMentionsTypes[]; repliedUser?: boolean; roles?: Snowflake[]; users?: Snowflake[]; } /** * @link https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure * channel_id is optional when creating a reply, but will always be present when receiving an event/response that includes this data model. */ interface MessageReference { messageId: Snowflake; channelId?: Snowflake; guildId?: Snowflake; failIfNotExists?: boolean; } /** * @link https://discord.com/developers/docs/resources/channel#create-message-jsonform-params * Params used for sending of Messages */ interface CreateMessageParams { /** * Message contents (up to 2000 characters) */ content?: string; /** * Array of Embeds (max 10) */ embeds?: APIEmbed[]; /** * Allowed mentions for the message */ allowedMentions?: AllowedMentions; /** * Include to make your message a reply */ messageReference?: MessageReference; /** * The components belonging to this message */ components?: APIActionRowComponent<APIMessageActionRowComponent>[]; files?: RESTFile[]; /** * Message flags to be used */ flags?: MessageFlagsBitField | BitFieldResolvable; } declare class Message implements IBase { readonly handler: InteractionHandler; /** * Id of this message */ id: Snowflake; /** * Embeds for this message */ embeds: APIEmbed[]; /** * Content of this message */ content?: string; /** * Timestamp of the message was sent at */ createdTimestamp: number; /** * TImestamp of when this message was last edited (if applicable) */ editedTimestamp: number | null; /** * The user who created this message (if created by a user) */ author?: User; /** * Webhook that created this message (if created by webhook) */ webhook?: WebhookPartial; /** * Channel this message was created in */ channelId: string; channel: GenericPartialChannel; /** * Flags for this message */ flags: MessageFlagsBitField; constructor(handler: InteractionHandler, apiData: APIMessage); /** * The time the message was sent at */ get createdAt(): Date; /** * The time the message was last edited at (if applicable) */ get editedAt(): Date | undefined; /** * Whether this message has a thread associated with it */ get hasThread(): boolean; /** * Delete this Message */ delete(): Promise<this>; addReaction(emoji: EmojiResolvable): Promise<void>; /** * Pins this message */ pin(): Promise<void>; /** * Unpin this message */ unpin(): Promise<void>; /** * Creates a new thread from an existing message. * @param threadOptions Options for this thread * @returns */ startThread(threadOptions: { name: string; rateLimitPerUser?: number; autoArchiveDuration?: number; }): Promise<ThreadChannel>; /** * Internal method to resolve data for message Create * @private */ static resolveMessageParams<T extends Record<string, unknown>>(params: CreateMessageParams): { body: T; files: RESTFile[]; }; } declare class PartialGuild implements IBase { handler: InteractionHandler; /** * Id of this guild */ id: string; constructor(handler: InteractionHandler, { id }: { id: string; }); /** * Fetch the guild this partial belongs to * @param opts.withCounts when true, will return approximate member and presence counts for the guild */ fetch({ withCounts }?: { withCounts?: boolean; }): Promise<Guild>; } /** * Represents a discord guild */ declare class Guild extends PartialGuild { /** * Owner of this Guild as a partial */ owner: PartialUser; /** * Name of this guild */ name: string; /** * Approximate Member count not always present (use Guild.fetch() with "withCounts" enabled) */ approximateMemberCount?: number; /** * Approximate Presence count not always present (use Guild.fetch() with "withCounts" enabled) */ approximatePresenceCount?: number; /** * The description for the guild */ description: string | null; /** * Enabled guild features (animated banner, news, auto moderation, etc). * @link https://discord.com/developers/docs/resources/guild#guild-object-guild-features */ features: GuildFeature[]; /** * Icon hash for this guild's Icon * @link https://discord.com/developers/docs/reference#image-formatting */ iconHash: string | null; constructor(handler: InteractionHandler, apiData: APIGuild); /** * boolean to indicate if this guild is a verified guild or not */ get verified(): boolean; /** * boolean to indicate if this guild is a partnered guild or not */ get partnered(): boolean; /** * TimeStamp of when this guild was created */ get createdTimestamp(): number; /** * The time this guild was created as a date */ get createdAt(): Date; /** * iconURL gets the current guild icon. * @link https://discord.com/developers/docs/reference#image-formatting */ iconURL(opts?: { size?: DiscordImageSize; format?: GuildIconFormat; }): string | null; } /** * Represents a Member of a discord guild */ declare class Member implements IBase { handler: InteractionHandler; /** * User instance belonging to this member */ user: User; constructor(handler: InteractionHandler, apiMember: APIGuildMember); toString(): string; } /** * Represents a Autocomplete interaction */ declare class AutoCompleteInteraction extends BaseInteraction implements IBase { type: InteractionType; /** * Id of the command this autocomplete was sent for */ commandId: Snowflake; /** * Name of the command this autocomplete was sent for */ commandName: string; /** * Type of the command this autocomplete was sent for */ commandType: ApplicationCommandType; /** * Guild id of the command this autocomplete was sent for */ commandGuildId?: Snowflake; options: InteractionOptions; constructor(handler: InteractionHandler, rawData: APIApplicationCommandAutocompleteInteraction); /** * Send autocomplete results * * @example * ```ts * interaction.respond([ * "regular Choice", * { name: 'choice', value: 'choice value' } * ]) * ``` * * @example * ```ts * // for no choices screen * interaction.respond([]) * ``` */ respond(choices: (APIApplicationCommandOptionChoice | string)[]): this; private getChoices; } declare class ComponentInteraction extends BaseReplyInteraction implements IBase { type: InteractionType; customId: string; constructor(handler: InteractionHandler, apiData: APIMessageComponentInteraction); } type CallbackFunction = (data: APIInteractionResponse) => void; /** * Represents an basic interaction. */ declare abstract class BaseInteraction implements IBase { readonly RawInteractionData: APIInteraction; /** * ID of the interaction */ readonly id: Snowflake$1; /** * ID of the application this interaction is for */ readonly applicationId: Snowflake$1; /** * Token of this interaction */ readonly token: string; /** * Type of this interaction */ type: InteractionType; /** * Id of the Guild that the interaction was sent from */ guildId?: string; /** * Guild the interaction was sent from as a partial guild */ guild?: PartialGuild; /** * Id of the Channel that the interaction was sent from */ channelId?: string; /** * Channel the interactions was send from */ channel?: GenericPartialChannel; /** * Readonly Property, as per the Discord docs always 1 * https://discord.com/developers/docs/interactions/receiving-and-responding */ readonly version: 1; appPermissions?: PermissionsBitField; private callback; /** * If this interaction has Already been responded to */ responded: boolean; /** * The user who invoked this interaction */ user?: User; /** * Guild member who invoked this interaction (if any) */ member?: Member; /** * Handler that initiated this class */ readonly handler: InteractionHandler; /** * The preferred locale from the guild this interaction was sent in */ guildLocale: LocaleString | null; /** * Create a new received interaction * @param handler * @param RawInteractionData */ constructor(handler: InteractionHandler, RawInteractionData: APIInteraction); /** * Internal function. define the function used to respond the interaction * @param fn * @private * @ignore */ useCallback(fn: CallbackFunction): this; /** * Timestamp of this interaction */ get createdTimestamp(): number; /** * Created time as a date */ get createdAt(): Date; /** * Indicates whether this interaction is a {@link ApplicationCommand} */ isCommand(): this is ApplicationCommand; /** * Indicates whether this interaction is a {@link AutoCompleteInteraction} */ isAutoComplete(): this is AutoCompleteInteraction; /** * Indicates whether this interaction is a {@link ComponentInteraction} */ isComponent(): this is ComponentInteraction; /** * Indicates whether this interaction can be replied to (i.e {@link BaseReplyInteraction}). */ isRepliable(): this is BaseReplyInteraction; /** * Respond to this interaction, Raw method * @returns * @private * @ignore */ _respond(response: APIInteractionResponse): this; } /** * Base for all repliable to interactions */ declare class BaseReplyInteraction extends BaseInteraction { /** * Defers the reply to the interaction. * @param options options for defer reply * @param options.fetchReply Whether to fetch the reply that was sent * @param options.ephemeral send a ephemeral defer */ deferReply(options?: { fetchReply?: true; ephemeral?: boolean; }): Promise<Message>; /** * Fetch the reply that was sent for this interaction * @returns Message */ fetchReply(): Promise<Message>; /** * reply to this interaction * @param opts * @returns this interaction instance or the message instance after responding if fetchReply is true */ reply(opts: Omit<CreateMessageParams, "files"> & { fetchReply?: false; }): Promise<this>; reply(opts: Omit<CreateMessageParams, "files"> & { fetchReply: true; }): Promise<Message>; /** * Edit previously sent responses */ editReply(message: CreateMessageParams): Promise<Message>; } /** * Utility for working with interaction options */ declare class InteractionOptions { private _options; private subCommand?; private group?; constructor(options: APIApplicationCommandInteractionDataOption[]); /** * Gets the selected subcommand. * @param required If required and Subcommand is found, will throw a error * @returns The name of the selected subcommand, or null if not set and not required. */ getSubCommand(required: true): string; /** * Gets the selected subcommand group. * @param required If required and Subcommand group is found, will throw a error * @returns The name of the selected subcommand group, or null if not set and not required. */ getSubCommandGroup(required: true): string; /** * Get a option by name * @param key Key to get * @param required If required and no options found, will throw a error * @returns The option if found, if required is turned of null will be returned if not found */ get(name: string, required: true): APIApplicationCommandInteractionDataBasicOption; get(name: string, required?: boolean): APIApplicationCommandInteractionDataBasicOption | null; private _getType; /** * Retrive a String option * @param required If required and no String option by name was found, will throw a Error * @returns the value of the string option */ getString(name: string, required: true): string; getString(name: string, required?: boolean): string | null; /** * Retrive a Boolean option * @param required If required and no Boolean option by name was found, will throw a Error * @returns the value of the Boolean option */ getBoolean(name: string, required: true): boolean; getBoolean(name: string, required?: boolean): boolean | null; /** * Retrive a Number option * @param required If required and no Number option by name was found, will throw a Error * @returns the value of the Number option */ getNumber(name: string, required: true): number; getNumber(name: string, required?: boolean): number | null; /** * Retrive a Integer option * @param required If required and no Integer option by name was found, will throw a Error * @returns the value of the Integer option */ getInteger(name: string, required: true): number; getInteger(name: string, required?: boolean): number | null; /** * Retrive a User option * @param required If required and no User option by name was found, will throw a Error * @returns the value of the User (userId) option */ getUserId(name: string, required: true): string; getUserId(name: string, required?: boolean): string | null; /** * Retrive a Channel option * @param required If required and no Channel option by name was found, will throw a Error * @returns the value of the Channel (channelId) option */ getChannelId(name: string, required: true): string; getChannelId(name: string, required?: boolean): string | null; /** * Retrive a Role option * @param required If required and no Role option by name was found, will throw a Error * @returns the value of the Role (roleId) option */ getRolelId(name: string, required: true): string; getRolelId(name: string, required?: boolean): string | null; /** * Retrive a mentionable option * @param required If required and no mentionable option by name was found, will throw a Error * @returns the value of the mentionable option */ getMentionable(name: string, required: true): string; getMentionable(name: string, required?: boolean): string | null; /** * Retreive the currently Focused option, for AutoCompleteInteractions * @param full Whether to get the full option object * @returns The value of the option, or the whole option if full is true */ getFocused(full: true): APIApplicationCommandInteractionDataBasicOption; getFocused(full: false): APIApplicationCommandInteractionDataBasicOption["value"]; } /** * Represents the resolved data of a received command interaction. */ interface CommandInteractionResolvedData { users: Map<Snowflake, User>; members: Map<Snowflake, APIInteractionDataResolvedGuildMember>; roles: Map<Snowflake, unknown>; messages: Map<Snowflake, Message>; } /** * Represents Application commands such as slash commands / menu */ declare abstract class ApplicationCommand extends BaseReplyInteraction implements IBase { type: InteractionType; /** * Type of this command * https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types */ commandType: ApplicationCommandType; /** * Name of this command */ commandName: string; /** * Id Of **The Application command** (not interaction) */ commandId: string; /** * Resolved Data of this interaction */ resolved: CommandInteractionResolvedData; constructor(handler: InteractionHandler, rawData: APIApplicationCommandInteraction); /** * If this is a Message Context menu */ isMessageMenu(): this is MessageCommandInteraction; /** * If this is a User Context menu */ isUserMenu(): this is UserCommandInteraction; /** * If this is a Slash Command */ isSlashCommand(): this is ChatInputInteraction; /** * Alias to isSlashCommand */ isChatInputInteraction(): this is ChatInputInteraction; } declare class ChatInputInteraction extends ApplicationCommand { options: InteractionOptions; commandType: ApplicationCommandType; constructor(handler: InteractionHandler, rawData: APIChatInputApplicationCommandInteraction); } interface ContextMenuInteraction { targetId: Snowflake; } declare class MessageCommandInteraction extends ApplicationCommand { commandType: ApplicationCommandType; constructor(handler: InteractionHandler, rawData: APIMessageApplicationCommandInteraction); } declare class UserCommandInteraction extends ApplicationCommand implements ContextMenuInteraction { commandType: ApplicationCommandType; /** * Id of the Target user */ targetId: Snowflake; /** * Target User */ targetUser?: User; constructor(handler: InteractionHandler, rawData: APIUserApplicationCommandInteraction); } type ApplicationCommands = ChatInputInteraction | MessageCommandInteraction | UserCommandInteraction; /** * @link https://discord.com/developers/docs/reference#image-formatting */ type DiscordImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096; interface HandlerOptions { /** * Options for built in rest client */ rest: RESTClientOptions; } /** * Events fired by the handler */ interface ClientEvents { /** * Fired when a interaction is received * @param interaction - Respective interaction class */ interactionCreate: (interaction: BaseInteraction) => unknown; } /** * Main Handler class, handles incoming request and outputs a response */ declare class InteractionHandler extends EventEmitter<ClientEvents> { options: HandlerOptions; /** * Handler Rest Manager */ api: Rest; constructor(options?: Partial<HandlerOptions>); /** * Process a request and return a response according to the request. * This does not verify the validity of the request * * @param body body of the received request * @param signal Abort controller signal allow you to control when the handler ends (timeouts etc) * @returns A json object containing data to be responded with * * * @example * * ```ts * // get the request here * * // verify it here * if(!(await isVerified(request))) return new Response("Invalid Headers, Unauthorized", { status: 401 }) * * const timeOutAbort = new AbortController(); * const timeout = setTimeout(() => { * timeOutAbort.abort("Time out"); * }, 3000); * * try { * const handled = await processRequest(body, timeOutAbort.signal) * // if it resolved that means handler successfully resolved * // remember to remove the timeout * clearTimeout(timeout) * // it safe to return the response as a json response * return new Response(handled, { status: 200 }) * } * catch { * return new Response("Server Error", { status: 500 }) * } * ``` */ processRequest(body: string | Record<string, unknown>, signal?: AbortSignal): Promise<APIInteractionResponse>; } export { AllowedMentions, ApplicationCommand, ApplicationCommands, AutoCompleteInteraction, BaseInteraction, BaseReplyInteraction, ChatInputInteraction, ClientEvents, CommandInteractionResolvedData, ComponentInteraction, ContextMenuInteraction, CreateMessageParams, EmojiResolvable, HandlerOptions, IBase, InteractionHandler, InteractionOptions, MessageCommandInteraction, MessageReference, PartialGuild, PartialUser, RESTClientOptions, RESTCommonOptions, RESTFile, Rest, RestClient, UserCommandInteraction, Webhook, WebhookPartial };