diff --git a/package.json b/package.json index 1947344..5e41e5a 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,15 @@ }, "devDependencies": { "@types/bun": "latest", - "@types/node": "^22.10.1", - "prettier": "^3.4.1", + "@types/node": "^22.10.5", + "prettier": "^3.4.2", "ts-node": "^10.9.2", - "typescript": "^5.7.2" + "typescript": "^5.7.3" }, "dependencies": { - "bufferutil": "^4.0.8", - "discord.js": "^14.16.3", - "dotenv": "^16.4.5", + "bufferutil": "^4.0.9", + "discord.js": "^14.17.3", + "dotenv": "^16.4.7", "utf-8-validate": "^6.0.5" } } diff --git a/readme.md b/readme.md index db0b56f..fffe02d 100644 --- a/readme.md +++ b/readme.md @@ -264,7 +264,7 @@ export default new ContextMenu({ .setType(ApplicationCommandType.Message as ContextMenuCommandType), async execute(interaction: ContextMenuCommandInteraction): Promise { - await interaction.reply({ content: `Message ID: ${interaction.targetId}`, ephemeral: true }); + await interaction.reply({ content: `Message ID: ${interaction.targetId}`, flags: [MessageFlags.Ephemeral] }); }, }); ``` @@ -364,7 +364,7 @@ Unique IDs allow for more dynamic interaction handling by appending specific ide async execute(interaction: ButtonInteraction, uniqueId: string | null): Promise { await interaction.reply({ content: `You have pressed the **${uniqueId}** button.`, - ephemeral: true, + flags: [MessageFlags.Ephemeral], }); } ``` @@ -407,7 +407,7 @@ export default new Button({ async execute(interaction: ButtonInteraction, uniqueId: string | null): Promise { await interaction.reply({ content: `You have pressed the **${uniqueId}** button.`, - ephemeral: true, + flags: [MessageFlags.Ephemeral], }); }, }); @@ -504,7 +504,7 @@ export default new Modal({ await interaction.reply({ content: `Your favorite color is **${favoriteColor}** and you enjoy **${hobbies}**!`, - ephemeral: true, + flags: [MessageFlags.Ephemeral], }); }, }); diff --git a/src/commands/context/getMessageId.ts b/src/commands/context/getMessageId.ts index ed1531d..5fafa9c 100644 --- a/src/commands/context/getMessageId.ts +++ b/src/commands/context/getMessageId.ts @@ -4,6 +4,7 @@ import { ContextMenuCommandBuilder, ContextMenuCommandInteraction, type ContextMenuCommandType, + MessageFlags, } from 'discord.js'; export default new ContextMenu({ @@ -14,6 +15,6 @@ export default new ContextMenu({ .setType(ApplicationCommandType.Message as ContextMenuCommandType), async execute(interaction: ContextMenuCommandInteraction): Promise { - await interaction.reply({ content: `Message ID: ${interaction.targetId}`, ephemeral: true }); + await interaction.reply({ content: `Message ID: ${interaction.targetId}`, flags: [MessageFlags.Ephemeral] }); }, }); diff --git a/src/commands/context/getUserId.ts b/src/commands/context/getUserId.ts index e5f405e..6d29064 100644 --- a/src/commands/context/getUserId.ts +++ b/src/commands/context/getUserId.ts @@ -4,6 +4,7 @@ import { ContextMenuCommandBuilder, ContextMenuCommandInteraction, type ContextMenuCommandType, + MessageFlags, } from 'discord.js'; export default new ContextMenu({ @@ -14,6 +15,6 @@ export default new ContextMenu({ .setType(ApplicationCommandType.User as ContextMenuCommandType), async execute(interaction: ContextMenuCommandInteraction): Promise { - await interaction.reply({ content: `User ID: ${interaction.targetId}`, ephemeral: true }); + await interaction.reply({ content: `User ID: ${interaction.targetId}`, flags: [MessageFlags.Ephemeral] }); }, }); diff --git a/src/commands/slash/misc/reload.ts b/src/commands/slash/misc/reload.ts index 839711e..45c5515 100644 --- a/src/commands/slash/misc/reload.ts +++ b/src/commands/slash/misc/reload.ts @@ -1,11 +1,6 @@ import { client } from '../../../index'; import { RegisterType, SlashCommand } from '../../../handler'; -import { - type ChatInputCommandInteraction, - Colors, - EmbedBuilder, - SlashCommandBuilder, -} from 'discord.js'; +import { type ChatInputCommandInteraction, Colors, EmbedBuilder, MessageFlags, SlashCommandBuilder } from 'discord.js'; export default new SlashCommand({ restrictedToOwner: true, @@ -33,6 +28,6 @@ export default new SlashCommand({ .setColor(Colors.Red); } - await interaction.reply({ embeds: [embed], ephemeral: true }); + await interaction.reply({ embeds: [embed], flags: [MessageFlags.Ephemeral] }); }, }); diff --git a/src/commands/slash/showcase/buttons.ts b/src/commands/slash/showcase/buttons.ts index 32cd2a9..1f73a9d 100644 --- a/src/commands/slash/showcase/buttons.ts +++ b/src/commands/slash/showcase/buttons.ts @@ -4,6 +4,7 @@ import { ButtonBuilder, ButtonStyle, type ChatInputCommandInteraction, + MessageFlags, SlashCommandBuilder, } from 'discord.js'; @@ -33,7 +34,7 @@ export default new SlashCommand({ await interaction.reply({ content: 'Here are some interactive buttons. Try them out!', components: [row], - ephemeral: true, + flags: [MessageFlags.Ephemeral], }); }, }); diff --git a/src/components/buttons/buttons.ts b/src/components/buttons/buttons.ts index 6e83268..f0c3ce7 100644 --- a/src/components/buttons/buttons.ts +++ b/src/components/buttons/buttons.ts @@ -1,5 +1,5 @@ import { Button } from '../../handler'; -import type { ButtonInteraction } from 'discord.js'; +import { ButtonInteraction, MessageFlags } from 'discord.js'; export default new Button({ customId: 'buttons', @@ -7,7 +7,7 @@ export default new Button({ async execute(interaction: ButtonInteraction, uniqueId: string | null): Promise { await interaction.reply({ content: `You have pressed the **${uniqueId}** button.`, - ephemeral: true, + flags: [MessageFlags.Ephemeral], }); }, }); diff --git a/src/components/modals/askModal.ts b/src/components/modals/askModal.ts index a7128a2..9fbeb9c 100644 --- a/src/components/modals/askModal.ts +++ b/src/components/modals/askModal.ts @@ -1,5 +1,5 @@ import { Modal } from '../../handler'; -import { ModalSubmitFields, ModalSubmitInteraction } from 'discord.js'; +import { MessageFlags, ModalSubmitFields, ModalSubmitInteraction } from 'discord.js'; export default new Modal({ customId: 'askModal', @@ -10,7 +10,7 @@ export default new Modal({ await interaction.reply({ content: `Your favorite color is **${favoriteColor}** and you enjoy **${hobbies}**!`, - ephemeral: true, + flags: [MessageFlags.Ephemeral], }); }, }); diff --git a/src/handler/commands/services/CommandHandler.ts b/src/handler/commands/services/CommandHandler.ts index 5446889..a3fc21a 100644 --- a/src/handler/commands/services/CommandHandler.ts +++ b/src/handler/commands/services/CommandHandler.ts @@ -15,6 +15,7 @@ import { EmbedBuilder, Interaction, Message, + MessageFlags, } from 'discord.js'; export class CommandHandler { @@ -112,7 +113,7 @@ export class CommandHandler { await (context.reply?.({ embeds: [replyEmbed], - ephemeral: true, + flags: [MessageFlags.Ephemeral], }) || context.channel.send({ embeds: [replyEmbed] })); return false; } @@ -124,7 +125,7 @@ export class CommandHandler { ): Promise { try { const logChannelConfig: LogChannelConfig | undefined = config.logChannelConfig; - if (!logChannelConfig) return; + if (!logChannelConfig || logChannelConfig.channelId.length !> 0) return; const channel: Channel | null = await client.channels.fetch(logChannelConfig.channelId); if (!channel) return; diff --git a/src/handler/utils/EmbedPaginator.ts b/src/handler/utils/EmbedPaginator.ts index d6b80f9..8ce2dc2 100644 --- a/src/handler/utils/EmbedPaginator.ts +++ b/src/handler/utils/EmbedPaginator.ts @@ -12,8 +12,10 @@ import { ButtonStyle, CommandInteraction, EmbedBuilder, + InteractionCallbackResponse, Message, MessageComponentInteraction, + MessageFlags, type MessagePayloadOption, } from 'discord.js'; @@ -38,10 +40,10 @@ export class EmbedPaginator { let messageOptions: MessagePayloadOption = { content, - ephemeral: ephemeral ?? false, + flags: ephemeral ? [MessageFlags.Ephemeral] : [], embeds: [this.getPageEmbed()], components: this.getPageComponents(), - fetchReply: true, + withResponse: true, }; if (!messageOptions.content) { @@ -68,7 +70,7 @@ export class EmbedPaginator { private getPageEmbed(): EmbedBuilder { const page: EmbedBuilder | PaginatorPage = this.settings.pages[this.currentPageIndex]; - const embed: EmbedBuilder = (page as PaginatorPage)?.embed ?? page as EmbedBuilder; + const embed: EmbedBuilder = (page as PaginatorPage)?.embed ?? (page as EmbedBuilder); if (this.settings.autoPageDisplay) { embed.setFooter({ text: `Page ${this.currentPageIndex + 1}/${this.maxPageIndex}` }); @@ -130,7 +132,12 @@ export class EmbedPaginator { return row; } - private async collectButtonInteractions(message: Message): Promise { + private async collectButtonInteractions(context: Message | InteractionCallbackResponse): Promise { + const message: Message = + context instanceof InteractionCallbackResponse && context.resource?.message + ? context.resource.message + : (context as Message); + const authorId: string = message.author.id; const filter = (interaction: MessageComponentInteraction): boolean => diff --git a/src/handler/utils/logChannelPresets.ts b/src/handler/utils/logChannelPresets.ts index 4ff12f2..61e6925 100644 --- a/src/handler/utils/logChannelPresets.ts +++ b/src/handler/utils/logChannelPresets.ts @@ -1,4 +1,4 @@ -import { type ContextMenuCommandInteraction, EmbedBuilder, type Interaction, Message } from 'discord.js'; +import { type ContextMenuCommandInteraction, EmbedBuilder, type Interaction, Message, MessageFlags } from 'discord.js'; export function getLogChannelPresetEmbed( context: Interaction | ContextMenuCommandInteraction | Message, @@ -23,8 +23,11 @@ export function getLogChannelPresetEmbed( .setThumbnail(authorIconURL) .setTimestamp(); - const isEphemeralInteraction: boolean | null = - !(context instanceof Message) && 'ephemeral' in context && context.ephemeral; + const isEphemeralInteraction: boolean = + !(context instanceof Message) && + 'flags' in context && + typeof context.flags === 'number' && + (context.flags & MessageFlags.Ephemeral) === MessageFlags.Ephemeral; if (messageURL && !isEphemeralInteraction) { logEmbed.setURL(messageURL);