Skip to content

Commit

Permalink
fix: remove command duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Clembs committed Jul 31, 2024
1 parent 084f96d commit 334d6cb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/modules/events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ async function loadEconomyCommands(client: Client) {
...economy,
});

console.log(economy);

const discordGuild = await client.guilds.fetch(economy.id);
const urlParams = new URLSearchParams();
urlParams.set('with_localizations', 'true');
Expand Down Expand Up @@ -99,6 +97,13 @@ async function loadEconomyCommands(client: Client) {
});
});

// remove commands duplicates
commands = commands.filter(
(command, index, self) =>
index ===
self.findIndex((t) => t.name === command.name && t.description === command.description),
);

const res = await fetch(
`https://discord.com/api/v10/applications/${client.user.id}/guilds/${economy.id}/commands`,
{
Expand All @@ -111,7 +116,10 @@ async function loadEconomyCommands(client: Client) {
},
);

console.log(JSON.stringify(await res.json()));
if (!res.ok) {
console.error(await res.json());
return;
}

console.log(`Posted ${commands.length} commands on ${discordGuild.name ?? economy.id}`);
}),
Expand Down

0 comments on commit 334d6cb

Please sign in to comment.