From ddf90fd710a7f7c58a5a270ee98ac7931140d007 Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 1 Dec 2025 00:36:14 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8C=9F=20feat:=20add=20discord=20comm?= =?UTF-8?q?ands=20deploy=20script=20and=20remove=20global=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/deploy-commands.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/utils/deploy-commands.ts diff --git a/src/utils/deploy-commands.ts b/src/utils/deploy-commands.ts new file mode 100644 index 0000000..a638a72 --- /dev/null +++ b/src/utils/deploy-commands.ts @@ -0,0 +1,31 @@ +import { REST, type RESTPutAPIApplicationCommandsResult, Routes } from "discord.js"; +import { commands } from "../commands/index.js"; +import { config } from "../env.js"; + +export async function deployCommands(): Promise { + const commandData = [...commands.values()].map((command) => command.data); + + const rest = new REST({ version: "10" }).setToken(config.discord.token); + + (await rest.put(Routes.applicationCommands(config.discord.clientId), { + body: [], + })) as RESTPutAPIApplicationCommandsResult; + try { + const result = (await rest.put( + Routes.applicationGuildCommands(config.discord.clientId, config.discord.serverId), + { + body: commandData, + } + )) as RESTPutAPIApplicationCommandsResult; + console.log( + `✅ Successfully deployed ${result.length} commands to guild ${config.discord.serverId}` + ); + } catch (error) { + console.error("❌ Error deploying commands:", error); + } +} + +// If run directly with `node deploy.ts` +if (import.meta.url === `file://${process.argv[1]}`) { + deployCommands(); +} From f6df6d74a77401bc5fad2c5302ac1a4fe10d860d Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 1 Dec 2025 00:36:39 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8C=9F=20feat:=20add=20package.json?= =?UTF-8?q?=20script=20to=20deploy=20commands=20localy=20(dev)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index a9fef89..fa50701 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "format": "biome format --write .", "check": "biome check .", "check:fix": "biome check --write .", + "deploy-commands": "tsx src/utils/deploy-commands.ts", "db:migrate": "prisma migrate dev", "db:validate": "prisma validate", "db:format": "prisma format", From 7754374b21d820705c4f723515ad683720be8162 Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 1 Dec 2025 00:37:03 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A4=96=20ci:=20add=20worflow=20to=20d?= =?UTF-8?q?eploy=20commands=20to=20discord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-commands.yml | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/deploy-commands.yml diff --git a/.github/workflows/deploy-commands.yml b/.github/workflows/deploy-commands.yml new file mode 100644 index 0000000..e5730b3 --- /dev/null +++ b/.github/workflows/deploy-commands.yml @@ -0,0 +1,37 @@ +name: Deploy Discord Commands + +on: + workflow_dispatch: # Manual trigger only + +jobs: + deploy-commands: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Read Node version + run: | + NODE_VERSION=$(cat .nvmrc | sed 's/v//') + echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV + + - name: Deploy Discord Commands to VPS + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.VPS_HOST }} + username: ${{ secrets.VPS_USER }} + key: ${{ secrets.VPS_SSH_KEY }} + script: | + cd /home/${{ secrets.VPS_USER }}/moderation-tool-bot + + # Read NODE_VERSION from .nvmrc + export NODE_VERSION=$(cat .nvmrc | sed 's/v//') + echo "Using Node version: $NODE_VERSION" + + # Run deploy script inside the already running Docker container + # .env file should already exist from main deployment + echo "Deploying Discord commands..." + docker compose --profile prod exec discord-bot node dist/utils/deploy-commands.js + + echo "Discord commands deployment completed!" \ No newline at end of file From c2b2726a90e4a2ef188b272d092b7a824828ebae Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 1 Dec 2025 00:43:08 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20fix:=20change=20.env=20to=20?= =?UTF-8?q?.env.local=20in=20workflow=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-commands.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-commands.yml b/.github/workflows/deploy-commands.yml index e5730b3..66a2e84 100644 --- a/.github/workflows/deploy-commands.yml +++ b/.github/workflows/deploy-commands.yml @@ -30,7 +30,7 @@ jobs: echo "Using Node version: $NODE_VERSION" # Run deploy script inside the already running Docker container - # .env file should already exist from main deployment + # .env.local file should already exist from main deployment echo "Deploying Discord commands..." docker compose --profile prod exec discord-bot node dist/utils/deploy-commands.js