Skip to content

mavjav-edu/discordpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mav Jav Education bot

Build Status

Discord server invite PyPI version info Say Thanks!

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.

Features

  1. Simple message-response

    • The code includes templates for how to create commands that the bot recognizes and will respond to.
  2. 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).

  3. 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)

Deploy

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: Windows 10 Logo for Windows, Linux logo for Linux, and macOS Logo 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.

Prerequisites

The list enumerates system (💻) and epistemic (🎓) requirements to getting this bot running.

Run ▶

To actually get this code running, follow these 12 steps:

  1. Clone this repository in VS Code (how?)
git clone https://github.com/mavaddat-javid-education/discordpy.git
  1. Enter the discordpy directory using a shell (how Windows 10 Logo, Linux logo, macOS Logo)

  2. Create a Python virtual environment here called venv

    py -3 -m venv venv
  3. 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
  4. We use tox-travis to automatically install project dependencies in the venv. (What is tox?)

    1. Install tox-travis
    pip install tox-travis
    1. Run tox
    tox
  5. Get an OAuth2 token from Discord (it will be the 'secret' for writeToken.py)

    1. Go to the Discord developers' applications page
    2. Create an application or click the application you created for this bot
    3. Click the 'Bot' tab with puzzle piece Bot' tab on Discord developer's application icon Bot tab
    4. Add a bot to the application (if a bot is not already in the application) Bot' page on Discord developer's application Bot' tab on Discord developer's application
    5. Click 'Copy' under 'TOKEN' Copy the token
  6. Write your token into the keyring or create your Fernet token and key by pasting the auth token into Python shell running writeToken.py script3

  7. Go to the OAuth2 tab OAuth2 tab

  8. Check the box for bot role check the box for the bot role

  9. Check boxes for the permissions Send Messages and Read Message History to generate a URL inivitation Generate invitation URL

  10. Invite your bot and accept the invite.

    1. 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 Invite your bot
    2. Paste the invite URL in your browser's address bar and press enter to visit the link.
  11. Run the discordbot on your computer inside VS Code (how?)

That's it! The bot now should be running on your server. Discord bot triumphant

TODO

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, local computer, multithreading, asynchronous
  • Security principles motivating encryption, least privilege
  • SVG recording of bash and PowerShell 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
    • 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
  • 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. Invite button crossed out

[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.

About

A Discord.gg bot in Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages