A Discord bot that fetches and displays your upcoming Canvas assignments from the University of Alberta's Canvas LMS directly in Discord.
- π Fetches assignments from all your active Canvas courses
- π Shows only assignments due within the next 3 days
- π Provides direct links to each assignment
- β° Displays formatted due dates and times
- π¨ Clean Discord embed formatting
- β Automatically sorts assignments by due date
- π Automatic daily reminders at 7 AM and 5 PM (Mountain Time)
- π¬ Manual commands - check assignments anytime with
!assignments
- Node.js (v16.9.0 or higher)
- A Discord account and server where you have permission to add bots
- A University of Alberta Canvas account
Create a new folder and add the following files:
index.js
(main bot code)package.json
(dependencies).env
(configuration - create this yourself)
Open a terminal in the project folder and run:
npm install
This will install:
discord.js
- Discord bot frameworkaxios
- HTTP client for Canvas APIdotenv
- Environment variable managementnode-cron
- Task scheduler for automatic reminders
- Log in to canvas.ualberta.ca
- Click on Account (left sidebar) β Settings
- Scroll down to "Approved Integrations"
- Click "+ New Access Token"
- Give it a purpose name (e.g., "Discord Bot")
- Click "Generate Token"
- Copy and save this token immediately - you won't be able to see it again!
- Go to the Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" section in the left sidebar
- Click "Add Bot" and confirm
- Under the bot's username, click "Reset Token" and copy it
- Scroll down to "Privileged Gateway Intents"
- Enable "MESSAGE CONTENT INTENT"
- Click "Save Changes"
- In the Discord Developer Portal, go to OAuth2 β URL Generator
- Select the following scopes:
- β
bot
- β
- Select the following bot permissions:
- β Read Messages/View Channels
- β Send Messages
- β Embed Links
- Copy the generated URL at the bottom
- Open the URL in your browser and select your server
- Click "Authorize"
Create a file named .env
in your project folder with the following content:
# Discord Bot Token (from Discord Developer Portal)
DISCORD_TOKEN=your_discord_bot_token_here
# Canvas API Token (from canvas.ualberta.ca Account Settings)
CANVAS_TOKEN=your_canvas_api_token_here
# Discord Channel ID where automatic reminders will be sent
REMINDER_CHANNEL_ID=your_channel_id_here
Replace the placeholder values with your actual tokens.
.env
file or commit it to version control!
To enable automatic daily reminders, you need to get the Channel ID:
Enable Developer Mode:
- Open Discord and click the gear icon (User Settings)
- Go to Advanced (under "App Settings")
- Turn on Developer Mode
Get the Channel ID:
- Right-click the channel where you want automatic reminders
- Click "Copy Channel ID"
- Paste it into your
.env
file asREMINDER_CHANNEL_ID
Note: If you don't want automatic reminders, you can skip this step or leave REMINDER_CHANNEL_ID
empty. The manual !assignments
command will still work.
Run the bot with:
npm start
You should see:
β
Bot logged in as YourBotName#1234
β° Automatic reminders enabled for channel: 123456789012345678
π
Reminders scheduled for 7:00 AM and 5:00 PM (Mountain Time)
The bot is now online and ready to use!
If you didn't set up REMINDER_CHANNEL_ID
, you'll see:
β
Bot logged in as YourBotName#1234
β οΈ No REMINDER_CHANNEL_ID set. Automatic reminders disabled.
π‘ Add REMINDER_CHANNEL_ID to .env to enable automatic reminders.
The bot supports both automatic and manual modes:
- 7:00 AM Mountain Time - Morning reminder with upcoming assignments
- 5:00 PM Mountain Time - Evening reminder with updated assignments
- Posts automatically to the channel specified in
REMINDER_CHANNEL_ID
- Includes "Automatic Daily Reminder" footer to distinguish from manual requests
In any Discord channel where the bot has access, type:
!assignments
- Fetch and display upcoming assignments on demand!canvas
- Alternative command (same as !assignments)
Both modes show the same information - assignments due within the next 3 days.
When you run the command, the bot will display:
π Assignments Due in Next 3 Days
1. CMPUT 201 Lab 5
Due: Mon, Oct 7, 11:59 PM
Course: CMPUT 201 - Practical Programming Methodology
https://canvas.ualberta.ca/courses/12345/assignments/67890
2. MATH 125 Assignment 3
Due: Wed, Oct 9, 11:59 PM
Course: MATH 125 - Linear Algebra I
https://canvas.ualberta.ca/courses/23456/assignments/78901
Total: 2 assignments
If there are no assignments due:
π Upcoming Assignments
No assignments due in the next 3 days! π
By default, reminders are sent at 7:00 AM and 5:00 PM Mountain Time. To change these times, edit the cron schedules in index.js
around lines 168-180:
// 7 AM MT - Change '0 7' to your desired time
cron.schedule('0 7 * * *', () => {
sendScheduledReminder();
}, {
timezone: 'America/Edmonton'
});
// 5 PM MT (17:00) - Change '0 17' to your desired time
cron.schedule('0 17 * * *', () => {
sendScheduledReminder();
}, {
timezone: 'America/Edmonton'
});
Cron format: minute hour * * *
0 7
= 7:00 AM0 17
= 5:00 PM (17:00)30 9
= 9:30 AM0 12
= 12:00 PM (noon)
Simply update the REMINDER_CHANNEL_ID
in your .env
file with a different channel ID and restart the bot.
Remove or comment out the REMINDER_CHANNEL_ID
line in your .env
file. The manual commands will still work.
By default, the bot shows assignments due within 3 days. To change this, edit line 24 in index.js
:
threeDaysFromNow.setDate(threeDaysFromNow.getDate() + 3); // Change 3 to your preferred number
You can add more command triggers by modifying the message handler around line 195:
if (message.content.toLowerCase() === '!assignments' ||
message.content.toLowerCase() === '!canvas' ||
message.content.toLowerCase() === '!homework') { // Add your custom command
If you're not in Mountain Time, change the timezone in the cron schedules around lines 168-180:
cron.schedule('0 7 * * *', () => {
sendScheduledReminder();
}, {
timezone: 'America/Edmonton' // Change to your timezone
});
Common timezones:
America/Toronto
- Eastern TimeAmerica/New_York
- Eastern TimeAmerica/Chicago
- Central TimeAmerica/Denver
- Mountain TimeAmerica/Los_Angeles
- Pacific TimeAmerica/Vancouver
- Pacific Time
Solution:
- Make sure MESSAGE CONTENT INTENT is enabled in Discord Developer Portal
- Click "Save Changes" after enabling
- Restart the bot
- Wait a few minutes for Discord to update
Solution: You haven't enabled MESSAGE CONTENT INTENT. See step 4 in the Discord Bot setup above.
Solution:
- Verify your Canvas token is correct and hasn't expired
- Test the token manually:
curl -H "Authorization: Bearer YOUR_TOKEN" https://canvas.ualberta.ca/api/v1/courses
- Generate a new token if needed
Solution:
- Check that
DISCORD_TOKEN
in.env
is correct - Make sure the bot process is running (
npm start
) - Verify the bot is still in your server (check member list)
Solution:
- Check that assignments have due dates set in Canvas
- Verify assignments are due within the 3-day window
- Make sure you're enrolled in the courses as a student
Solution:
- Verify
REMINDER_CHANNEL_ID
is set correctly in.env
- Make sure the bot has permission to send messages in that channel
- Check the bot console for error messages at 7 AM or 5 PM
- Verify your server time matches Mountain Time or adjust timezone in code
- Wait until the scheduled time - reminders only send at 7 AM and 5 PM
Solution: Change the timezone in the cron schedules (see Configuration section above)
- Never share your
.env
file - Never commit
.env
to Git (add it to.gitignore
) - Never share your Canvas API token
- Never share your Discord bot token
- Regenerate tokens immediately if they're exposed
- Only run this bot in trusted environments
- Canvas API: Generally allows 3000 requests per hour per token
- This bot makes one request per course, so it should be well within limits
- Avoid running the command excessively to prevent rate limiting
canvas-discord-bot/
βββ index.js # Main bot code
βββ package.json # Dependencies and scripts
βββ .env # Environment variables (create this)
βββ .gitignore # Git ignore file (recommended)
βββ README.md # This file
Create a .gitignore
file with:
node_modules/
.env
*.log
For issues specific to:
- Canvas API: Canvas API Documentation
- Discord.js: Discord.js Guide
- University of Alberta Canvas: Contact UAlberta IT Support
This project is provided as-is for educational purposes. Feel free to modify and use it for your personal needs.
Feel free to fork and improve this bot! Some ideas for enhancements:
- β Daily automatic reminders (implemented!)
- Add reminders for specific assignment deadlines (e.g., 1 hour before)
- Filter by specific courses
- Show assignments due this week
- Add task completion tracking
- Support for multiple users with different Canvas tokens
- Quiz and exam reminders
- Grade notifications
Made with β€οΈ for UAlberta students