use bulk overwrite commands endpoint
This commit is contained in:
parent
18ef1c0503
commit
dd85537e4a
1 changed files with 22 additions and 13 deletions
33
src/index.js
33
src/index.js
|
@ -186,11 +186,8 @@ bot.once("ready", async () => {
|
||||||
logger.info("hf:main", "Reconnected to Discord.");
|
logger.info("hf:main", "Reconnected to Discord.");
|
||||||
});
|
});
|
||||||
|
|
||||||
const commands = await bot.getCommands();
|
const commands = [];
|
||||||
for (const command of interactionCommands.values()) {
|
for (const command of interactionCommands.values()) {
|
||||||
const hasCommand = commands.find((c) => c.name == command.name);
|
|
||||||
if (hasCommand) continue;
|
|
||||||
|
|
||||||
const options = Object.values(command.options);
|
const options = Object.values(command.options);
|
||||||
for (const option of options) {
|
for (const option of options) {
|
||||||
delete option.default;
|
delete option.default;
|
||||||
|
@ -200,21 +197,33 @@ bot.once("ready", async () => {
|
||||||
const send = options.shift();
|
const send = options.shift();
|
||||||
options.push(send);
|
options.push(send);
|
||||||
|
|
||||||
await bot.createCommand({
|
const formattedCommand = {
|
||||||
name: command.name,
|
name: command.name,
|
||||||
type: command.type,
|
type: command.type,
|
||||||
description: command.helpText,
|
description: command.helpText,
|
||||||
options: options,
|
options: options,
|
||||||
defaultMemberPermissions: command.permissions,
|
dm_permission: !command.guildOnly,
|
||||||
dmPermission: !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);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const command of commands) {
|
commands.push(formattedCommand);
|
||||||
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) => {
|
bot.on("error", (err) => {
|
||||||
|
|
Loading…
Reference in a new issue