Skip to content

Commit

Permalink
Port to using MessageFlags over the deprecated ephemeral option in In…
Browse files Browse the repository at this point in the history
…teractionReplyOptions
  • Loading branch information
PurpleCreativity committed Jan 8, 2025
1 parent f717617 commit 64ac2f6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/classes/components/Button.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/classes/components/PageEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ButtonStyle,
EmbedBuilder,
type Message,
MessageFlags,
TextInputBuilder,
TextInputStyle,
} from "discord.js";
Expand Down Expand Up @@ -185,7 +186,7 @@ export default class PageEmbed extends ButtonEmbed {
description: field.value,
}),
],
ephemeral: true,
flags: MessageFlags.Ephemeral,
});
},
}),
Expand Down
11 changes: 9 additions & 2 deletions src/classes/components/StringSelectMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ButtonStyle,
type ChatInputCommandInteraction,
ComponentType,
MessageFlags,
StringSelectMenuBuilder,
StringSelectMenuComponent,
type StringSelectMenuOptionBuilder,
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
14 changes: 10 additions & 4 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/interactables/points/getPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type APIEmbedField,
ButtonStyle,
type ChatInputCommandInteraction,
MessageFlags,
SlashCommandStringOption,
type UserContextMenuCommandInteraction,
} from "discord.js";
Expand Down Expand Up @@ -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}\``,
Expand Down
5 changes: 3 additions & 2 deletions src/interactables/points/pointlogs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ButtonStyle,
type GuildMember,
MessageFlags,
SlashCommandSubcommandBuilder,
TextChannel,
TextInputBuilder,
Expand Down Expand Up @@ -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,
});
},
}),
Expand Down Expand Up @@ -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,
});
},
}),
Expand Down

0 comments on commit 64ac2f6

Please sign in to comment.