Mav Jav Education Discord server bot.
This project uses Rapptz/discord.py to implement a Discord server bot. This bot is meant to be used as an educational tool to teach Python programming to kids🦸🏼♀️🦸🏼♂️🦸🏽♀️🦸🏽♂️ grades 7-121. The bot is occassionally deployed on Mav Jav Education Discord server for testing.
-
Simple message-response
- The code includes templates for how to create commands that the bot recognizes and will respond to.
-
A timer function to remind the chat of a message after a specified time. This is achieved using multithreaded function calls to enable asynchronous input/output, allowing our bot to do work in the background without freezing up (being unresponsive to further commands until it finishes the work).
-
Subcommands. This demonstrates multiple variations on a central command (e.g.,
!playMusic
,!playSong
,!playArtist
,!playMovie
,!playYouTube
all have the root!play
followed by some target)
How do we get it running? You can assemble and deploy this bot using your own computer2 to get an idea of how to create your own Python-powered bot on your Discord servers.
To try this, you will need some set up. If necessary, platform-specific instructions are given as links by major operating systems' icons: for Windows,
for Linux, and
for macOS. At each step, please judge for yourself whether you're missing knowledge to complete that step. If you think you need to learn, please click the icon that matches your operating system to learn more about that step.
The list enumerates system (💻) and epistemic (🎓) requirements to getting this bot running.
- 🎓 Understand how to run Python in VS Code,
- 🎓 Understand Python virtualenv,
- 🎓 Shell familiarity (
,
,
),
- 💻
install discord.py module,
- 💻
install VS Code,
- 💻
Git,
- 💻
Python,
- 💻
Fernet cryptography module
To actually get this code running, follow these 12 steps:
- Clone this repository in VS Code (how?)
git clone https://github.com/mavaddat-javid-education/discordpy.git
-
Create a Python virtual environment here called
venv
py -3 -m venv venv
-
Activate the Python virtual environment
venv
(how macOS/Linux, how Windows),source ./venv/Scripts/activate
or
.\venv\Scripts\Activate.ps1
or
.\venv\Scripts\activate.bat
-
We use
tox-travis
to automatically install project dependencies in thevenv
. (What istox
?)- Install
tox-travis
pip install tox-travis
- Run
tox
tox
- Install
-
Get an OAuth2 token from Discord (it will be the 'secret' for
writeToken.py
)- Go to the Discord developers' applications page
- Create an application or click the application you created for this bot
- Click the 'Bot' tab with puzzle piece
icon
- Add a bot to the application (if a bot is not already in the application)
- Click 'Copy' under 'TOKEN'
-
Write your token into the keyring or create your Fernet
token
andkey
by pasting the auth token into Python shell running writeToken.py script3 -
Check boxes for the permissions
Send Messages
andRead Message History
to generate a URL inivitation -
Invite your bot and accept the invite.
- Invite the bot to join your server by copying the URL generated by the permissions calculating tool in step 8. The URL will have the format
https://discord.com/api/oauth2/authorize?client_id=
{CLIENT_ID}&permissions=
{PERMISSIONS_NUMBER}&scope=bot
- Paste the invite URL in your browser's address bar and press enter to visit the link.
- Invite the bot to join your server by copying the URL generated by the permissions calculating tool in step 8. The URL will have the format
-
Run the discordbot on your computer inside VS Code (how?)
That's it! The bot now should be running on your server.
This repository is a work-in-progress. I still need to add the following to the README.
-
Explain prerequisites to start -
Instructions on how to deploy bot -
Explain features of the bot - Explain how to add your own features
- Explain remote
server
, localcomputer
, multithreading, asynchronous - Security principles motivating encryption, least privilege
- SVG recording of
bash
andPowerShell
demonstrating each step - Add functionality of Discord.py
- Re-invite students who leave sever
- Re-assign roles
- Connect to
MySQL db
- Welcome message
- Moderation
- Auto role
- Twitch, YouTube, Reddit, Mixer alerts
- Pokémon catching
- Accept donations
- Meme maker
- Mini games
- Quiz games
- Music trivia
- Gaming trivia
- Tidbits knowledge test
- Asks channel a small question about topic
- Keeps track of points
- Quiz games
- Member levels and XP
- Role rewards
- Play music/videos
- YouTube • Tracks, Playlists, Searches, Links, Streams
- SoundCloud • Tracks, Playlists, Searches, Links
- Spotify • Links to tracks, Playlists
- Twitch • Links to streams
- Mixer • Links to streams
- BandCamp • Links to tracks and albums
- Pull stats from https://tracker.gg/
- Apex Legends
- CSGO
- Division 2
- Overwatch
- Splitgate
- Fortnite Power Rankings
- Re-invite students who leave sever
- Multilingual translations
[1] To use Discord, students must be ≥ 13, the age of digital consent in Canada and USA. If you are not thirteen years old (13) yet, please seek your guardian's or parents' assistance. Your guardian or parents can sign up for Discord and help you get your bot going.↩
[2] The purpose of this bot is to motivate kids to learn to code.
My bot is not a "public bot" (unlike top.gg bots you might know), so it cannot be added by invitation. ↩
[3] This step will use jaraco/keyring to store and retrieve the key securely from the system credential manager or keychain. You will store the token once and keyring
retrieves the token securely from then on.
Optionally, you can encrypt the OAuth2 token so that it can be securely stored as a file locally. In the latter case, the writeToken.py
script also attempts to append the .gitignore
manifest so that we do not upload the token
or key
file onto a repository. The file key
must be kept secret, but token
is encrypted safe even if acquired by an adversary. That is, anyone who has the key can decrypt the token, but having the encrypted token will be useless (that is the purpose of encryption).
Notice that keeping the key in the same location as the encrypted file (in the same file system) is a security risk, but the purpose of this option to demonstrate the method of file encryption.↩