Skip to content

Commit a15b30a

Browse files
authored
feat: command deployment (#13)
* 🌟 feat: add discord commands deploy script and remove global commands * 🌟 feat: add package.json script to deploy commands localy (dev) * πŸ€– ci: add worflow to deploy commands to discord * πŸ› fix: change .env to .env.local in workflow comment
1 parent 7dcc474 commit a15b30a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy Discord Commands
2+
3+
on:
4+
workflow_dispatch: # Manual trigger only
5+
6+
jobs:
7+
deploy-commands:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Read Node version
15+
run: |
16+
NODE_VERSION=$(cat .nvmrc | sed 's/v//')
17+
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV
18+
19+
- name: Deploy Discord Commands to VPS
20+
uses: appleboy/ssh-action@v1.0.3
21+
with:
22+
host: ${{ secrets.VPS_HOST }}
23+
username: ${{ secrets.VPS_USER }}
24+
key: ${{ secrets.VPS_SSH_KEY }}
25+
script: |
26+
cd /home/${{ secrets.VPS_USER }}/moderation-tool-bot
27+
28+
# Read NODE_VERSION from .nvmrc
29+
export NODE_VERSION=$(cat .nvmrc | sed 's/v//')
30+
echo "Using Node version: $NODE_VERSION"
31+
32+
# Run deploy script inside the already running Docker container
33+
# .env.local file should already exist from main deployment
34+
echo "Deploying Discord commands..."
35+
docker compose --profile prod exec discord-bot node dist/utils/deploy-commands.js
36+
37+
echo "Discord commands deployment completed!"

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"format": "biome format --write .",
1515
"check": "biome check .",
1616
"check:fix": "biome check --write .",
17+
"deploy-commands": "tsx src/utils/deploy-commands.ts",
1718
"db:migrate": "prisma migrate dev",
1819
"db:validate": "prisma validate",
1920
"db:format": "prisma format",

β€Žsrc/utils/deploy-commands.tsβ€Ž

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { REST, type RESTPutAPIApplicationCommandsResult, Routes } from "discord.js";
2+
import { commands } from "../commands/index.js";
3+
import { config } from "../env.js";
4+
5+
export async function deployCommands(): Promise<void> {
6+
const commandData = [...commands.values()].map((command) => command.data);
7+
8+
const rest = new REST({ version: "10" }).setToken(config.discord.token);
9+
10+
(await rest.put(Routes.applicationCommands(config.discord.clientId), {
11+
body: [],
12+
})) as RESTPutAPIApplicationCommandsResult;
13+
try {
14+
const result = (await rest.put(
15+
Routes.applicationGuildCommands(config.discord.clientId, config.discord.serverId),
16+
{
17+
body: commandData,
18+
}
19+
)) as RESTPutAPIApplicationCommandsResult;
20+
console.log(
21+
`βœ… Successfully deployed ${result.length} commands to guild ${config.discord.serverId}`
22+
);
23+
} catch (error) {
24+
console.error("❌ Error deploying commands:", error);
25+
}
26+
}
27+
28+
// If run directly with `node deploy.ts`
29+
if (import.meta.url === `file://${process.argv[1]}`) {
30+
deployCommands();
31+
}

0 commit comments

Comments
Β (0)