Table of Contents:
- VSCode / Intellij WebStorm
- Nodejs LTS (Please check package.json for the latest supported Node version)
- PnPM package manager
Note: You DO NOT need docker to run the bot locally.
pnpm icp .env.example .envcopy .env.example .env # pwsh-
Populate fields in the
.envfile.- Sign up on Keybase!
- Ask Sirrele or Pratik for an invite to the GitFitCode Team in Keybase.
- Upon receiving the invite, navigate to the Files section in Keybase.
- Inside Files, look for team -> gitfitcode -> discord bot secrets -> autobot ->
.env. - Download or copy contents into your local
.envfile.
-
Get access to the Digital Junkyard development server on Discord.
pnpm dev # the bot is online in the Digital Junkyard discord serverWhen committing code to the repo, please follow the commit message guidelines/patterns set here and here.
-
Add command constants in
src/utils/constants.tsfile.// Info command constants export const COMMAND_INFO = { COMMAND_NAME: 'info', COMMAND_DESCRIPTION: 'Displays info about yourself and the server.', };
-
Create a new
.tsfile insrc/commandsdirectory. -
Name it same as the slash command (e.g.
Info.ts). -
Follow the example format below to create a new slash command:
/** * Slash command that replies with the information of the server and the user who * triggered the command. * * To trigger, type `/info` in the discord server. */ import { CommandInteraction, Client } from 'discord.js'; import { version } from '../../package.json'; import { COMMAND_INFO } from '../utils'; import { SlashCommand } from '../Command'; async function executeRun(interaction: CommandInteraction) { const content = `\`Your username\`: ${interaction.user.username} \`Your ID\`: ${interaction.user.id} \`Server name\`: ${interaction.guild?.name} \`Total members\`: ${interaction.guild?.memberCount} \`${interaction.client.user.username} version\`: ${version}`; await interaction.followUp({ ephemeral: true, content }); } const Info: SlashCommand = { name: COMMAND_INFO.COMMAND_NAME, description: COMMAND_INFO.COMMAND_DESCRIPTION, run: async (_client: Client, interaction: CommandInteraction) => { await executeRun(interaction); }, }; export default Info;
-
Update the code for the required logic.
-
Import the command in
src/Commands.tsfile to register the command on discord.import Info from './commands/Info'; const Commands: SlashCommand[] = [ //... Info, //... ];
-
Run the bot:
pnpm dev
Your newly added slash commands are now ready to be used on discord!
-
Create a new
.tsfile insrc/listenersdirectory. -
Name it according to the event you want to listen to from here (e.g.
ready.ts). -
Follow the example below to create a new event listener:
import { ActivityType, Client } from 'discord.js'; import Commands from '../Commands'; export default (client: Client): void => { client.on('ready', async () => { if (!client.user || !client.application) { return; } console.log(`${client.user.username} is online`); }); };
-
Register the listener in
src/Bot.tsfile:function start () { ... ready(client); ... }
-
Run the bot:
pnpm dev
Note: If you're having issues listening to events, ensure the intents are accurately provided in src/Bot.ts file.
-
Ensure you've followed every step in Setting up the project step.
-
Install Docker
- Docker Engine (if you're on a *nix system)
- Docker Desktop (Windows/macOS)
-
Build image:
docker build --tag gitfitbot . -
Run the bot:
docker run --detach --name gitfitbot-container --env-file ./.env gitfitbot
-
Stop/Restart the bot
- List all docker processes:
docker ps
- Stop the bot's container:
docker stop <CONTAINER ID>
- Restart the bot's container:
docker restart <CONTAINER ID>
- List all docker processes: