Skip to content

Commit

Permalink
fix: deploy commands to all servers, register on all
Browse files Browse the repository at this point in the history
  • Loading branch information
sanriodev committed Oct 24, 2024
1 parent 01bcb44 commit f4fa935
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
BOT_TOKEN =
#used for adding bot/application to server
CLIENT_ID =
# invite link:
# https://discord.com/api/oauth2/authorize?CLIENT_ID=<clientId>&permissions=0&scope=bot%20applications.commands
SERVER_ID =
# Mongo configuration
MONGO_URI=
MONGO_PORT=
Expand Down
23 changes: 17 additions & 6 deletions src/deployment/deploy.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { REST, RESTPostAPIChatInputApplicationCommandsJSONBody, Routes } from 'discord.js';
import {
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
} from 'discord.js';
import { Injectable } from '@nestjs/common';
import { CommandService } from '../modules/command/command.service';
import { AppConfigService } from '../config/config.service';
Expand All @@ -18,18 +22,25 @@ export class DeployServcice {
return commands.map((command) => command.data.toJSON());
}

async deployCommands(commands: RESTPostAPIChatInputApplicationCommandsJSONBody[]) {
async deployCommands(
commands: RESTPostAPIChatInputApplicationCommandsJSONBody[],
) {
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(this.configService.botToken);

// and deploy your commands!
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
console.log(
`Started refreshing ${commands.length} application (/) commands.`,
);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID ?? '', process.env.SERVER_ID ?? ''), {
body: commands,
});
const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID ?? ''),
{
body: commands,
},
);

let log = '';
if (Array.isArray(data)) log = data.length + ' ';
Expand Down

0 comments on commit f4fa935

Please sign in to comment.