diff --git a/bot/deploy-commands.js b/bot/deploy-commands.js index fdfa21f36..7c34cd114 100644 --- a/bot/deploy-commands.js +++ b/bot/deploy-commands.js @@ -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) @@ -21,13 +22,10 @@ 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') { @@ -35,13 +33,13 @@ const 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) { diff --git a/docs/DISCORD_BOT.md b/docs/DISCORD_BOT.md index 97152275f..914d48896 100644 --- a/docs/DISCORD_BOT.md +++ b/docs/DISCORD_BOT.md @@ -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= +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. diff --git a/package.json b/package.json index ff6848677..cf970f185 100644 --- a/package.json +++ b/package.json @@ -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",