Skip to content

Commit

Permalink
chore: update discord.js to v14.17.3 and refactor for latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukazbaum committed Jan 12, 2025
1 parent 3c0deb3 commit 4b3e100
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 33 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export default new ContextMenu({
.setType(ApplicationCommandType.Message as ContextMenuCommandType),

async execute(interaction: ContextMenuCommandInteraction): Promise<void> {
await interaction.reply({ content: `Message ID: ${interaction.targetId}`, ephemeral: true });
await interaction.reply({ content: `Message ID: ${interaction.targetId}`, flags: [MessageFlags.Ephemeral] });
},
});
```
Expand Down Expand Up @@ -364,7 +364,7 @@ Unique IDs allow for more dynamic interaction handling by appending specific ide
async execute(interaction: ButtonInteraction, uniqueId: string | null): Promise<void> {
await interaction.reply({
content: `You have pressed the **${uniqueId}** button.`,
ephemeral: true,
flags: [MessageFlags.Ephemeral],
});
}
```
Expand Down Expand Up @@ -407,7 +407,7 @@ export default new Button({
async execute(interaction: ButtonInteraction, uniqueId: string | null): Promise<void> {
await interaction.reply({
content: `You have pressed the **${uniqueId}** button.`,
ephemeral: true,
flags: [MessageFlags.Ephemeral],
});
},
});
Expand Down Expand Up @@ -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],
});
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context/getMessageId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ContextMenuCommandBuilder,
ContextMenuCommandInteraction,
type ContextMenuCommandType,
MessageFlags,
} from 'discord.js';

export default new ContextMenu({
Expand All @@ -14,6 +15,6 @@ export default new ContextMenu({
.setType(ApplicationCommandType.Message as ContextMenuCommandType),

async execute(interaction: ContextMenuCommandInteraction): Promise<void> {
await interaction.reply({ content: `Message ID: ${interaction.targetId}`, ephemeral: true });
await interaction.reply({ content: `Message ID: ${interaction.targetId}`, flags: [MessageFlags.Ephemeral] });
},
});
3 changes: 2 additions & 1 deletion src/commands/context/getUserId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ContextMenuCommandBuilder,
ContextMenuCommandInteraction,
type ContextMenuCommandType,
MessageFlags,
} from 'discord.js';

export default new ContextMenu({
Expand All @@ -14,6 +15,6 @@ export default new ContextMenu({
.setType(ApplicationCommandType.User as ContextMenuCommandType),

async execute(interaction: ContextMenuCommandInteraction): Promise<void> {
await interaction.reply({ content: `User ID: ${interaction.targetId}`, ephemeral: true });
await interaction.reply({ content: `User ID: ${interaction.targetId}`, flags: [MessageFlags.Ephemeral] });
},
});
9 changes: 2 additions & 7 deletions src/commands/slash/misc/reload.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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] });
},
});
3 changes: 2 additions & 1 deletion src/commands/slash/showcase/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ButtonBuilder,
ButtonStyle,
type ChatInputCommandInteraction,
MessageFlags,
SlashCommandBuilder,
} from 'discord.js';

Expand Down Expand Up @@ -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],
});
},
});
4 changes: 2 additions & 2 deletions src/components/buttons/buttons.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Button } from '../../handler';
import type { ButtonInteraction } from 'discord.js';
import { ButtonInteraction, MessageFlags } from 'discord.js';

export default new Button({
customId: 'buttons',

async execute(interaction: ButtonInteraction, uniqueId: string | null): Promise<void> {
await interaction.reply({
content: `You have pressed the **${uniqueId}** button.`,
ephemeral: true,
flags: [MessageFlags.Ephemeral],
});
},
});
4 changes: 2 additions & 2 deletions src/components/modals/askModal.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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],
});
},
});
5 changes: 3 additions & 2 deletions src/handler/commands/services/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EmbedBuilder,
Interaction,
Message,
MessageFlags,
} from 'discord.js';

export class CommandHandler {
Expand Down Expand Up @@ -112,7 +113,7 @@ export class CommandHandler {

await (context.reply?.({
embeds: [replyEmbed],
ephemeral: true,
flags: [MessageFlags.Ephemeral],
}) || context.channel.send({ embeds: [replyEmbed] }));
return false;
}
Expand All @@ -124,7 +125,7 @@ export class CommandHandler {
): Promise<void> {
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;
Expand Down
15 changes: 11 additions & 4 deletions src/handler/utils/EmbedPaginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
ButtonStyle,
CommandInteraction,
EmbedBuilder,
InteractionCallbackResponse,
Message,
MessageComponentInteraction,
MessageFlags,
type MessagePayloadOption,
} from 'discord.js';

Expand All @@ -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) {
Expand All @@ -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}` });
Expand Down Expand Up @@ -130,7 +132,12 @@ export class EmbedPaginator {
return row;
}

private async collectButtonInteractions(message: Message): Promise<void> {
private async collectButtonInteractions(context: Message | InteractionCallbackResponse): Promise<void> {
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 =>
Expand Down
9 changes: 6 additions & 3 deletions src/handler/utils/logChannelPresets.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 4b3e100

Please sign in to comment.