use bulk overwrite commands endpoint

This commit is contained in:
Cynthia Foxwell 2024-05-17 14:54:37 -06:00
parent 18ef1c0503
commit dd85537e4a
1 changed files with 22 additions and 13 deletions

View File

@ -186,11 +186,8 @@ bot.once("ready", async () => {
logger.info("hf:main", "Reconnected to Discord.");
});
const commands = await bot.getCommands();
const commands = [];
for (const command of interactionCommands.values()) {
const hasCommand = commands.find((c) => c.name == command.name);
if (hasCommand) continue;
const options = Object.values(command.options);
for (const option of options) {
delete option.default;
@ -200,21 +197,33 @@ bot.once("ready", async () => {
const send = options.shift();
options.push(send);
await bot.createCommand({
const formattedCommand = {
name: command.name,
type: command.type,
description: command.helpText,
options: options,
defaultMemberPermissions: command.permissions,
dmPermission: !command.guildOnly,
});
dm_permission: !command.guildOnly,
};
if (command.type === Dysnomia.Constants.ApplicationCommandTypes.CHAT_INPUT)
formattedCommand.name = formattedCommand.name.toLowerCase();
if (command.permissions !== undefined) {
formattedCommand.default_member_permissions =
command.permissions instanceof Dysnomia.Permission
? String(command.permissions.allow)
: String(command.permissions);
}
commands.push(formattedCommand);
}
for (const command of commands) {
if (interactionCommands.has(command.name)) continue;
await bot.deleteCommand(command.id);
}
await this.requestHandler.request(
"PUT",
`/applications/${bot.application.id}/commands`,
true,
commands
);
});
bot.on("error", (err) => {