Skip to content

Commit

Permalink
fix registercommands
Browse files Browse the repository at this point in the history
  • Loading branch information
PyxelCodes committed Dec 29, 2024
1 parent 64709b4 commit b1a39b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aetherial",
"version": "1.2.8",
"version": "1.2.9",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/types/index.d.ts",
Expand Down
41 changes: 21 additions & 20 deletions src/rest/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export async function registerCommands(
token: string,
guildId?: string
) {
const cmds = Array.from(commands, ([n, v]) => v).map((cmd) => { // eslint-disable-line @typescript-eslint/no-unused-vars
const cmds = Array.from(commands, ([n, v]) => v).map((cmd) => {
// eslint-disable-line @typescript-eslint/no-unused-vars
let builder: SlashCommandBuilder = cmd.data;
if (!builder) builder = new SlashCommandBuilder();
builder.setName(cmd.name);
Expand Down Expand Up @@ -39,26 +40,26 @@ export async function registerCommands(
.red
);
}

try {
const uri = guildId ? `guilds/${guildId}/commands` : `commands`;
await axios.put(
`https://discord.com/api/v10/applications/${client.id}/${uri}`,
cmds,
{ headers: { Authorization: `Bot ${token}` } }
return;
}
try {
const uri = guildId ? `guilds/${guildId}/commands` : `commands`;
await axios.put(
`https://discord.com/api/v10/applications/${client.id}/${uri}`,
cmds,
{ headers: { Authorization: `Bot ${token}` } }
);
} catch (error) {
if (error instanceof AxiosError) {
console.error(`Failed to send commands to Discord API`.red);
console.log({
url: error.config.url,
response: error.response.data,
});
console.error(
`HTTP ${error.response?.status} ${error.response?.statusText}`
.red
);
} catch (error) {
if (error instanceof AxiosError) {
console.error(`Failed to send commands to Discord API`.red);
console.log({
url: error.config.url,
response: error.response.data,
});
console.error(
`HTTP ${error.response?.status} ${error.response?.statusText}`
.red
);
}
}
}
}

0 comments on commit b1a39b6

Please sign in to comment.