mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Use helpers in interaction methods (#3395)
This commit is contained in:
@@ -206,10 +206,7 @@ export function createBotHelpers(bot: Bot): BotHelpers {
|
|||||||
return bot.transformers.message(bot, snakelize(await bot.rest.editMessage(channelId, messageId, options)) as DiscordMessage)
|
return bot.transformers.message(bot, snakelize(await bot.rest.editMessage(channelId, messageId, options)) as DiscordMessage)
|
||||||
},
|
},
|
||||||
editOriginalInteractionResponse: async (token, options) => {
|
editOriginalInteractionResponse: async (token, options) => {
|
||||||
const result = await bot.rest.editOriginalInteractionResponse(token, options)
|
return bot.transformers.message(bot, snakelize(await bot.rest.editOriginalInteractionResponse(token, options)))
|
||||||
if (!result) return
|
|
||||||
|
|
||||||
return bot.transformers.message(bot, snakelize(result) as DiscordMessage)
|
|
||||||
},
|
},
|
||||||
editOriginalWebhookMessage: async (webhookId, token, options) => {
|
editOriginalWebhookMessage: async (webhookId, token, options) => {
|
||||||
return bot.transformers.message(bot, snakelize(await bot.rest.editOriginalWebhookMessage(webhookId, token, options)) as DiscordMessage)
|
return bot.transformers.message(bot, snakelize(await bot.rest.editOriginalWebhookMessage(webhookId, token, options)) as DiscordMessage)
|
||||||
@@ -752,7 +749,7 @@ export interface BotHelpers {
|
|||||||
editGuildSticker: (guildId: BigString, stickerId: BigString, options: AtLeastOne<EditGuildStickerOptions>, reason?: string) => Promise<Sticker>
|
editGuildSticker: (guildId: BigString, stickerId: BigString, options: AtLeastOne<EditGuildStickerOptions>, reason?: string) => Promise<Sticker>
|
||||||
editGuildTemplate: (guildId: BigString, templateCode: string, options: ModifyGuildTemplate) => Promise<Template>
|
editGuildTemplate: (guildId: BigString, templateCode: string, options: ModifyGuildTemplate) => Promise<Template>
|
||||||
editMessage: (channelId: BigString, messageId: BigString, options: EditMessage) => Promise<Message>
|
editMessage: (channelId: BigString, messageId: BigString, options: EditMessage) => Promise<Message>
|
||||||
editOriginalInteractionResponse: (token: string, options: InteractionCallbackData) => Promise<Message | undefined>
|
editOriginalInteractionResponse: (token: string, options: InteractionCallbackData) => Promise<Message>
|
||||||
editOriginalWebhookMessage: (webhookId: BigString, token: string, options: InteractionCallbackData & { threadId?: BigString }) => Promise<Message>
|
editOriginalWebhookMessage: (webhookId: BigString, token: string, options: InteractionCallbackData & { threadId?: BigString }) => Promise<Message>
|
||||||
editRole: (guildId: BigString, roleId: BigString, options: EditGuildRole, reason?: string) => Promise<Role>
|
editRole: (guildId: BigString, roleId: BigString, options: EditGuildRole, reason?: string) => Promise<Role>
|
||||||
editRolePositions: (guildId: BigString, options: ModifyRolePositions[], reason?: string) => Promise<Role[]>
|
editRolePositions: (guildId: BigString, options: ModifyRolePositions[], reason?: string) => Promise<Role[]>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
type ApplicationCommandOptionTypes,
|
type ApplicationCommandOptionTypes,
|
||||||
type ApplicationCommandTypes,
|
type ApplicationCommandTypes,
|
||||||
type BigString,
|
type BigString,
|
||||||
type CamelizedDiscordMessage,
|
|
||||||
type ChannelTypes,
|
type ChannelTypes,
|
||||||
type DiscordInteraction,
|
type DiscordInteraction,
|
||||||
type DiscordInteractionDataOption,
|
type DiscordInteractionDataOption,
|
||||||
@@ -75,13 +74,33 @@ export interface Interaction extends BaseInteraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseInteraction {
|
export interface BaseInteraction {
|
||||||
/** Sends a response to an interaction. */
|
/**
|
||||||
respond: (response: string | InteractionCallbackData, options?: { isPrivate?: boolean }) => Promise<CamelizedDiscordMessage | void>
|
* Sends a response to an interaction.
|
||||||
/** Edit the original response of an interaction. */
|
*
|
||||||
edit: (response: string | InteractionCallbackData) => Promise<CamelizedDiscordMessage>
|
* @remarks
|
||||||
/** Defer the interaction. */
|
* Uses `interaction.type`, `interaction.token` and `interaction.id`
|
||||||
|
*/
|
||||||
|
respond: (response: string | InteractionCallbackData, options?: { isPrivate?: boolean }) => Promise<Message | void>
|
||||||
|
/**
|
||||||
|
* Edit the original response of an interaction.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* Uses `interaction.token`
|
||||||
|
*/
|
||||||
|
edit: (response: string | InteractionCallbackData) => Promise<Message>
|
||||||
|
/**
|
||||||
|
* Defer the interaction.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* Uses `interaction.type`, `interaction.token` and `interaction.id`
|
||||||
|
*/
|
||||||
defer: (isPrivate?: boolean) => Promise<void>
|
defer: (isPrivate?: boolean) => Promise<void>
|
||||||
/** Delete the original interaction response or a followup message */
|
/**
|
||||||
|
* Delete the original interaction response or a followup message
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* Uses `interaction.type` and `interaction.token`
|
||||||
|
*/
|
||||||
delete: (messageId?: BigString) => Promise<void>
|
delete: (messageId?: BigString) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +118,7 @@ const baseInteraction: Partial<Interaction> & BaseInteraction = {
|
|||||||
if (type === InteractionResponseTypes.ChannelMessageWithSource && options?.isPrivate) response.flags = 64
|
if (type === InteractionResponseTypes.ChannelMessageWithSource && options?.isPrivate) response.flags = 64
|
||||||
|
|
||||||
// Since this has already been given a response, any further responses must be followups.
|
// Since this has already been given a response, any further responses must be followups.
|
||||||
if (this.acknowledged) return await this.bot?.rest.sendFollowupMessage(this.token!, response)
|
if (this.acknowledged) return await this.bot!.helpers.sendFollowupMessage(this.token!, response)
|
||||||
|
|
||||||
// Modals cannot be chained
|
// Modals cannot be chained
|
||||||
if (this.type === InteractionTypes.ModalSubmit && type === InteractionResponseTypes.Modal)
|
if (this.type === InteractionTypes.ModalSubmit && type === InteractionResponseTypes.Modal)
|
||||||
@@ -111,7 +130,7 @@ const baseInteraction: Partial<Interaction> & BaseInteraction = {
|
|||||||
|
|
||||||
// If user has not already responded to this interaction we need to send an original response
|
// If user has not already responded to this interaction we need to send an original response
|
||||||
this.acknowledged = true
|
this.acknowledged = true
|
||||||
return await this.bot?.rest.sendInteractionResponse(this.id!, this.token!, { type, data: response })
|
return await this.bot!.helpers.sendInteractionResponse(this.id!, this.token!, { type, data: response })
|
||||||
},
|
},
|
||||||
|
|
||||||
async edit(response) {
|
async edit(response) {
|
||||||
@@ -120,7 +139,7 @@ const baseInteraction: Partial<Interaction> & BaseInteraction = {
|
|||||||
// If user provides a string, change it to a response object
|
// If user provides a string, change it to a response object
|
||||||
if (typeof response === 'string') response = { content: response }
|
if (typeof response === 'string') response = { content: response }
|
||||||
|
|
||||||
return await this.bot!.rest.editOriginalInteractionResponse(this.token!, response)
|
return await this.bot!.helpers.editOriginalInteractionResponse(this.token!, response)
|
||||||
},
|
},
|
||||||
|
|
||||||
async defer(isPrivate) {
|
async defer(isPrivate) {
|
||||||
@@ -138,14 +157,14 @@ const baseInteraction: Partial<Interaction> & BaseInteraction = {
|
|||||||
if (isPrivate) data.flags = 64
|
if (isPrivate) data.flags = 64
|
||||||
|
|
||||||
this.acknowledged = true
|
this.acknowledged = true
|
||||||
return await this.bot?.rest.sendInteractionResponse(this.id!, this.token!, { type, data })
|
return await this.bot!.helpers.sendInteractionResponse(this.id!, this.token!, { type, data })
|
||||||
},
|
},
|
||||||
|
|
||||||
async delete(messageId?: BigString) {
|
async delete(messageId?: BigString) {
|
||||||
if (this.type === InteractionTypes.ApplicationCommandAutocomplete) throw new Error('Cannot delete an autocomplete interaction')
|
if (this.type === InteractionTypes.ApplicationCommandAutocomplete) throw new Error('Cannot delete an autocomplete interaction')
|
||||||
|
|
||||||
if (messageId) return await this.bot?.rest.deleteFollowupMessage(this.token!, messageId)
|
if (messageId) return await this.bot?.helpers.deleteFollowupMessage(this.token!, messageId)
|
||||||
else return await this.bot?.rest.deleteOriginalInteractionResponse(this.token!)
|
else return await this.bot?.helpers.deleteOriginalInteractionResponse(this.token!)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user