Skip to content

Commit 9239424

Browse files
committed
fix: use Events.ClientReady instead of deprecated 'ready' event
Discord.js v14 renamed the 'ready' event to 'clientReady' and it will only emit under that name in v15. Using the Events.ClientReady enum provides type safety and forward compatibility. - Update src/index.ts to import and use Events.ClientReady - Update src/platforms/discord.ts to import and use Events.ClientReady - Update test mock to export Events and check for Events.ClientReady
1 parent 944a82f commit 9239424

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, type TextBasedChannel } from "discord.js";
1+
import { Client, Events, type TextBasedChannel } from "discord.js";
22
import {
33
type EventTimestampSource,
44
fetchCollectionSlug,
@@ -31,7 +31,7 @@ const fetchDiscordChannelNames = async (): Promise<Map<string, string>> => {
3131

3232
try {
3333
await new Promise<void>((resolve) => {
34-
client.on("ready", () => resolve());
34+
client.on(Events.ClientReady, () => resolve());
3535
client.login(process.env.DISCORD_TOKEN);
3636
});
3737

src/platforms/discord.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Client,
33
type ColorResolvable,
44
EmbedBuilder,
5+
Events,
56
type MessageCreateOptions,
67
type TextBasedChannel,
78
} from "discord.js";
@@ -410,7 +411,7 @@ const messagesForEvents = async (
410411

411412
const login = (client: Client): Promise<void> =>
412413
new Promise<void>((resolve) => {
413-
client.on("ready", () => {
414+
client.on(Events.ClientReady, () => {
414415
resolve();
415416
});
416417
client.login(process.env.DISCORD_TOKEN);

test/platforms/discord.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ const channelsMap: Record<string, { send: jest.Mock; id: string }> = {};
88
const setColorArgs: Record<string, string[]> = {};
99

1010
jest.mock("discord.js", () => {
11+
const Events = { ClientReady: "clientReady" };
1112
const Client = jest.fn().mockImplementation(() => {
1213
return {
1314
on: (event: string, cb: () => void) => {
14-
if (event === "ready") {
15+
if (event === Events.ClientReady) {
1516
// Call immediately instead of using setImmediate for faster tests
1617
cb();
1718
}
@@ -42,7 +43,7 @@ jest.mock("discord.js", () => {
4243
};
4344
return obj;
4445
});
45-
return { Client, EmbedBuilder };
46+
return { Client, EmbedBuilder, Events };
4647
});
4748

4849
// Mock opensea username

0 commit comments

Comments
 (0)