Skip to content

Commit da09d14

Browse files
author
xyzjesper
committed
Improve Database Init for Users and change log message from CommandHelper.ts
1 parent 02daf1e commit da09d14

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/helper/CommandHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class CommandHelper {
219219
timestamp: new Date().toISOString(),
220220
level: "error",
221221
label: "CommandHelper",
222-
message: `Command loading failed with error: ${e} - Commands failed at ${cmdlist.map((c) => c.name)} commands`,
222+
message: `Command loading failed with error: ${e} - Commands failed at ${cmdlist.map((c) => c.name)} commands on Guild \"${guild.name}\" (${guild.id})`,
223223
botType: Config.BotType.toString() || "Unknown",
224224
action: LoggingAction.Command,
225225
});
@@ -229,7 +229,7 @@ export class CommandHelper {
229229
timestamp: new Date().toISOString(),
230230
level: "info",
231231
label: "CommandHelper",
232-
message: `Discord added ${cmdlist.length} commands (${stats.subCommands} subCommands, ${stats.subCommandGroups} subCommandGroups), ${stats.userInstall} userInstall commands, ${stats.contextMenus} context menu commands from ${moduleDirectories.length} module(s) for ${allGuilds.size} Guilds`,
232+
message: `Discord added ${cmdlist.length} commands (${stats.subCommands} subCommands, ${stats.subCommandGroups} subCommandGroups), ${stats.userInstall} userInstall commands, ${stats.contextMenus} context menu commands from ${moduleDirectories.length} module(s) for \"${guild.name}\" (${guild.id})`,
233233
botType: Config.BotType.toString() || "Unknown",
234234
action: LoggingAction.Command,
235235
});

src/helper/databaseHelper.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {LoggingAction} from "../enums/loggingTypes.js";
77
import colors from "colors"
88
import {User} from "discord.js";
99
import {Config} from "../main/config.js";
10+
import * as cluster from "node:cluster";
1011

1112
colors.enable();
1213

@@ -96,7 +97,7 @@ export async function setupDisBotConfig(client: ExtendedClient): Promise<void> {
9697
export async function initGuildsToDatabase(client: ExtendedClient) {
9798
const allGuilds = await client.guilds.fetch();
9899

99-
allGuilds.forEach(async (guild) => {
100+
for (const guild of allGuilds.values()) {
100101
// Init Guilds
101102
const guildsData = await database.guilds.findFirst({
102103
where: {
@@ -152,7 +153,31 @@ export async function initGuildsToDatabase(client: ExtendedClient) {
152153
}
153154
})
154155
}
155-
})
156+
157+
// Init Guild Users
158+
const clientGuild = await client.guilds.fetch(guild.id)
159+
const guildMembers = await clientGuild.members.fetch()
160+
161+
for (const member of guildMembers.values()) {
162+
await initUsersToDatabase(client, member.user)
163+
}
164+
165+
Logger.info(
166+
{
167+
guildId: "0",
168+
userId: "0",
169+
channelId: "0",
170+
messageId: "0",
171+
timestamp: new Date().toISOString(),
172+
level: "info",
173+
label: "Database",
174+
message: `Database init loaded for Guild ${clientGuild.name} ${guildMembers.size} members!`.gray,
175+
botType: Config.BotType.toString() || "Unknown",
176+
action: LoggingAction.Database,
177+
}
178+
);
179+
180+
}
156181
}
157182

158183
export async function initUsersToDatabase(client: ExtendedClient, user: User) {

0 commit comments

Comments
 (0)