Dependency Versions:
This Discord bot was written to merge all the functions of different bots used in the Fragsoc Discord server into one bot that is maintained by Fragsoc members.
- Clone this repository:
$ git clone https://github.com/FragSoc/Esports-Bot-Rewrite.git
- Change into the repo directory:
$ cd Esports-Bot-Rewrite
- Rename the
secrets.template
tosecrets.env
and set all the variables. Be sure to read theCurrent Functions
section below for the Cog you want to enable in case of any special setup instructions:
$ nano secrets.env
- Run docker-compose:
$ docker-compose up
Requirements needed to run:
- Python 3.8
- Pip
- A postgres 11 database
- Clone this repository:
$ git clone https://github.com/FragSoc/Esports-Bot-Rewrite.git
- Change into the repo directory:
$ cd Esports-Bot-Rewrite
- Rename the
secrets.template
tosecrets.env
and set all the variables. Be sure to read theCurrent Functions
section below for the Cog you want to enable in case of any special setup instructions:
$ nano secrets.env
$ source secrets.env
- Change into the bot directory:
$ cd src
- Install all the requirements for python:
pip install -r requirements.txt
- Run the bot:
python3 main.py
The list below describes the different "Cogs" of the bot, their associated commands, and any additional information required to set them up.
Voicemaster
- Aliases:
setvmparent
- Make the given ID a Voicemaster parent voice channel.
- Aliases:
setvmparent
- Get all the Voicemaster parent voice channels in the server.
- Aliases:
removevmparent
- Remove the given ID as a Voicemaster parent voice channel.
- Remove all Voicemaster parents from the server.
- Delete all the Voicemaster child channels in the server.
- Aliases:
lockvm
- Locks the Voicemaster child you're currently in to the number of current members.
- Aliases:
unlockvm
- Unlocks the Voicemaster child you're currently in.
- Aliases:
renamevm
- Renames your current Voicemaster voice channel.
Default Role
- Sets the roles that the server gives to members when they join the server.
- Gets the current default roles set for the server.
- Removes the current default roles for the server.
Log Channel
- Set the log channel to the #'ed channel or given role ID.
- Gets the current log channel value.
- Removes the current log channel value.
Administrator Tools
Adds a few commands useful for admin operations.
- Aliases:
cls, purge, delete
- Clear the specified number of messages from the current text channel.
- Get the current version of the bot.
- List the current number of members in the server.
- Unloads the given cog.
- This command requires your user ID to be defined in the env file under
DEV_IDS
- Loads the given cog.
- This command requires your user ID to be defined in the env file under
DEV_IDS
- Reloads the given cog.
- This command requires your user ID to be defined in the env file under
DEV_IDS
- Sets the permissions for a user in the channels/categories given.
- Requires
administrator
permission in Discord
- Get basic information about a users profile.
- Requires
administrator
permission in Discord
Twitter Integration
Enables forwarding tweets when they are tweeted to a discord channel for specific Twitter accounts.
Requires the ENABLE_TWITTER
variable to be set to TRUE
in order to function.
- Add a Twitter handle to notify when they tweet or quote retweet.
- Remove the given Twitter handle from notifications.
- Aliases:
addtwitterhook, create-hook
- Creates a Discord Webhook bound to the channel the command was executed in, unless a channel is given, and with a default name unless a name is given.
- Aliases:
deltwitterhook, delete-hook
- Deletes the Discord Webhook so that updates are no longer sent to that channel
- Aliases:
accounts, get-all
. - Returns a list of the currently tracked Twitter accounts for the server.
Event Channel Management
Each server can have any number of named event categories, where each category creates a sign-in channel, a general chat, a voice chat and a role for the event. All commands in this cog required the administrator
permission in Discord.
- Creates the text channels, and voice channel for the event. The role given is used to later expose the sign-in channel to members. Upon creation the event is set to
closed
. - See the
open-event
andclose-event
for more information regarding which members can see which channels. - The role created for this event will have the same as the event name, it is not the role given in the command.
- Allows the role given in the
create-event
command to see the sign-in channel, and add reactions to the sign-in message. - The sign-in message grants the role created by the bot for the event.
- Stops any member who is not an administrator from being able to see any of the event channels.
- Deletes all the channels in the category for the event and deletes the role created by the bot for the event.
Twitch Integration
Enables sending notifications to a Discord channel whenever a tracked channel goes live.
Requires the ENABLE_TWITCH
variable to be set to TRUE
in order to function.
Set the TEMP_BEARER_FILE
to anything you like, this will be the file where your bearer token is stored for reuse.
- Create the Certificate Authority (CA) private key:
$ openssl genrsa -des3 -out servercakey.pem
- Create the CA public certificate:
$ openssl req -new -x509 -key servercakey.pem -out root.crt
- Create the server's private key file:
$ openssl genrsa -out server.key
- Create the server's certificate request:
$ openssl req -new -out reqout.txt -key server.key
- Use the CA private key file to sign the server's certificate:
$ openssl x509 -req -in reqout.txt -days 3650 -sha1 -CAcreateserial -CA root.crt -CAkey servercakey.pem -out server.crt
-
Move your
server.crt
andserver.key
files into thesrc
folder. -
Set the environment variable
SSL_CERT_FILE
to the name of yourserver.crt
file and the variableSSL_KEY_FILE
to the name of yourserver.key
file.
- Go to the Twitch Developers site.
- Once logged in, in the top left, go to
Your Console
or this site. - Register a new application using any name and the OAuth Redirect URL of
http://localhost
. - Once created, click
manage
. Copy the string that is inClient ID
and then click theNew Secret
button to generate a newClient Secret
and then copy the string it generates.
In your .env
file the TWITCH_SUB_SECRET
should be a string that is 10-100 characters long and should not be shared anywhere. This is used to authenticate if a message has come from Twitch or if it has been altered along the way.
The TWITCH_CALLBACK
is the URL to your HTTPS server. For testing you can use ngrok
:
- Run
ngrok http 443
and copy thehttps
URL not thehtttp
URL and use that as yourTWITCH_CALLBACK
variable.
- Creates a Discord Webhook bound to the channel given and with the name given, but prefixed with the Twitch Webhook prefix.
- Deletes the given Discord Webhook.
- Adds a Twitch channel to be tracked in the given Webhook.
- If a custom message is given, it must be surrounded by double quotes:
!twitch add <twitch_handle> "custom_message"
- Removes a Twitch channel from being tracked in the current Discord server.
- Shows a list of all the currently tracked Twitch accounts and their custom messages.
- If a hook name is given, only shows the information for the given hook.
- Get a list of the current Discord Webhooks for Twitch notifications.
- Sets the custom message of a Twitch channel. Can be left empty if the custom message is to be removed.
- If a custom message is given, it must be surrounded by double quotes:
!twitch setmessage <twitch_handle> "custom_message"
- Gets the currently set custom message for a Twitch channel.
- If a hook name is given, gets the currently set custom message for the Twitch channel in that Webhook.
- Get a preview of the live notification for the given Twitch channel in the given Webhook.
Role Reaction Menus
Role reaction menus allow admins to create reactable menus that when reacted to grant defined roles to the user.
For devs:
- To enable this function in the bot use the
ENABLE_ROLEREACTIONS
env var and set it toTRUE
. - Making new types of reaction menus is easy - simply extend
DiscordReactableMenus.ReactableMenu
or one of the example menus inDiscordReactableMenus.ExampleMenus
.
- Creates a new role reaction menu with the given roles and their emojis.
- Each option must be a mentioned role followed by the emoji to use as its reaction. There can be up to 25 roles in a single reaction menu.
- The
title
is displayed at the top of the menu, and thedescription
just below. To have either blank leave the quotes empty. - If the
DELETE_ROLE_CREATION
env var is set toTRUE
the command message will be deleted. - Requires
administrator
permission in Discord - An example usage of this command is as such:
!roles make-menu "{title}" "{description}" {@option1 role} {option1 emoji} ... ...
- Adds more role reaction options to the given menu. If there is no menu id given, the latest role reaction menu will be used.
- There can be one or many options added at the same time with this command.
- Each option must be a mentioned role followed by the emoji to use as its reaction. There can be up to 25 roles in a single reaction menu.
- Requires
administrator
permission in Discord - An example usage of this command is as such:
!roles add-option {menu id} {@option role} {option emoji} ... ...
- Removes the role associated with the emoji from the given menu. If there is no menu id given, the latest role reaction menu will be used.
- Requires
administrator
permission in Discord
- Disables a reaction menu. This means that roles will not be given to users when they react to the message. If there is no menu id given, the latest role reaction menu will be used.
- Requires
administrator
permission in Discord
- Enables a reaction menu. This means that users will be able to receive roles from the reaction menu when they react. If there is no menu id given, the latest role reaction menu will be used.
- Requires
administrator
permission in Discord
- Deletes the given role reaction menu. Does not delete any of the roles in the menu, just the message.
- Requires
administrator
permission in Discord
- Shows or Hides all role reaction menu footers, which contain the ID of the role reaction menu for ease of identification.
- Requires
administrator
permission in Discord
Poll Reaction Menus
Poll reaction menus allow users to create polls with up to 25 different options for other users, and themselves, to vote on.
The poll start and end is not time based, but instead controlled by the user that created the poll or administrators.
For devs:
- To enable this function in the bot use the
ENABLE_VOTINGMENUS
env var and set it toTRUE
. - Making new types of reaction menus is easy - simply extend
DiscordReactableMenus.ReactableMenu
or one of the example menus inDiscordReactableMenus.ExampleMenus
.
- Creates a new poll with each emoji having a description.
- Each option must be an emoji and a description, with each one on a new line. There can be up to 25 roles in a single reaction menu.
- If the
DELETE_VOTING_CREATION
env var is set toTRUE
the command message will be deleted. - An example usage of this command is as such:
!votes make-poll {title} {option1 emoji} {option1 description} {option2 emoji} {option2 description} ... ... [up to option 25]
- Aliases:
add, aoption
- Adds another option to the poll with the menu id given.
- Only one option can be added at a time with this command.
- Each option must be an emoji and a description, with each one on a new line. There can be up to 25 roles in a single reaction menu.
- You must be the owner of the poll or be an administrator
- An example usage of this command is as such:
!votes add-option {menu id} {option emoji} {option description}
- Aliases:
remove, roption
- Removes the option from the poll with the menu id given.
- You must be the owner of the poll or be an administrator
- Aliases:
delete, del
- Deletes the poll with the menu id given.
- You must be the owner of the poll or be an administrator
- Aliases:
finish, complete, end
- Deletes the actual poll message and sends a new message with the results of the poll.
- You must be the owner of the poll or be an administrator
- Aliases:
reset, clear, restart
- Removes all the current user-added reactions from the poll with the menu id given.
- You must be the owner of the poll or be an administrator
Music Bot
A basic music bot that functions similarly to the popular 'Hydra Bot'.
Commands that use the prefix of !music
are commands that must be sent in the defined music channel for the server.
The rest of the commands in this cog can be sent anywhere.
Most !music
commands require you to be in the same voice channel as the bot, or if it is not in a channel, for you to be in a voice channel.
Some !music
commands can have this requirement ignored if the user performing the command is an administrator and uses the force
or -f
flag in the command.
To add new songs to the queue, just put the name, YouTube link, or a YouTube playlist into the music channel once set. Also requires you to be in the voice channel with the bot, or if the bot is inactive, in any voice channel.
To enable this cog, use the ENABLE_MUSIC
env var in your secrets.env
file, and set it to TRUE
.
For this cog to work, the GOOGLE_API
env var must also be set, and instructions on how to get an API credential is below:
- Go to the Google Cloud API site.
- Create a new project and name it whatever you want.
- In the dashboard, click the
Enable APIs and Services
and search forYouTube Data API v3
. - Click
Enable
to enable the use of the YouTube API. - Keep going back until at your dashboard, and go to the credentials section on the left.
- Click on
Create Credentials
and thenAPI key
. - Copy the key given. For security, it is recommended that you "restrict key" and only enable
YouTube Data API v3
.
- This sets the channel mentioned to be used as the music channel. All messages into this channel will be considered music requests, and any music commands must be sent in this channel.
- Optional args:
- Using
-c
will clear the entire channel before setting it up as the music channel.
- Using
- Requires
administrator
permission in Discord
- Sends the currently set music channel for the server.
- Requires
administrator
permission in Discord
- This clears the current music channel and resets the preview and queue messages.
- Requires
administrator
permission in Discord
- Unlinks the currently linked music channel from being the music channel. This will not delete the channel or its contents.
- Requires
administrator
permission in Discord
- If the bot has broken and thinks it is still in a Voice Channel, use this command to force it to reset.
- Requires
administrator
permission in Discord
- Aliases:
songqueue, songs, songlist, songslist
- Gets the current list of songs in the queue.
- Aliases:
connect
- Make the bot join the channel.
- If you are an admin you can force it join your voice channel using the
-f
orforce
option.
- Aliases:
leave
- Kicks the bot from the channel.
- If you are an admin you can force it to leave a voice channel with the
-f
orforce
option.
- Aliases:
resume
- Resumes playback of the current song.
- If a song is requested and there is no current song, it is played, otherwise it is added to the queue.
- Pauses the current song.
- Shuffles the current queue of songs.
- Sets the volume of the bot for everyone to the level given.
- Clears the queue entirely, does not stop the current song from playing.
- Skips the current song.
- If a number is given it will also skip to the song at the position given.
- For example, if 'songs to skip' is 4, the next song to play would be song 4 in the queue.
- Removes the song at the given position from the queue.
- Moves the song at position
from position
to positionto position
in the queue.
Pingable Roles
Pingable roles are roles that can be voted in to be created by any user, and that once created have a cooldown tied to how often that role can be pinged.
A user can create a poll where if there are enough votes by the time the poll ends, a role will be created. The length of the poll and the number of votes required are customisable by server admins.
After the poll finishes, a reaction menu gets created, allowing any user to react and receive the role. Initially the role will have the default cooldown of the server, but can be overridden.
- Returns an embed of the current default settings for the server.
- Requires
administrator
permission in Discord
- Resets all settings for this guild to the bot-defined defaults defined in the
.env
file. - Requires
administrator
permission in Discord
- Sets the default poll length to the given time in seconds.
- Polls can have a custom length by specifying it when using the
!pingme create-role
command. - Requires
administrator
permission in Discord
- Sets the number of votes required in a poll for the role to be created.
- Requires
administrator
permission in Discord
- Sets the default ping cooldown for any pingable role created with this cog.
- Roles can have their cooldown altered individually with the
!pingme role-cooldown
command. - Requires
administrator
permission in Discord
- Sets the emoji to be used when creating a poll to vote in.
- Requires
administrator
permission in Discord
- Sets the default emoji to be used in the role reaction menu for the pingable role once it has been created.
- Roles can have their reactable emoji altered individually with the
!pingme role-emoji
command. - Requires
administrator
permission in Discord
- Disables the roles mentioned from being mentioned by non-administrators and disables their reaction menus.
- The roles provided must be pingable roles created with this cog.
- Requires
administrator
permission in Discord
- Enabled the roles mentioned to be mentioned by non-administrators and allows their reaction menus to be reacted to.
- The roles provided must be pingable roles created with this cog.
- Requires
administrator
permission in Discord
- Creates a new poll to create a role if the number of votes has surpassed the server's threshold after the poll length has passed.
- Deletes the mentioned roles from the server.
- The roles provided must be pingable roles created with this cog.
- Requires
administrator
permission in Discord
- Converts the mentioned roles into pingable roles and creates their reaction menus.
- The roles provided cannot be roles that are already pingable roles.
- Requires
administrator
permission in Discord
- Converts the mentioned roles from pingable roles into normal roles and deletes their reaction menus.
- The roles provided must be pingable roles created with this cog.
- Requires
administrator
permission in Discord
- Sets the ping cooldown for a specific role which overrides the server default for that role.
- The role provided must be a pingable role created with this cog.
- Requires
administrator
permission in Discord
- Sets the emoji to use in the reaction menu for the given role.
- The role provided must be a pingable role created with this cog.
- Requires
administrator
permission in Discord