Skip to content

Commit

Permalink
Fix: Global Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RileCraft committed Jan 27, 2024
1 parent ce61d73 commit 82b57f3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<img src="https://media.discordapp.net/attachments/774290264764055582/1093484780525469757/A_banner_for_a_discord_bots_template_made_using_discord.js.png" height="200" width="400"><br>
<img src="https://img.shields.io/badge/version-1.0.3-05122A?style=for-the-badge">
<img src="https://img.shields.io/badge/version-1.0.4-05122A?style=for-the-badge">
<a href="https://discord.gg/VStdRr8nP2"><img src="https://img.shields.io/badge/discord-invite-5865f2?style=for-the-badge&logo=discord&logoColor=white"></a>
<img src="https://img.shields.io/github/issues/RileCraft/DiscordBot-Template-ts.svg?style=for-the-badge">
<img src="https://img.shields.io/github/forks/RileCraft/DiscordBot-Template-ts.svg?style=for-the-badge">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discordbot-template-ts",
"version": "1.0.3",
"version": "1.0.4",
"description": "TypeScript version of DiscordBot-Template",
"main": "./src/bot.ts",
"type": "module",
Expand Down
90 changes: 47 additions & 43 deletions src/structures/managers/slashCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,61 @@ export const SlashManager = async (client: DiscordClient, rootPath: string): Pro
const guildCommandsObject: GuildCommandObjects = {};
const globalCommandsArray: Array<GlobalCommandArray> = [];

if (allSlashCommandsFiles.length > 0) allSlashCommandsFiles.forEach(async(slashCommandFile: string) => {
const slashCommand: SlashCommand | undefined = (await import(slashCommandFile))?.Slash;
if (!slashCommand) return;
if (allSlashCommandsFiles.length > 0) {
for (const slashCommandFile of allSlashCommandsFiles) {
const slashCommand: SlashCommand | undefined = (await import(slashCommandFile))?.Slash;
if (!slashCommand) continue;

if (slashCommand?.ignore || !slashCommand?.name || !slashCommand.description) return;
client.slashCommands?.set(slashCommand.name, slashCommand);
if (slashCommand?.ignore || !slashCommand?.name || !slashCommand.description) continue;
client.slashCommands?.set(slashCommand.name, slashCommand);

if (slashCommand.guilds && Array.isArray(slashCommand.guilds)) {
for (const guild of slashCommand.guilds) {
if (!guildCommandsObject[guild]) guildCommandsObject[guild] = [];
if (slashCommand.guilds && Array.isArray(slashCommand.guilds)) {
for (const guild of slashCommand.guilds) {
if (!guildCommandsObject[guild]) guildCommandsObject[guild] = [];

guildCommandsObject[guild].push({
name: slashCommand.name,
nsfw: slashCommand.nsfw ?? false,
description: slashCommand.description,
type: ApplicationCommandType.ChatInput,
options: slashCommand.options ?? []
})
};
} else return globalCommandsArray.push({
name: slashCommand.name,
nsfw: slashCommand.nsfw ?? false,
description: slashCommand.description,
type: ApplicationCommandType.ChatInput,
options: slashCommand.options ?? []
})
});
guildCommandsObject[guild].push({
name: slashCommand.name,
nsfw: slashCommand.nsfw ?? false,
description: slashCommand.description,
type: ApplicationCommandType.ChatInput,
options: slashCommand.options ?? []
})
};
} else globalCommandsArray.push({
name: slashCommand.name,
nsfw: slashCommand.nsfw ?? false,
description: slashCommand.description,
type: ApplicationCommandType.ChatInput,
options: slashCommand.options ?? []
})
};
};

if (allContextMenusFiles.length > 0) allContextMenusFiles.forEach(async(contextMenuFile: string) => {
const contextMenu: ContextMenu | undefined = (await import(contextMenuFile))?.Context;
if (!contextMenu) return;
if (allContextMenusFiles.length > 0) {
for (const contextMenuFile of allContextMenusFiles) {
const contextMenu: ContextMenu | undefined = (await import(contextMenuFile))?.Context;
if (!contextMenu) continue;

if (contextMenu?.ignore || !contextMenu?.name || !contextMenu?.type) return;
client.contextMenus?.set(contextMenu.name, contextMenu);
if (contextMenu?.ignore || !contextMenu?.name || !contextMenu?.type) continue;
client.contextMenus?.set(contextMenu.name, contextMenu);

if (contextMenu.guilds && Array.isArray(contextMenu.guilds)) {
for (const guild of contextMenu.guilds) {
if (!guildCommandsObject[guild]) guildCommandsObject[guild] = [];
if (contextMenu.guilds && Array.isArray(contextMenu.guilds)) {
for (const guild of contextMenu.guilds) {
if (!guildCommandsObject[guild]) guildCommandsObject[guild] = [];

guildCommandsObject[guild].push({
name: contextMenu.name,
type: contextMenu.type
})
};
}
guildCommandsObject[guild].push({
name: contextMenu.name,
type: contextMenu.type
})
};
}

else return globalCommandsArray.push({
name: contextMenu.name,
type: contextMenu.type
})
});
else globalCommandsArray.push({
name: contextMenu.name,
type: contextMenu.type
})
};
};

try {
await rest.put(Routes.applicationCommands(client.application.id), {
Expand Down

0 comments on commit 82b57f3

Please sign in to comment.