From 679f46c9670cd83dc7e77fe3a066519dee366f27 Mon Sep 17 00:00:00 2001 From: Hikari Date: Tue, 24 Mar 2026 20:20:21 -0700 Subject: [PATCH] feat: pre-fetch guild members on boot --- src/index.ts | 17 ++++++++++++----- src/register.ts | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3e09351..6ca2fb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,6 +20,7 @@ import { softbanCommand } from "./commands/softban.js"; import { unbanCommand } from "./commands/unban.js"; import { unmuteCommand } from "./commands/unmute.js"; import { warnCommand } from "./commands/warn.js"; +import { guildConfig } from "./config/guild.js"; // eslint-disable-next-line stylistic/max-len -- Import path cannot be shortened import { onGuildAuditLogEntryCreate } from "./events/guildAuditLogEntryCreate.js"; import { onGuildMemberAdd } from "./events/guildMemberAdd.js"; @@ -127,11 +128,17 @@ client.on(Events.GuildAuditLogEntryCreate, (entry, guild) => { void onGuildAuditLogEntryCreate(entry, guild, client); }); -client.on(Events.ClientReady, () => { - void logger.log( - "debug", - `Keiko is online as ${client.user?.username ?? "unknown"}.`, - ); +client.on(Events.ClientReady, (readyClient) => { + void (async(): Promise => { + const guild = readyClient.guilds.cache.get(guildConfig.guildId); + if (guild) { + await guild.members.fetch(); + } + await logger.log( + "debug", + `Keiko is online as ${readyClient.user.username}.`, + ); + })(); }); await client.login(process.env.DISCORD_TOKEN); diff --git a/src/register.ts b/src/register.ts index 05a6c6f..2817eb8 100644 --- a/src/register.ts +++ b/src/register.ts @@ -29,6 +29,7 @@ const commandData = [ const rest = new REST().setToken(process.env.DISCORD_TOKEN ?? ""); +/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- REST returns unknown; shape is documented by Discord API */ const me = await rest.get(Routes.user()) as { id: string; username: string }; console.log(`Authenticated as: ${me.username} (${me.id})`);