Skip to content

Commit

Permalink
feat: add followup messages for interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilloftheshadow committed Sep 6, 2024
1 parent dcf5b44 commit c8e7c1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-phones-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@buape/carbon": patch
---

feat: add followup messages for interactions
3 changes: 2 additions & 1 deletion packages/carbon/src/abstracts/BaseComponentInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type APIMessageComponentInteraction,
type ComponentType,
InteractionResponseType,
type RESTPostAPIInteractionCallbackJSONBody,
Routes
} from "discord-api-types/v10"
import type { Client } from "../classes/Client.js"
Expand Down Expand Up @@ -29,7 +30,7 @@ export class BaseComponentInteraction extends BaseInteraction<APIMessageComponen
{
body: {
type: InteractionResponseType.DeferredMessageUpdate
}
} as RESTPostAPIInteractionCallbackJSONBody
}
)
}
Expand Down
37 changes: 31 additions & 6 deletions packages/carbon/src/abstracts/BaseInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
type APIInteraction,
InteractionResponseType,
type InteractionType,
type RESTPatchAPIInteractionOriginalResponseJSONBody,
type RESTPostAPIInteractionCallbackJSONBody,
type RESTPostAPIInteractionFollowupJSONBody,
Routes
} from "discord-api-types/v10"
import {
Expand Down Expand Up @@ -160,8 +163,9 @@ export abstract class BaseInteraction<T extends APIInteraction> extends Base {
{
body: {
...data,
embeds: data.embeds?.map((embed) => embed.serialize()),
components: data.components?.map((row) => row.serialize())
},
} as RESTPatchAPIInteractionOriginalResponseJSONBody,
files: options.files
}
)
Expand All @@ -173,10 +177,11 @@ export abstract class BaseInteraction<T extends APIInteraction> extends Base {
type: InteractionResponseType.ChannelMessageWithSource,
data: {
...data,
embeds: data.embeds?.map((embed) => embed.serialize()),
components: data.components?.map((row) => row.serialize()),
ephemeral: options.ephemeral ?? this.defaultEphemeral
flags: options.ephemeral ? 64 : undefined
}
},
} as RESTPostAPIInteractionCallbackJSONBody,
files: options.files
}
)
Expand All @@ -196,8 +201,8 @@ export abstract class BaseInteraction<T extends APIInteraction> extends Base {
{
body: {
type: InteractionResponseType.DeferredChannelMessageWithSource,
ephemeral: this.defaultEphemeral
}
flags: this.defaultEphemeral ? 64 : undefined
} as RESTPostAPIInteractionCallbackJSONBody
}
)
}
Expand All @@ -216,7 +221,27 @@ export abstract class BaseInteraction<T extends APIInteraction> extends Base {
body: {
type: InteractionResponseType.Modal,
data: modal.serialize()
}
} as RESTPostAPIInteractionCallbackJSONBody
}
)
}

/**
* Send a followup message to the interaction
*/
async followUp(
reply: InteractionReplyData,
options: InteractionReplyOptions = {}
) {
await this.client.rest.post(
Routes.webhook(this.client.options.clientId, this.rawData.token),
{
body: {
...reply,
embeds: reply.embeds?.map((embed) => embed.serialize()),
components: reply.components?.map((row) => row.serialize()),
flags: options.ephemeral ? 64 : undefined
} as RESTPostAPIInteractionFollowupJSONBody
}
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/carbon/src/internals/ModalInteraction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
InteractionResponseType,
Routes,
type RESTPostAPIInteractionCallbackJSONBody,
type APIModalSubmitInteraction
} from "discord-api-types/v10"
import { BaseInteraction } from "../abstracts/BaseInteraction.js"
Expand Down Expand Up @@ -28,7 +29,7 @@ export class ModalInteraction extends BaseInteraction<APIModalSubmitInteraction>
{
body: {
type: InteractionResponseType.DeferredMessageUpdate
}
} as RESTPostAPIInteractionCallbackJSONBody
}
)
}
Expand Down

0 comments on commit c8e7c1c

Please sign in to comment.