Skip to content

Commit

Permalink
Add documentation for updating bot commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KittySparkles committed Nov 22, 2024
1 parent 5befeca commit 7cea5b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
14 changes: 6 additions & 8 deletions bot/deploy-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { REST } from '@discordjs/rest'

const CLIENT_ID = process.env.DISCORD_APP_ID
const DISCORD_TOKEN = process.env.DISCORD_TOKEN
const SERVER_ID = process.env.DISCORD_SERVER_ID || '714858253531742208'

const commands = (
await Promise.all(
fs
.readdirSync('./bot/commands')
.map(name => import(`./commands/${name}/index.js`))
.map(name => import(`./commands/${name}/index.js`)),
)
)
.map(module => module.default)
Expand All @@ -21,27 +22,24 @@ const commands = (
const rest = new REST({ version: '10' }).setToken(DISCORD_TOKEN)
const environment = process.env.NODE_ENV
const global = Routes.applicationCommands(CLIENT_ID)
const local = Routes.applicationGuildCommands(
CLIENT_ID,
'714858253531742208'
)
const local = Routes.applicationGuildCommands(CLIENT_ID, SERVER_ID)

console.log(
`Started refreshing ${commands.length} application (/) commands in ${environment}.`
`Started refreshing ${commands.length} application (/) commands in ${environment}.`,
)

if (environment === 'production') {
const data = await rest.put(global, { body: commands })
await rest.put(local, { body: [] })

console.log(
`Successfully reloaded ${data.length} application (/) commands in ${environment}.`
`Successfully reloaded ${data.length} application (/) commands in ${environment}.`,
)
} else {
const data = await rest.put(local, { body: commands })

console.log(
`Successfully reloaded ${data.length} application (/) commands in ${environment}.`
`Successfully reloaded ${data.length} application (/) commands in ${environment}.`,
)
}
} catch (error) {
Expand Down
18 changes: 18 additions & 0 deletions docs/DISCORD_BOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ npm run bot:dev

The bot is automatically deployed on Heroku with every commit that gets pushed to the `main` branch. This environment is named [stormbound-kitty-bot](https://github.com/Stormbound-Games/stormbound-kitty/deployments/activity_log?environment=stormbound-kitty-bot) on GitHub.

### Updating commands

Updating the definition of Discord bot commands requires a manual intervention. First, make sure you have a `.env` file at the root of the repository with the following environment variables:

```
DISCORD_APP_ID=714857388229787809
DISCORD_TOKEN=<secret>
NODE_ENV=development
```

You can find the Discord token in the Heroku environment variables for the project.

Then, execute the following command where the Discord server ID is the ID of the Discord server using the bot (the one in the example below is the official Stormbound Discord ID):

```
DISCORD_SERVER_ID=293674725069029377 npm run bot:refresh
```

## Setup

To set up the bot on a new Discord server, follow the [typical process](https://discordpy.readthedocs.io/en/stable/discord.html#inviting-your-bot) to invite it. Then, run the `bot/setup.sh` script passing it the Discord server (guild) ID. It will require a [jsonbin](https://jsonbin.org/) authentication token from Kitty.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build-site": "next build && next-sitemap",
"test": "npm run modulify && jest --forceExit",
"bot": "npm run modulify && node bot/cli.js",
"bot:refresh": "npm run modulify && node bot/deploy-commands.js",
"bot:dev": "npm run modulify && nodemon bot/cli.js --watch src --watch bot",
"prepare": "husky install",
"revalidate": "node --experimental-fetch -r dotenv/config bin/revalidate.js",
Expand Down

0 comments on commit 7cea5b1

Please sign in to comment.