Skip to content

Commit 9633e33

Browse files
author
xyzjesper
committed
Updated command loading
1 parent 7b1e051 commit 9633e33

File tree

3 files changed

+18
-39
lines changed

3 files changed

+18
-39
lines changed

src/helper/CommandHelper.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,6 @@ export class CommandHelper {
7373
}
7474
}
7575

76-
// Load userInstall commands
77-
if (fs.existsSync(commandDirs.userInstall)) {
78-
const userCommandFiles = getFilesRecursively(commandDirs.userInstall, [".js"]);
79-
for (const filePath of userCommandFiles) {
80-
try {
81-
const module = await import(pathToFileURL(filePath).href);
82-
if (module.default?.data) {
83-
cmdlist.push(module.default.data.toJSON());
84-
stats.userInstall++;
85-
}
86-
} catch (error) {
87-
console.error(`Failed to load userInstall command from ${filePath}:`.red, error);
88-
}
89-
}
90-
}
91-
9276
// Load context menu commands
9377
if (fs.existsSync(commandDirs.contextMenus)) {
9478
const contextCommandFiles = getFilesRecursively(commandDirs.contextMenus, [".js"]);
@@ -123,8 +107,7 @@ export class CommandHelper {
123107

124108
const restClient = new REST({version: "10"}).setToken(Config.Bot.DiscordBotToken);
125109

126-
127-
110+
128111
// Clear application command
129112
await restClient.put(Routes.applicationCommands(Config.Bot.DiscordApplicationId), {
130113
body: [],
@@ -134,7 +117,7 @@ export class CommandHelper {
134117
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
135118
body: [],
136119
});
137-
120+
138121
const buildInCommandOverrides = await database.buildInCommands.findMany({
139122
where: {
140123
GuildCommandMangerId: guild.id
@@ -232,6 +215,7 @@ export class CommandHelper {
232215

233216
public static async loadCommands(client: ExtendedClient) {
234217
let cmdlist: any[] = [];
218+
let applicationcmdlist: any[] = [];
235219
const stats = {
236220
commands: 0,
237221
userInstall: 0,
@@ -294,7 +278,7 @@ export class CommandHelper {
294278
try {
295279
const module = await import(pathToFileURL(filePath).href);
296280
if (module.default?.data) {
297-
cmdlist.push(module.default.data.toJSON());
281+
applicationcmdlist.push(module.default.data.toJSON());
298282
stats.userInstall++;
299283
}
300284
} catch (error) {
@@ -342,14 +326,18 @@ export class CommandHelper {
342326
body: [],
343327
});
344328

345-
const allGuilds = await client.guilds.fetch();
346-
for (const guild of allGuilds.values()) {
329+
await restClient.put(Routes.applicationCommands(Config.Bot.DiscordApplicationId), {
330+
body: applicationcmdlist,
331+
});
347332

333+
Logger.info("Application Command Loaded")
334+
Logger.info(`Loading guild commands for ${client.guilds.cache.size} guilds...`)
335+
client.guilds.cache.forEach(async (guild) => {
348336
// Clear Guild Commands
349337
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
350338
body: [],
351339
});
352-
340+
353341
const buildInCommandOverrides = await database.buildInCommands.findMany({
354342
where: {
355343
GuildCommandMangerId: guild.id
@@ -444,6 +432,6 @@ export class CommandHelper {
444432
botType: Config.BotType.toString() || "Unknown",
445433
action: LoggingAction.Command,
446434
});
447-
}
435+
})
448436
}
449437
}

src/modules/bot/events/bot-ready.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@ export default {
2424
name: Events.ClientReady,
2525
async execute(client: ExtendedClient) {
2626
try {
27-
// INFO: Only a little await because I have to load everything here since I definitely have a client here,
28-
// and therefore no await that everything is loaded correctly and then loads in sequence...
29-
// (This events load everything sync and then the functions that need longer they load longer but all functions will be loaded!!!)
30-
3127
// Database init (Default)
32-
initDataToDatabase(client)
28+
await initDataToDatabase(client)
3329

3430
// Load Commands
35-
CommandHelper.loadCommands(client);
31+
setTimeout(async () => {
32+
Logger.info("Loading Command...")
33+
await CommandHelper.loadCommands(client);
34+
}, 10000)
3635

3736
// Invite Tracker Fetch
3837
client.guilds.cache.forEach(async (guild: Guild) => {
39-
guildFetcher(client, guild);
38+
await guildFetcher(client, guild);
4039
})
4140

4241
// Spawn Drops...
@@ -54,13 +53,6 @@ export default {
5453
// AutoDelete
5554
Scheduler.deleteMessagesFromAutoDelete(client);
5655

57-
// Run Guild Commands
58-
const guilds = await client.guilds.fetch();
59-
for (const fakeGuild of guilds.values()) {
60-
const guild = await client.guilds.fetch(fakeGuild.id)
61-
CommandHelper.loadCommandsForGuild(client, guild);
62-
}
63-
6456
// Schedule Vanity URL's && Vote Role on Guild
6557
setInterval(async () => {
6658
Scheduler.checkLast30DaysVanities(client);

src/systems/inviteTracker/guildFetcher.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export async function guildFetcher(client: ExtendedClient, guild: Guild, useCach
2424
}).catch(() => {
2525
});
2626
} else return;
27-
;
2827
});
2928
}).catch(() => {
3029
});

0 commit comments

Comments
 (0)