Runtime and Code Management - shinyfinder/chatot-smogon GitHub Wiki

Managing commands

This bot uses slash commands (a subset of application commands). Deployment of these commands is handled during startup of the bot witihn the /src/helpers/updateState.ts file. This script detects any changes in your command definitions and (re)deploys them as appropriate. The deployment scope is defined within the command definitions themselves with the following flags:

global: <boolean>
guilds: <string[]>

Setting the global flag to true will cause the command to be deployed globally (i.e. to every server the bot is in). Setting the global flag to false and providing a list of server IDs as strings within the guilds array will instead deploy the command as a guild command (i.e. only to that guild) to the listed servers. Note that if the bot is in dev mode (its client id is equal to a value specifed in /src/helpers/hashCommands.ts), the specified guild array will be overwritten with the dev guild id specifed in the .env.

Starting the bot

With Docker running on your system, open a new terminal and navigate to the root project directory. Establish a live connection to the production server with pnpm tunnel.

Then, open a new terminal, navigate to the project's root directory, and start the bot from the terminal with pnpm chatot.

You should see that the bot is now online in Discord. To confirm it is responding to commands, post the following within Discord:

/ping

The bot should respond with "Pong!".

Your running instance of Chatot can be turned off with Ctrl+C within the terminal that's running it. This will trigger the shutdown sequence (in reality this sequence is triggered by sending a SIGTERM to the program, but we in turn send that automatically on SIGINT), backing up any inserts to the databases and logging out of Discord. Please give the program a few moments to finish. When done, the program should return on its own and print some message lke "Aborted". Keep in mind spamming Ctrl+C will cause the program to terminate immediately without backing up your information or shutting down cleanly.

Code organization

Comments are provided within the *.ts files to offer a more precise understanding of what the code is doing line-by-line. For the sake of providiing a general overview, the core components of the bot are separated into different directories within /src. Any additions you make to the code will likely go within this folder. Commands (user interfaces with the bot) and events (triggers the bot listens for) are separated into their respective directories. Further, each command and event is given its own file. While it may be possible to oranize the files into further subdirectories, each feature being given its own file allows for easier debugging and isolation of code. Any functions used by the commands or multiple files are stored in the /helpers directoy. Type defintions needed by multiple files are stored within the /types directory.

⚠️ **GitHub.com Fallback** ⚠️