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.
Get school timetable
- Day [Optional]
- Day of cycle / 'today' / 'tomorrow'
Default: Day of cycle of today
- Day of cycle / 'today' / 'tomorrow'
- Class [Optional]
- Your class (e.g. 1A)
Default: class in config.json
- Your class (e.g. 1A)
$timetable today 1A
$timetable H 3A
Get assignment list
This is not required if you are using the version without the
$assignments
command
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
- If you are hosting on repl.it:
- a Google API OAuth2 Token (stored as
./credentials.json
)
(You may follow the instructions below to get the token)
You may clone this repository onto your device, or, if you are using repl.it, import this repository.
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:
-
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
-
Create a new project with the type of web application
-
In the Libraries tab (under API & Services) search for Google Classroom API and enable it
-
In the Credentials tab (just below the Libraries tab), press 'Create Credentials' and choose OAuth client ID
-
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
- add
-
Press Create and wait for a pop-up menu which says OAuth client created. In the menu press DOWNLOAD JSON
-
Move the downloaded file to your working directory and rename it as
credentials.json
-
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)
- Press Windows+R, type
- If you are using repl.it:
-
cd
to the directory containingbot.py
cd path/to/the/folder/containing/the/files
-
run the python file once
python3 ./bot.py
-
A browser window / tab will pop up. Sign in and authorize using the school account (pycXXXXX@school.pyc.edu.hk)
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)
- What should I do if I see this error?
-
Once the authorization is completed, you may close the browser window. The
$assignments
command should now work.
Skip this part if you're using repl.it to host as repl.it automatically install dependencies.
Python 3.9 or above (recommended: latest stable version)
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
discord.py
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.
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
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)
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
- Discord.py's documentation
- Python's documentation
- Beginner's Guide to Python
- W3schools Python Tutorial
Happy coding!