Discord bot for Eddie Jaoude's Discord server
-
Set/Get user bio with description and social links
-
Timezone, listens for messages that contain 1:30pm UTC and replies with common timezones translation
-
Code of Conduct
-
Daily standup message consistently formatted
-
Help showing a list of available commands
-
Members role rewards
-
Gets tips of resources on a given subject
-
Server status
-
Firebase (Firestore) integration, allowing people to easily add commands and persist data
-
GitHub Actions deploys mainline branch to Azure
-
node v10+ installed
-
discord token. To get one follow these instructions
-
general channel ID of your discord server, read the instructions on one of these links to get yours:
-
ID of your discord server, to get your server ID follow these steps:
- First make sure you have Developer Mode enabled on your Discord by visiting your Discord settings and going to Appearance
- Right click on the server icon on the left hand sidebar then click on "Copy ID"
-
firebase key for the project, check these docs to get your key
-
[optional] GCP account to deploy to (using GitHub Actions)
- Clone the project or your fork (if you plan to make changes use your fork)
- Install dependencies by running the command
npm install
DISCORD_TOKEN=<GET YOUR DISCORD TOKEN> GENERAL_CHANNEL_ID=<GET YOUR GENERAL CHANNEL ID> DISCORD_SERVER_ID=<YOUR SERVER_ID> DISCORD_BOT_CHANNEL_ID=<ID> COMMAND_PREFIX=<PREFIX> FIREBASE_KEY=<FIREBASE_KEY> npm run start:local
or you can the envars in a file envars.tmp.sh
and run the command source envars.tmp.sh && npm run start:local
Example envars.tmp.sh
file
export DISCORD_TOKEN=<DISCORD_TOKEN>
export COMMAND_PREFIX='^'
export DISCORD_SERVER_ID=<DISCORD_SERVER_ID>
export DISCORD_BOT_CHANNEL_ID=<DISCORD_BOT_CHANNEL_ID>
export FIREBASE_KEY=<FIREBASE_KEY>
set DISCORD_TOKEN=<GET YOUR DISCORD TOKEN>
set GENERAL_CHANNEL_ID=<GET YOUR GENERAL CHANNEL ID>
set DISCORD_SERVER_ID=<YOUR SERVER_ID>
set DISCORD_BOT_CHANNEL_ID=<ID>
set COMMAND_PREFIX=<PREFIX>
npm run start:local
Note
FIREBASE_KEY
is the firebase service key and expected key structure is json string that needs to be valid json with single quotes around the whole string and the field names/values need double quotes. An example below:
export FIREBASE_KEY='{"type": "service_account","project_id": ... }'
Logging will happen to the console as well as to the Discord bot
channel.
- Include the logger object...
import { log } from './logger';
- Usage
log.info('Message', 'Details');
or
log.warn('Message', 'Details');
or
log.error('Message', 'Details');
or
log.fatal('Message', 'Details');
If you want the bot to receive a new type of event, you might need to add the required intent in client.ts
to receive that event. Have a look at discord.js docs for the list of intents.
- Add the
GUILD_BANS
intent inclient.ts
:
export const client = new Client({
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
ws: { intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'GUILD_BANS', PrivilegedIntents.GUILD_MEMBERS] }
});
- Add an event handler function for the events you want in
index.ts
:
client.on('guildBanAdd', guild => guildBanAdd(guild));
Note: We are using the GUILD_MEMBERS
privileged intent to receive the guildMemberAdd
event. To know more about Privileged Intents check the official docs.
All the commands are located in the folder src/commandHandlers
so that each command has its own file. They are then executed in src/commands.ts
when a user types a command with the configured command prefix in config.ts.
To create a new command, follow these steps:
-
Create a new file on the
/commandHandlers
folder with the name of the new command. Note: If you need to, use camel case for the file name, likecodeOfConduct.ts
-
On this file you must export a function and three variables:
command
- the function that executes the command. The signature of this function is the following:
(arg: string, embed: MessageEmbed, message: Message): Promise<MessageEmbed>
The arg parameter contains the arguments given to the command in a string. The embed parameter is a MessageEmbed instance, and it represents the message that is returned by the bot, in response to the user. The command should return this parameter or a new instance with an appropriate message to the user. The message parameter is a Message instance that represents the message inputted by the user to execute a given command.
description
- a string with a more detailed description of the command. Used for example by the help commandtriggers
- a string array with the values that trigger this command. If the user types the configured command prefix followed by one of these values, the command should be executedusage
- a string explaining how the command is used (e.g. specifying the number of arguments and their separator)
-
After creating that file, you have to import it and add it to the exported list of commands on the index.ts file located in this folder. Here is an example of adding the
standup
command:
import * as codeOfConduct from './codeOfConduct';
import * as help from './help';
+ import * as standup from './standup';
import * as stats from './stats';
- export default [codeOfConduct, help, stats];
+ export default [codeOfConduct, help, standup, stats];
export { fallback } from './fallback';
Using Firestore from Firebase.
Source
classDiagram
User -- Bio : Nested
User: bio (object)
User: avatar (string)
User: joinedAt (date)
User: updatedAt (date)
User: username (string)
Bio: description
Bio: twitter
Bio: github
Bio: youtube
Bio: linkedin
If you are having trouble creating a new command, here is an example. Feel free to create an issue or make a PR with a new command π. Please see our Contributing file first, before making new commits or opening a PR. We appreciate it β€οΈ!
Join our discord community here
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!