EddieBot
Discord bot for Eddie Jaoude's Discord server
→ Features of EddieBot
-
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, to display some statistics of the server (e.g total number of users and messages)
-
Firebase (Firestore) integration, allowing people to easily add commands and persist data
-
GitHub Actions deploys mainline branch to Azure
→ Requirements
- [optional] Docker and Docker-Compose
- 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] Github token that you can get from here
- [optional] GCP account to deploy to (using GitHub Actions)
→ How to run EddieBot locally:
1. Set Environment Variables
- Copy
.env.example
to.env
. - Generate the "Service Account" from Firebase Settings > Cloud Messaging.
- Download Service Account JSON file from this same screen.
- Open
.env
and fill empty strings with matching credentials from the JSON file.
2. To start the application
-
[optional] To run with Docker ensure you have the latest version and Docker Compose installed and run
docker-compose up
-
To run locally
- To setup:
npm run setup
- To start:
npm run start:local
- To setup:
→ Useful Commands
-
View Logs
docker-compose logs --tail=all -f eddiebot-nodejs
-
Use NodeJS instance CLI
docker-compose exec eddiebot-nodejs /bin/bash
Standardized Code Formating
- Before Commit
- lint for errors:
npm run lint
- fix any errors:
npm run lint:fix
- lint for errors:
Using Commitizen for commits
git add <your files>
npm run commit
→ Logging
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');
Discord Gateway Intents
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.
Example adding ban capabilities to moderators:
- 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.
How to add a new command to the bot
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, string], embed: MessageEmbed, message: Message): Promise<MessageEmbed>
The arg parameter contains the arguments given to the command in a string. The arg parameter is a tuple of two
string
s where,arg[0]
is the command name andarg[1]
is the string of command arguments. 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';
Database
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
Socials
Join our discord community here