File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 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!"
Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change 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+ }
You canβt perform that action at this time.
0 commit comments