Skip to content

Commit 919ae21

Browse files
committed
feat: translate /help commands names and descriptions
1 parent c048840 commit 919ae21

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

src/commands/Help.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SlashCommandBuilder, type CommandInteraction, type CommandInteractionOption } from "discord.js";
1+
import { SlashCommandBuilder, type CommandInteraction, type CommandInteractionOption, type LocaleString } from "discord.js";
22
import { useEmbedify } from "@lib/embedify.ts";
33
import { CmdBase, SlashCommand } from "@lib/Command.ts";
44
import pkg from "@root/package.json" with { type: "json" };
@@ -56,6 +56,8 @@ export class HelpCmd extends SlashCommand {
5656

5757
const allowedCmds = [...cmdInstances.values()]
5858
.filter(cmd => {
59+
if(cmd.type === "ctx")
60+
return false;
5961
if(typeof cmd.builderJson.default_member_permissions === "undefined" || cmd.builderJson.default_member_permissions === "0")
6062
return true;
6163
if(typeof int.member?.permissions === "undefined")
@@ -73,38 +75,47 @@ export class HelpCmd extends SlashCommand {
7375
if(!showHidden)
7476
ephemeral = false;
7577

76-
for(const { builderJson: data } of allowedCmds)
77-
cmdList += `- ${hiddenCmds.has(data.name) ? "🔒 " : ""}\`/${data.name}\`${"description" in data ? `\n ${data.description}` : ""}\n`;
78-
7978
await int.deferReply({ ephemeral });
80-
const locale = await HelpCmd.getGuildLocale(int);
8179

82-
return int.editReply(useEmbedify(cmdList, undefined, (e) => e
83-
.setTitle(tr.for(locale, "commands.help.embedTitles.commands"))
84-
.setFooter({ text: tr.for(locale, "commands.help.embedFooters.commands") }),
85-
));
80+
const locale = await HelpCmd.getGuildLocale(int),
81+
t = tr.use(locale);
82+
83+
for(const { builderJson: data } of allowedCmds) {
84+
const name = data.name_localizations?.[locale as LocaleString] ?? data.name;
85+
const description = data.description_localizations?.[locale as LocaleString] ?? ("description" in data ? data.description : undefined);
86+
87+
cmdList += `- ${hiddenCmds.has(data.name) ? "🔒 " : ""}\`/${name}\`${description ? `\n ${description}` : ""}\n`;
88+
}
89+
90+
return int.editReply(
91+
useEmbedify(cmdList, undefined, (e) => e
92+
.setTitle(t("commands.help.embedTitles.commands"))
93+
.setFooter({ text: t("commands.help.embedFooters.commands") }),
94+
)
95+
);
8696
}
8797
case "info": {
8898
await int.deferReply();
89-
const locale = await HelpCmd.getGuildLocale(int);
9099

100+
const t = tr.use(await HelpCmd.getGuildLocale(int));
91101
const { version, author: { name, url }} = pkg;
102+
92103
return int.editReply(useEmbedify([
93-
tr.for(locale, "commands.help.info.headline", { version, name, url }),
94-
tr.for(locale, "commands.help.info.donationLink", pkg.funding.url),
104+
t("commands.help.info.headline", { version, name, url }),
105+
t("commands.help.info.donationLink", pkg.funding.url),
95106
"",
96-
tr.for(locale, "commands.help.info.bugsLink", pkg.bugs.url),
97-
tr.for(locale, "commands.help.info.supportServerLink", getEnvVar("SUPPORT_SERVER_INVITE_URL")),
98-
tr.for(locale, "commands.help.info.globalOptOut"),
107+
t("commands.help.info.bugsLink", pkg.bugs.url),
108+
t("commands.help.info.supportServerLink", getEnvVar("SUPPORT_SERVER_INVITE_URL")),
109+
t("commands.help.info.globalOptOut"),
99110
"",
100-
tr.for(locale, "commands.help.info.installExtensions"),
101-
tr.for(locale, "commands.help.info.installExtReturnYtDislike"),
102-
tr.for(locale, "commands.help.info.installExtSponsorBlock"),
103-
tr.for(locale, "commands.help.info.installExtDeArrow"),
104-
tr.for(locale, "commands.help.info.installExtMobile"),
111+
t("commands.help.info.installExtensions"),
112+
t("commands.help.info.installExtReturnYtDislike"),
113+
t("commands.help.info.installExtSponsorBlock"),
114+
t("commands.help.info.installExtDeArrow"),
115+
t("commands.help.info.installExtMobile"),
105116
"",
106-
tr.for(locale, "commands.help.info.poweredBy"),
107-
], undefined, (e) => e.setTitle(tr.for(locale, "commands.help.embedTitles.info"))));
117+
t("commands.help.info.poweredBy"),
118+
], undefined, (e) => e.setTitle(t("commands.help.embedTitles.info"))));
108119
}
109120
}
110121
}

0 commit comments

Comments
 (0)