generated from nhcarrigan/template
feat: pre-fetch guild members on boot
This commit is contained in:
+12
-5
@@ -20,6 +20,7 @@ import { softbanCommand } from "./commands/softban.js";
|
|||||||
import { unbanCommand } from "./commands/unban.js";
|
import { unbanCommand } from "./commands/unban.js";
|
||||||
import { unmuteCommand } from "./commands/unmute.js";
|
import { unmuteCommand } from "./commands/unmute.js";
|
||||||
import { warnCommand } from "./commands/warn.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
|
// eslint-disable-next-line stylistic/max-len -- Import path cannot be shortened
|
||||||
import { onGuildAuditLogEntryCreate } from "./events/guildAuditLogEntryCreate.js";
|
import { onGuildAuditLogEntryCreate } from "./events/guildAuditLogEntryCreate.js";
|
||||||
import { onGuildMemberAdd } from "./events/guildMemberAdd.js";
|
import { onGuildMemberAdd } from "./events/guildMemberAdd.js";
|
||||||
@@ -127,11 +128,17 @@ client.on(Events.GuildAuditLogEntryCreate, (entry, guild) => {
|
|||||||
void onGuildAuditLogEntryCreate(entry, guild, client);
|
void onGuildAuditLogEntryCreate(entry, guild, client);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(Events.ClientReady, () => {
|
client.on(Events.ClientReady, (readyClient) => {
|
||||||
void logger.log(
|
void (async(): Promise<void> => {
|
||||||
"debug",
|
const guild = readyClient.guilds.cache.get(guildConfig.guildId);
|
||||||
`Keiko is online as ${client.user?.username ?? "unknown"}.`,
|
if (guild) {
|
||||||
);
|
await guild.members.fetch();
|
||||||
|
}
|
||||||
|
await logger.log(
|
||||||
|
"debug",
|
||||||
|
`Keiko is online as ${readyClient.user.username}.`,
|
||||||
|
);
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
await client.login(process.env.DISCORD_TOKEN);
|
await client.login(process.env.DISCORD_TOKEN);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const commandData = [
|
|||||||
|
|
||||||
const rest = new REST().setToken(process.env.DISCORD_TOKEN ?? "");
|
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 };
|
const me = await rest.get(Routes.user()) as { id: string; username: string };
|
||||||
console.log(`Authenticated as: ${me.username} (${me.id})`);
|
console.log(`Authenticated as: ${me.username} (${me.id})`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user