From 64ac2f66ae4ab586177f3569041ea9efc2b3aa1e Mon Sep 17 00:00:00 2001 From: Purple_Creativity Date: Wed, 8 Jan 2025 21:17:27 +0100 Subject: [PATCH] Port to using MessageFlags over the deprecated ephemeral option in InteractionReplyOptions --- src/classes/components/Button.ts | 10 ++++++++-- src/classes/components/PageEmbed.ts | 3 ++- src/classes/components/StringSelectMenu.ts | 11 +++++++++-- src/events/interactionCreate.ts | 14 ++++++++++---- src/interactables/points/getPoints.ts | 3 ++- src/interactables/points/pointlogs.ts | 5 +++-- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/classes/components/Button.ts b/src/classes/components/Button.ts index 039eac5a..eae6ef88 100644 --- a/src/classes/components/Button.ts +++ b/src/classes/components/Button.ts @@ -1,4 +1,10 @@ -import { ButtonBuilder, type ButtonInteraction, ButtonStyle, type ComponentEmojiResolvable } from "discord.js"; +import { + ButtonBuilder, + type ButtonInteraction, + ButtonStyle, + type ComponentEmojiResolvable, + MessageFlags, +} from "discord.js"; import client from "../../main.js"; export type ButtonOptions = { @@ -38,7 +44,7 @@ export default class Button extends ButtonBuilder { ) { await interaction.reply({ content: "You are not allowed to use this button", - ephemeral: true, + flags: MessageFlags.Ephemeral, }); return; } diff --git a/src/classes/components/PageEmbed.ts b/src/classes/components/PageEmbed.ts index e700369f..526a5599 100644 --- a/src/classes/components/PageEmbed.ts +++ b/src/classes/components/PageEmbed.ts @@ -3,6 +3,7 @@ import { ButtonStyle, EmbedBuilder, type Message, + MessageFlags, TextInputBuilder, TextInputStyle, } from "discord.js"; @@ -185,7 +186,7 @@ export default class PageEmbed extends ButtonEmbed { description: field.value, }), ], - ephemeral: true, + flags: MessageFlags.Ephemeral, }); }, }), diff --git a/src/classes/components/StringSelectMenu.ts b/src/classes/components/StringSelectMenu.ts index 7d0d029a..5edde49a 100644 --- a/src/classes/components/StringSelectMenu.ts +++ b/src/classes/components/StringSelectMenu.ts @@ -9,6 +9,7 @@ import { ButtonStyle, type ChatInputCommandInteraction, ComponentType, + MessageFlags, StringSelectMenuBuilder, StringSelectMenuComponent, type StringSelectMenuOptionBuilder, @@ -100,7 +101,10 @@ export default class StringSelectMenu { if (!newInteraction.isStringSelectMenu()) return; if (newInteraction.customId !== this.selector.data.custom_id) return; if (this.allowedUsers.length > 0 && !this.allowedUsers.includes(newInteraction.user.id)) { - await newInteraction.reply({ content: "You are not allowed to use this menu", ephemeral: true }); + await newInteraction.reply({ + content: "You are not allowed to use this menu", + flags: MessageFlags.Ephemeral, + }); return; } @@ -122,7 +126,10 @@ export default class StringSelectMenu { ) return; if (this.allowedUsers.length > 0 && !this.allowedUsers.includes(newInteraction.user.id)) { - await newInteraction.reply({ content: "You are not allowed to use this button", ephemeral: true }); + await newInteraction.reply({ + content: "You are not allowed to use this button", + flags: MessageFlags.Ephemeral, + }); return; } diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 51541d2f..ece206ea 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -1,4 +1,4 @@ -import { BaseInteraction } from "discord.js"; +import { BaseInteraction, MessageFlags } from "discord.js"; import Event from "../classes/Event.js"; import client from "../main.js"; @@ -21,7 +21,9 @@ export default new Event({ } try { - await interaction.deferReply({ ephemeral: command.ephemeral }); + await interaction.deferReply({ + flags: command.ephemeral ? MessageFlags.Ephemeral : undefined, + }); const guildProfile = interaction.guild && !command.userApp @@ -87,7 +89,9 @@ export default new Event({ } try { - await interaction.deferReply({ ephemeral: command.ephemeral }); + await interaction.deferReply({ + flags: command.ephemeral ? MessageFlags.Ephemeral : undefined, + }); const guildProfile = interaction.guild && !command.userApp @@ -138,7 +142,9 @@ export default new Event({ } try { - await interaction.deferReply({ ephemeral: command.ephemeral }); + await interaction.deferReply({ + flags: command.ephemeral ? MessageFlags.Ephemeral : undefined, + }); const guildProfile = interaction.guild && !command.userApp diff --git a/src/interactables/points/getPoints.ts b/src/interactables/points/getPoints.ts index f6f420a8..6905d812 100644 --- a/src/interactables/points/getPoints.ts +++ b/src/interactables/points/getPoints.ts @@ -3,6 +3,7 @@ import { type APIEmbedField, ButtonStyle, type ChatInputCommandInteraction, + MessageFlags, SlashCommandStringOption, type UserContextMenuCommandInteraction, } from "discord.js"; @@ -54,7 +55,7 @@ const callback = async ( allowedUsers: [interaction.user.id], function: async (buttonInteraction) => { - await buttonInteraction.deferReply({ ephemeral: true }); + await buttonInteraction.deferReply({ flags: MessageFlags.Ephemeral }); let fields: APIEmbedField[] = guildUserProfile.notes.map((note: noteData) => ({ name: `\`${note.id}\``, diff --git a/src/interactables/points/pointlogs.ts b/src/interactables/points/pointlogs.ts index b0872ede..02143ca3 100644 --- a/src/interactables/points/pointlogs.ts +++ b/src/interactables/points/pointlogs.ts @@ -1,6 +1,7 @@ import { ButtonStyle, type GuildMember, + MessageFlags, SlashCommandSubcommandBuilder, TextChannel, TextInputBuilder, @@ -338,7 +339,7 @@ export default new SlashCommand({ await buttonInteraction.reply({ files: [{ name: `pointlog_${pointlog.id}_fulldata.txt`, attachment: userBuffer }], - ephemeral: true, + flags: MessageFlags.Ephemeral, }); }, }), @@ -520,7 +521,7 @@ export default new SlashCommand({ await buttonInteraction.reply({ files: [{ name: `pointlog_${pointlog.id}_fulldata.txt`, attachment: userBuffer }], - ephemeral: true, + flags: MessageFlags.Ephemeral, }); }, }),