Skip to content

Commit

Permalink
refactor: make deployCommands function only take 1 single commands param
Browse files Browse the repository at this point in the history
  • Loading branch information
samhwang committed Apr 13, 2024
1 parent 3ff1331 commit baa5bed
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const main = async () => {
// For development usage, please use `pnpm deploy:command`
logger.info('[main]: Deploying global commands');
const op = await Result.safe(
deployGlobalCommands(commandList, contextMenuCommandList, {
deployGlobalCommands([...commandList, ...contextMenuCommandList], {
token,
clientId: client.user.id,
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-global-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const deploy = async () => {

logger.info('[delete-global-commands]: Deleting global commands');
const op = await Result.safe(
deployGlobalCommands([], [], {
deployGlobalCommands([], {
token,
clientId,
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-guild-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const deploy = async () => {

logger.info('[delete-guild-commands]: Deleting guild commands');
const op = await Result.safe(
deployGuildCommands([], [], {
deployGuildCommands([], {
token,
clientId,
guildId,
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-guild-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const deploy = async () => {

logger.info('[deploy-guild-commands]: Deploying guild commands');
const op = await Result.safe(
deployGuildCommands(commandList, contextMenuCommandList, {
deployGuildCommands([...commandList, ...contextMenuCommandList,], {
token,
clientId,
guildId,
Expand Down
12 changes: 4 additions & 8 deletions src/commands/deploy-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@ const registerCommands = async ({ request, token, body }: DiscordRequestPayload)
return rest.put(request, { body });
};

export const deployGuildCommands = async (commandList: Command[], contextMenuCommandList: ContextMenuCommand[], config: DiscordRequestConfig) => {
export const deployGuildCommands = async (commandList: Array<Command | ContextMenuCommand>, config: DiscordRequestConfig) => {
const { token, clientId, guildId } = config;

const commands = [...commandList, ...contextMenuCommandList].map((cmd) => cmd.data.toJSON());
const commands = commandList.map((cmd) => cmd.data.toJSON());

const request = Routes.applicationGuildCommands(clientId, guildId);
return registerCommands({ request, token, body: commands });
};

export const deployGlobalCommands = async (
commandList: Command[],
contextMenuCommandList: ContextMenuCommand[],
config: Omit<DiscordRequestConfig, 'guildId'>
) => {
export const deployGlobalCommands = async (commandList: Array<Command | ContextMenuCommand>, config: Omit<DiscordRequestConfig, 'guildId'>) => {
const { token, clientId } = config;

const commands = [...commandList, ...contextMenuCommandList].map((cmd) => cmd.data.toJSON());
const commands = commandList.map((cmd) => cmd.data.toJSON());

const request = Routes.applicationCommands(clientId);
return registerCommands({ request, token, body: commands });
Expand Down

0 comments on commit baa5bed

Please sign in to comment.