The official Discord bot for Codewars.
Early stage. Expect breaking changes.
Feedback is appreciated (Discord or GitHub issues/discussions).
The following environment variables are required:
BOT_TOKEN
: The token used to log in.CLIENT_ID
: The ID of the application associated with the bot.GUILD_ID
: The ID of the server where slash commands should be registered.
Use .env.development
(gitignored) to configure these variables.
NOTE: Please discuss with us first before adding new features to avoid wasting your time.
Before working on this repo, you should already have set up a bot account and added it to your development server, with at least the following permissions:
applications.commands
: Enables the use of slash commandsbot
: Enables your application to join the server as a botSEND_MESSAGES
: Enables your bot to send messages to channelsMANAGE_MESSAGES
: Enables your bot to edit server messages and reactions
You also need to enable the MESSAGE CONTENT INTENT
for your bot.
In order to mimic the Codewars Discord server in your development server, you may also wish to add appropriate roles such as @admin
, @mods
and @power-users
, as well as common channels such as #help-solve
and #bot-playground
.
-
Fork this repo
-
Clone the fork to your local development environment, assuming
GITHUB_USERNAME
is set to your GitHub username:$ git clone git@github.com:"$GITHUB_USERNAME"/discord-bot.git
-
Make this project your working directory
-
Install dependencies and compile TypeScript
$ npm install
-
Start TypeScript compiler process to recompile on change:
$ npm run build:watch
-
In a new terminal session, copy
.env.example
to.env.development
:$ cp .env.example .env.development
-
In
.env.development
:- Set
BOT_TOKEN
to your bot token - Set
CLIENT_ID
andGUILD_ID
to your application ID and server ID, respectively
- Set
-
Start the bot:
$ npm start
After confirming that the bot works as expected, make changes to the local copy of your fork as appropriate and test your changes by restarting the bot.
Run npx plop command
to generate boilerplate. You will be asked to enter the name of the command (lowercase English letters only) which should be a verb and select an associated category.
If your command belongs to a category that does not exist yet, stop the command generation by pressing Ctrl-C
, then modify plopfile.mjs
as appropriate to add your category and re-run npx plop command
.
Run npx plop message-handler
to generate boilerplate.
Prettier is used to ensure consistent style. We use the defaults except for printWidth: 100
because 80
is often too narrow with types.
pre-commit
hook to format staged changes is installed automatically when you run npm install
, so you don't need to do anything. However, it's recommended to configure your editor to format on save, and forget about formatting.