new
This commit is contained in:
		
							parent
							
								
									7bdbb165f4
								
							
						
					
					
						commit
						dffce5bd0b
					
				
					 2 changed files with 52 additions and 40 deletions
				
			
		|  | @ -44,26 +44,20 @@ export interface InteractionMessageOptions { | ||||||
|   tts?: boolean |   tts?: boolean | ||||||
|   flags?: number | InteractionResponseFlags[] |   flags?: number | InteractionResponseFlags[] | ||||||
|   allowedMentions?: AllowedMentionsPayload |   allowedMentions?: AllowedMentionsPayload | ||||||
|   /** Whether to reply with Source or not. True by default */ |  | ||||||
|   withSource?: boolean |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface InteractionResponse extends InteractionMessageOptions { | export interface InteractionResponse extends InteractionMessageOptions { | ||||||
|   /** Type of Interaction Response */ |   /** Type of Interaction Response */ | ||||||
|   type?: InteractionResponseType |   type?: InteractionResponseType | ||||||
|   /** |  | ||||||
|    * DEPRECATED: Use `ephemeral` instead. |  | ||||||
|    * |  | ||||||
|    * @deprecated |  | ||||||
|    */ |  | ||||||
|   temp?: boolean |  | ||||||
|   /** Whether the Message Response should be Ephemeral (only visible to User) or not */ |   /** Whether the Message Response should be Ephemeral (only visible to User) or not */ | ||||||
|   ephemeral?: boolean |   ephemeral?: boolean | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** Represents a Channel Object for an Option in Slash Command */ | /** Represents a Channel Object for an Option in Slash Command */ | ||||||
| export class InteractionChannel extends SnowflakeBase { | export class InteractionChannel extends SnowflakeBase { | ||||||
|  |   /** Name of the Channel */ | ||||||
|   name: string |   name: string | ||||||
|  |   /** Channel Type */ | ||||||
|   type: ChannelTypes |   type: ChannelTypes | ||||||
|   permissions: Permissions |   permissions: Permissions | ||||||
| 
 | 
 | ||||||
|  | @ -98,17 +92,22 @@ export class Interaction extends SnowflakeBase { | ||||||
|   token: string |   token: string | ||||||
|   /** Interaction ID */ |   /** Interaction ID */ | ||||||
|   id: string |   id: string | ||||||
|   /** Data sent with Interaction. Only applies to Application Command, type may change in future. */ |   /** Data sent with Interaction. Only applies to Application Command */ | ||||||
|   data?: InteractionApplicationCommandData |   data?: InteractionApplicationCommandData | ||||||
|   /** Channel in which Interaction was initiated */ |   /** Channel in which Interaction was initiated */ | ||||||
|   channel?: TextChannel | GuildTextChannel |   channel?: TextChannel | GuildTextChannel | ||||||
|  |   /** Guild in which Interaction was initiated */ | ||||||
|   guild?: Guild |   guild?: Guild | ||||||
|   /** Member object of who initiated the Interaction */ |   /** Member object of who initiated the Interaction */ | ||||||
|   member?: Member |   member?: Member | ||||||
|   /** User object of who invoked Interaction */ |   /** User object of who invoked Interaction */ | ||||||
|   user: User |   user: User | ||||||
|  |   /** Whether we have responded to Interaction or not */ | ||||||
|   responded: boolean = false |   responded: boolean = false | ||||||
|  |   /** Resolved data for Snowflakes in Slash Command Arguments */ | ||||||
|   resolved: InteractionApplicationCommandResolved |   resolved: InteractionApplicationCommandResolved | ||||||
|  |   /** Whether response was deferred or not */ | ||||||
|  |   deferred: boolean = false | ||||||
| 
 | 
 | ||||||
|   constructor( |   constructor( | ||||||
|     client: Client, |     client: Client, | ||||||
|  | @ -159,19 +158,14 @@ export class Interaction extends SnowflakeBase { | ||||||
|   async respond(data: InteractionResponse): Promise<Interaction> { |   async respond(data: InteractionResponse): Promise<Interaction> { | ||||||
|     if (this.responded) throw new Error('Already responded to Interaction') |     if (this.responded) throw new Error('Already responded to Interaction') | ||||||
|     let flags = 0 |     let flags = 0 | ||||||
|     if (data.ephemeral === true || data.temp === true) |     if (data.ephemeral === true) flags |= InteractionResponseFlags.EPHEMERAL | ||||||
|       flags |= InteractionResponseFlags.EPHEMERAL |  | ||||||
|     if (data.flags !== undefined) { |     if (data.flags !== undefined) { | ||||||
|       if (Array.isArray(data.flags)) |       if (Array.isArray(data.flags)) | ||||||
|         flags = data.flags.reduce((p, a) => p | a, flags) |         flags = data.flags.reduce((p, a) => p | a, flags) | ||||||
|       else if (typeof data.flags === 'number') flags |= data.flags |       else if (typeof data.flags === 'number') flags |= data.flags | ||||||
|     } |     } | ||||||
|     const payload: InteractionResponsePayload = { |     const payload: InteractionResponsePayload = { | ||||||
|       type: |       type: data.type ?? InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||||||
|         data.type ?? |  | ||||||
|         (data.withSource === false |  | ||||||
|           ? InteractionResponseType.CHANNEL_MESSAGE |  | ||||||
|           : InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE), |  | ||||||
|       data: |       data: | ||||||
|         data.type === undefined || |         data.type === undefined || | ||||||
|         data.type === InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE || |         data.type === InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE || | ||||||
|  | @ -195,14 +189,12 @@ export class Interaction extends SnowflakeBase { | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** Acknowledge the Interaction */ |   /** Defer the Interaction i.e. let the user know bot is processing and will respond later. You only have 15 minutes to edit the response! */ | ||||||
|   async acknowledge(withSource?: boolean): Promise<Interaction> { |   async defer(): Promise<Interaction> { | ||||||
|     await this.respond({ |     await this.respond({ | ||||||
|       type: |       type: InteractionResponseType.DEFERRED_CHANNEL_MESSAGE | ||||||
|         withSource === true |  | ||||||
|           ? InteractionResponseType.ACK_WITH_SOURCE |  | ||||||
|           : InteractionResponseType.ACKNOWLEDGE |  | ||||||
|     }) |     }) | ||||||
|  |     this.deferred = true | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -228,12 +220,17 @@ export class Interaction extends SnowflakeBase { | ||||||
|     if (options === undefined) options = {} |     if (options === undefined) options = {} | ||||||
|     if (typeof content === 'string') Object.assign(options, { content }) |     if (typeof content === 'string') Object.assign(options, { content }) | ||||||
| 
 | 
 | ||||||
|  |     if (this.deferred && this.responded) { | ||||||
|  |       await this.editResponse({ | ||||||
|  |         content: options.content, | ||||||
|  |         embeds: options.embeds, | ||||||
|  |         flags: options.flags, | ||||||
|  |         allowedMentions: options.allowedMentions | ||||||
|  |       }) | ||||||
|  |     } else | ||||||
|       await this.respond( |       await this.respond( | ||||||
|         Object.assign(options, { |         Object.assign(options, { | ||||||
|         type: |           type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE | ||||||
|           options.withSource === false |  | ||||||
|             ? InteractionResponseType.CHANNEL_MESSAGE |  | ||||||
|             : InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE |  | ||||||
|         }) |         }) | ||||||
|       ) |       ) | ||||||
| 
 | 
 | ||||||
|  | @ -243,7 +240,9 @@ export class Interaction extends SnowflakeBase { | ||||||
|   /** Edit the original Interaction response */ |   /** Edit the original Interaction response */ | ||||||
|   async editResponse(data: { |   async editResponse(data: { | ||||||
|     content?: string |     content?: string | ||||||
|     embeds?: Embed[] |     embeds?: EmbedPayload[] | ||||||
|  |     flags?: number | number[] | ||||||
|  |     allowedMentions?: AllowedMentionsPayload | ||||||
|   }): Promise<Interaction> { |   }): Promise<Interaction> { | ||||||
|     const url = WEBHOOK_MESSAGE( |     const url = WEBHOOK_MESSAGE( | ||||||
|       this.client.user?.id as string, |       this.client.user?.id as string, | ||||||
|  | @ -252,7 +251,12 @@ export class Interaction extends SnowflakeBase { | ||||||
|     ) |     ) | ||||||
|     await this.client.rest.patch(url, { |     await this.client.rest.patch(url, { | ||||||
|       content: data.content ?? '', |       content: data.content ?? '', | ||||||
|       embeds: data.embeds ?? [] |       embeds: data.embeds ?? [], | ||||||
|  |       flags: | ||||||
|  |         typeof data.flags === 'object' | ||||||
|  |           ? data.flags.reduce((p, a) => p | a, 0) | ||||||
|  |           : data.flags, | ||||||
|  |       allowed_mentions: data.allowedMentions | ||||||
|     }) |     }) | ||||||
|     return this |     return this | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -52,6 +52,7 @@ export enum InteractionType { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface InteractionMemberPayload extends MemberPayload { | export interface InteractionMemberPayload extends MemberPayload { | ||||||
|  |   /** Permissions of the Member who initiated Interaction (Guild-only) */ | ||||||
|   permissions: string |   permissions: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -67,9 +68,7 @@ export interface InteractionPayload { | ||||||
|   /** ID of the Interaction */ |   /** ID of the Interaction */ | ||||||
|   id: string |   id: string | ||||||
|   /** |   /** | ||||||
|    * Data sent with the interaction |    * Data sent with the interaction. Undefined only when Interaction is not Slash Command.* | ||||||
|    * |  | ||||||
|    * This can be undefined only when Interaction is not a Slash Command. |  | ||||||
|    */ |    */ | ||||||
|   data?: InteractionApplicationCommandData |   data?: InteractionApplicationCommandData | ||||||
|   /** ID of the Guild in which Interaction was invoked */ |   /** ID of the Guild in which Interaction was invoked */ | ||||||
|  | @ -86,7 +85,9 @@ export interface SlashCommandChoice { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum SlashCommandOptionType { | export enum SlashCommandOptionType { | ||||||
|  |   /** A sub command that is either a part of a root command or Sub Command Group */ | ||||||
|   SUB_COMMAND = 1, |   SUB_COMMAND = 1, | ||||||
|  |   /** A sub command group that is present in root command's options */ | ||||||
|   SUB_COMMAND_GROUP = 2, |   SUB_COMMAND_GROUP = 2, | ||||||
|   STRING = 3, |   STRING = 3, | ||||||
|   INTEGER = 4, |   INTEGER = 4, | ||||||
|  | @ -112,28 +113,35 @@ export interface SlashCommandOption { | ||||||
|   options?: SlashCommandOption[] |   options?: SlashCommandOption[] | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** Represents the Slash Command (Application Command) payload sent for creating/bulk editing. */ | ||||||
| export interface SlashCommandPartial { | export interface SlashCommandPartial { | ||||||
|  |   /** Name of the Slash Command */ | ||||||
|   name: string |   name: string | ||||||
|  |   /** Description of the Slash Command */ | ||||||
|   description: string |   description: string | ||||||
|  |   /** Options (arguments, sub commands or group) of the Slash Command */ | ||||||
|   options?: SlashCommandOption[] |   options?: SlashCommandOption[] | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** Represents a fully qualified Slash Command (Application Command) payload. */ | ||||||
| export interface SlashCommandPayload extends SlashCommandPartial { | export interface SlashCommandPayload extends SlashCommandPartial { | ||||||
|  |   /** ID of the Slash Command */ | ||||||
|   id: string |   id: string | ||||||
|  |   /** Application ID */ | ||||||
|   application_id: string |   application_id: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum InteractionResponseType { | export enum InteractionResponseType { | ||||||
|   /** Just ack a ping, Http-only. */ |   /** Just ack a ping, Http-only. */ | ||||||
|   PONG = 1, |   PONG = 1, | ||||||
|   /** Do nothing, just acknowledge the Interaction */ |   /** @deprecated **DEPRECATED:** Do nothing, just acknowledge the Interaction */ | ||||||
|   ACKNOWLEDGE = 2, |   ACKNOWLEDGE = 2, | ||||||
|   /** Send a channel message without "<User> used /<Command> with <Bot>" */ |   /** @deprecated **DEPRECATED:** Send a channel message without "<User> used /<Command> with <Bot>" */ | ||||||
|   CHANNEL_MESSAGE = 3, |   CHANNEL_MESSAGE = 3, | ||||||
|   /** Send a channel message with "<User> used /<Command> with <Bot>" */ |   /** Send a channel message as response. */ | ||||||
|   CHANNEL_MESSAGE_WITH_SOURCE = 4, |   CHANNEL_MESSAGE_WITH_SOURCE = 4, | ||||||
|   /** Send nothing further, but send "<User> used /<Command> with <Bot>" */ |   /** Let the user know bot is processing ("thinking") and you can edit the response later */ | ||||||
|   ACK_WITH_SOURCE = 5 |   DEFERRED_CHANNEL_MESSAGE = 5 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface InteractionResponsePayload { | export interface InteractionResponsePayload { | ||||||
|  | @ -155,6 +163,6 @@ export interface InteractionResponseDataPayload { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export enum InteractionResponseFlags { | export enum InteractionResponseFlags { | ||||||
|   /** A Message which is only visible to Interaction User, and is not saved on backend */ |   /** A Message which is only visible to Interaction User. */ | ||||||
|   EPHEMERAL = 1 << 6 |   EPHEMERAL = 1 << 6 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue