Discord bot using Stargate
Creating Commands
To create a command, you will need to work in the /src/commands
directory.
NO commands should go directly in the /src/commands
directory. All commands should go within a nested category folder, such as /src/commands/general
.
Interface
All commands take a standard structure, which is defined in /src/interfaces/CommandInterface.ts
. This allows TypeScript to apply type checking to ensure our commands have the same, consistent structure.
The interface is as follows:
{
name: string;
description: string;
parameters?: string[];
command: (message: Message, config?: BotConfigInterface) => Promise<void>;
}
-
name
is the name of the command, used by a user to call it. -
description
is a short explanation of what the command does. This is displayed in thehelp
command when a user queries your specific command. -
parameters
is an optional property, which lists the parameters the command expects. This is an array of strings, where each string represents a single parameter. Parameter strings should take the format\
<parameter name>\` (optional|required) - description`. -
command
is the command function. As defined in the interface, the command function takes one or two parameters. The first,message
, is the Discord message object which is required. The second is the bot config object, which is optional. When you write the command function, note that all commands are asyncronous and should use theasync
keyword.
Loading Your Command
Commands are manually loaded in to the bot. Once your command is written, you can import the command to the /src/commands/CommandList.ts
file. Add the command to the array and the bot will be able to load it.
Example Command
Here is an example of a new command file. This command would go in src/commands/general/example.ts
.
import { CommandInterface } from "../../interfaces/CommandInterface";
export const example: CommandInterface = {
name: "example",
description: "This is an example command",
parameters: ["`<exampleParam> (required) - does example stuff"],
command: async (message) => {
console.log("Command logic goes here!");
},
};
Then, in the src/commands/CommandList.ts
file:
import { CommandInterface } from "../interfaces/CommandInterface";
// all the other command imports are here...
import { example } from "./general/example";
export const CommandList: CommandInterface[] = [
// all the other command variables are in this array
example,
];
Commits
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
The commit message should be structured as follows:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Examples
-
Basic
docs: correct spelling of CHANGELOG
-
Basic with scope
feat(lang): add polish language
More information can be found https://www.conventionalcommits.org/en/v1.0.0/#examples
Notes
Husky should check your commit messages, if these error the commit will not be made.
Labels
To facilitate the community in finding ways to contribute that match their experiences and skillsets, we have developed a comprehensive system for labelling issues and PRs. This is an introduction to this standard labelling scheme.
Labels consist of three fields, viz. name, description and color. Label names should have a consistent format to aid both filtering within the github UI as well as scanning visually through the list. The following format is the most suited to this task (where ⎵ denotes a single space):
<emoji>⎵<category>:⎵<name>
Using the label convention from https://opensource.creativecommons.org/contributing-code/repo-labels/
Usage
Using the library xavierchow/github-label-template to export/import labels with the file labels.json
To add a new label, update the labels.json
file and the GitHub Action will do the rest.
1
2
3
4
5
6
7
8
9
10
[
{
"name": "good first issue",
"color": "7f0799"
},
{
"name": "help wanted",
"color": "7f0799"
}
]
Docker
Run from GitHub Registry
docker run -p 3000:3000 --name stargatebot -d ghcr.io/eddiejaoude/stargate:latest
Build locally
docker build -t eddiejaoude/stargate .
Run from local build
docker run -p 3000:3000 --name stargatebot -d eddiejaoude/stargate
Logs
To see the logs of your container
-
docker ps
-
docker logs <container-id>