Skip to content

codewars/discord-bot

Repository files navigation

Codewars Discord Bot

Discord chat CI License MIT code style: prettier

The official Discord bot for Codewars.

Project Status

Early stage. Expect breaking changes.

Feedback is appreciated (Discord or GitHub issues/discussions).

Configuration

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.

Development Setup

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 commands
  • bot: Enables your application to join the server as a bot
    • SEND_MESSAGES: Enables your bot to send messages to channels
    • MANAGE_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.

Making Changes

  1. Fork this repo

  2. 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
  3. Make this project your working directory

  4. Install dependencies and compile TypeScript

    $ npm install
  5. Start TypeScript compiler process to recompile on change:

    $ npm run build:watch
  6. In a new terminal session, copy .env.example to .env.development:

    $ cp .env.example .env.development
  7. In .env.development:

  8. 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.

Adding a new command

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.

Adding a new message handler

Run npx plop message-handler to generate boilerplate.

Code Style

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.

License

MIT