This repository contains the code for the CodeSupport Discord Bot. The project is written in TypeScript using the Discord.js module for interaction with the Discord API.
- TypeScript
- Mocha
- TS-Mocha
- Sinon
- Chai
- ESLint
- TypeScript ESLint Plugin
- TypeScript ESLint Parser
- CodeSupport's ESLint Config
- NYC
- TS-Node
Notes:
- We have excluded @types packages from this list.
- Although TypeScript is listed as a development dependency, it is needed to build the source code.
- Navigate into the repository on your computer and run
npm i
- Build the source code with
npm run build
- Start the Discord bot with
npm start
- You will need to supply the
DISCORD_TOKEN
environment variable
- You will need to supply the
If you would like to use a .env
file for storing your environment variables please create it in the root of the project.
- All source code lives inside
src/
- All tests live inside
test/
- Any static assets (i.e. images) live inside
assets/
- Commands live in
src/commands/
- Event handlers live in
src/event/handlers
Please name files (which aren't interfaces) with their type in, for example RuleCommand
and RuleCommandTest
. This helps make the file names more readable in your editor. Do not add a prefix or suffix of "I" or "Interface" to interfaces.
To create a command, create a new file in src/commands
named <CommandName>Command.ts
. Commands should extend the Command
abstract and super
the command name, the description and any command options (if applicable). When a command is run, it triggers the run
method. This method has two parameters:
message
- The Discord Message objectargs
- An optional array of strings that the user sends along with the command
class ExampleCommand extends Command {
constructor() {
super(
"example",
"an example command"
);
}
async run(message: Message): Promise<void> {
await message.channel.send("Hello!");
}
}
To create an event handler, create a new file in src/event/handlers
named <HandlerName>Handler.ts
. Event handlers should extend the EventHandler
abstract and super
the event constant they are triggered by. When an event handler is handled, it triggers the handle
method. This method accepts any parameters that the event requires. Do not name event handlers after the event they handle, but what their functionality is (for example, AutomaticMemberRoleHandler
not GuildMemberAddHandler
.
class ExampleHandler extends EventHandler {
constructor() {
super(Constants.Events.MESSAGE_CREATE);
}
async handle(message: Message): Promise<void> {
await message.channel.send("Hello!");
}
}
We are using Mocha with Sinon and Chai for our tests. All code should be tested, if you are unsure of how to test your code ask LamboCreeper#6510 on Discord.
- To start the Discord bot use
npm start
- To build the source code use
npm run build
- To start the bot in developer mode (auto-reload + run)
npm run dev
- To test the code use
npm test
- To lint the code use
npm run lint
- To get coverage stats use
npm run coverage
Any Questions? Feel free to mention @LamboCreeper#6510 in the CodeSupport Discord.