Skip to content

Commit

Permalink
[feat](syncCommands) don't sync perms for global commands, better log…
Browse files Browse the repository at this point in the history
…ging
  • Loading branch information
0xDevansh committed Mar 15, 2022
1 parent 68b14d9 commit b1bd4e1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/commands/syncCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const setPermissions = async (registered: ApplicationCommand, command: SlashComm
}),
);

if (!permissions.length) return;

await registered.permissions.set({ permissions });
};

Expand All @@ -49,6 +51,7 @@ const setPermissions = async (registered: ApplicationCommand, command: SlashComm
* @param {SlashCommand[]} newCommands The commands to sync
*/
const syncGlobalCommands = async (application: ClientApplication, newCommands: SlashCommand[]): Promise<void> => {
logVerbose('Syncing global commands', application.client);
const currentCommands = await application.commands.fetch();
const cc = currentCommands.map((c) => toApplicationCommand(c));

Expand All @@ -59,20 +62,20 @@ const syncGlobalCommands = async (application: ClientApplication, newCommands: S
// command is new
if (!matching) {
logVerbose(`Syncing new global command: ${command.name}`, application.client);
const registered = await application.commands.create(command);
await setPermissions(registered, command);
await application.commands.create(command);
logVerbose(` ✅ ${command.name}`, application.client);
continue;
}

// command has changed
if (!deepEqual(matching, toApplicationCommand(command))) {
logVerbose(`Syncing changed global command: ${command.name}`, application.client);
const registered = await application.commands.create(command);
await setPermissions(registered, command);
await application.commands.create(command);
}

// finally, remove from synced commands
cc.splice(cc.indexOf(matching), 1);
logVerbose(` ✅ ${command.name}`, application.client);
}

// delete left over commands
Expand Down Expand Up @@ -215,6 +218,7 @@ export const syncCommands = async (client: Client): Promise<void> => {
if (global) await syncGlobalCommands(application, global);

// sync guild commands
logVerbose(`Syncing guild commands`, client);
const guilds = await client.guilds.fetch();
for (const [, g] of guilds) {
const guild = await g.fetch();
Expand Down

0 comments on commit b1bd4e1

Please sign in to comment.