Skip to content

SayakoHazuki/SPYC-STEM-Discord.py-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPYC STEM Discord Bot

Refer to this guide to set-up a Discord bot on repl.it 24/7

Note: This repository is a version that includes the $assignments command, which is a little bit complicated. You are recommended to learn python from websites like W3schools first if you are not familiar with this programming language.

Commands:

$timetable [Day] [Class]

Get school timetable

Parameters

  • Day [Optional]
    • Day of cycle / 'today' / 'tomorrow'
      Default: Day of cycle of today
  • Class [Optional]
    • Your class (e.g. 1A)
      Default: class in config.json

Examples

$timetable today 1A
$timetable H 3A

$assignments

Get assignment list

Set-up

Below is a guide for authorzing the bot to access your assignment list

This is not required if you are using the version without the $assignments command

Getting started

You will need the following items before setting up the bot.

  • a Discord application with a bot (Refer to this guide)
    • If you are hosting on repl.it:
      Store the token as an environment variable (You may refer to the guide)
    • If you are using a private host:
      store the token in ./secrets.json
  • a Google API OAuth2 Token (stored as ./credentials.json)
    (You may follow the instructions below to get the token)

Downloading the files

You may clone this repository onto your device, or, if you are using repl.it, import this repository.

Google API OAuth2 Token:

We need a Google API OAuth2 Token to authorize the bot to read our courses and assignments on Google Classroom. Here's how to get the token:

  1. Visit Google Cloud Platform and sign in using your personal account (not your school account)

    • Only education accounts aged 18 or above / perseonal accounts aged 13 or above can access to this service
  2. Create a new project with the type of web application

  3. In the Libraries tab (under API & Services) search for Google Classroom API and enable it

  4. In the Credentials tab (just below the Libraries tab), press 'Create Credentials' and choose OAuth client ID

  5. Set application type to 'web application'. Under the 'Authorized redirect URIs field,

    • add http://localhost:59821/ if you are using your device to host
    • add https://<repl_name>.<your_replit_username>.repl.co:59821 if you are using repl.it to host
  6. Press Create and wait for a pop-up menu which says OAuth client created. In the menu press DOWNLOAD JSON

  7. Move the downloaded file to your working directory and rename it as credentials.json

  8. Open a new command prompt/terminal

    • If you are using repl.it:
      • Press Ctrl+Shift+P on repl.it (Windows/Linux)
      • Press Cmd+Shift+P on repl.it (Mac)
    • If you are not using repl.it:
      • Press Windows+R, type cmd and press OK. (Windows)
      • Open the Terminal application (Mac/Linux)
  9. cd to the directory containing bot.py

    cd path/to/the/folder/containing/the/files
  10. run the python file once

    python3 ./bot.py
  11. A browser window / tab will pop up. Sign in and authorize using the school account (pycXXXXX@school.pyc.edu.hk)

    Seeing an error that says 'redirect_uri_mismatch'?

    Seeing this error means that the redirect uri does not match any uri you added into the 'Authorized Redirect URIs' section in step 5.

    • What should I do if I see this error?
      • Go to the console in repl.it / the command prompt or terminal you opened in step 10.
      • Copy the link in the console
      • Add the link to 'Authorized Redirect URIs' (Refer to Step 5)
  12. Once the authorization is completed, you may close the browser window. The $assignments command should now work.

Dependencies

Skip this part if you're using repl.it to host as repl.it automatically install dependencies.

Python:

Python 3.9 or above (recommended: latest stable version)

Python packages:

google-api-python-client
google-auth-httplib2
google-auth-oauthlib
discord.py

Installing python packages

tl;dr

pip install package_name
# replace package_name with the name of the package

Packages can be installed with the The Python Package Index (PyPI). Click here for a complete tutorial on how to install packages.

Starting the bot

To start the bot, simply run the following command:

python3 ./bot.py

Hey! My bot doesn't work!

There are a lot of reasons for the bot to not work, we cannot list out every possible reasons and the solutions. However, the following are a few things you may try.

  • Check if Python is installed correctly
  • Check the version of Python by using the following command:
    python3 --version
    # The version should be at least 3.9.x for the bot to run without errors
  • Check if the dependencies are installed
  • Check if you have completed all the steps above to set-up the bot

Still doesn't work?

You may contact us through Discord, or open an issue with detailed information (e.g. the errors you received, the Operating System, the host service you're using)

Want to learn more?

There are a lot of resources online to learn! Here are a few resources for you to discover more about coding Discord Bots in Python

Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages