Ren-chan
Ren-chan is a Discord bot for riichi club management, using Google Sheets for data store. Ren-chan is based on Ronhorn, as an effort to:
- isolate the club management commands from the mahjong analysis commands (e.g.,
/injustice
)
- eventually create an end-to-end club management bot with minimal setup
Repository Structure:
bot.py
: entry point of the Discord bot. Does the following:
- imports
global_stuff.py
, which does the following:
- load all the environment variabels from
config.env
- set up the non-slash Discord commands
- set up command error handlers (both slash and non-slash)
/ext/
: Discord bot extensions (each extension is a suite of slash commands and their helper functions)
Utilities
: various utilities, including recording in-person games, managing club membership, etc.
Setting up the bot
First, cp config.template.env config.env
.
Discord Stuff
- set up a bot account on Discord's developer portal (
New Application
).
- (SETTINGS -> Bot) Privileged Gateway Intents:
SERVER MEMBERS INTENT
AND MESSAGE CONTENT INTENT
- invite the bot to the respective servers. You can use the developer portal's OAuth2 URL Generator (SETTINGS -> OAuth2 -> URL Generator):
- Scopes: bot
- Bot Permissions:
- General Permissions: Manage Roles, Read Messages/View Channels
- Text Permissions: Send Messages, Create Public Threads, Send Messages in Threads, Manage Messages, Manage Threads, Use External Emojis
- Current Bot Invite URL
- fill in the
Discord Stuff
section of config.env. The bot token can be obtained through (SETTINGS -> Bot [-> Reset Token])
Google Sheets Stuff
- set up a Google Cloud project. Enable Google Sheets API access, and "Create Credentials" for a service account (no need to give it access to the project). Generate a JSON key for that service account and save it as
gs_service_account.json
in the root directory
- make a suitable Google Spreadsheet (example)
- share the Spreadsheet with that service account.
- fill in the
Google Sheets Stuff
section of config.env
Running the bot
-
in a Unix shell:
pipenv install
pipenv shell
./start.sh
- in the relevant Discord server: run
rc/sync
to sync the slash commands for that server (rc/
is the regular command prefix).
Relevant Links (References)