This project is a Discord bot designed to interact with Google Calendar, allowing users to fetch and create calendar events directly from a Discord server. The bot leverages Discord's slash commands for ease of use and integrates seamlessly with the Google Calendar API for robust event management.
- Google Calendar Authentication: Securely authenticate with Google Calendar using OAuth 2.0. Credentials are stored and refreshed as needed.
- Event Retrieval: Fetch and display upcoming events from the primary Google Calendar in a well-formatted table.
- Event Creation: Authorized users can create new calendar events by specifying the event summary, description, start time, and end time.
- Role-Based Access Control: Ensure only users with specific roles can create events, maintaining control and security within the server.
- Pacific Time Zone Handling: Events are handled in the 'America/Los_Angeles' time zone for accurate scheduling.
This bot facilitates efficient event management for communities using Discord, bridging the gap between real-time communication and calendar scheduling.
- Python 3.7 or higher
- Discord.py library
- Google API Python Client
- Tabulate library
- OAuth2Client library
-
Clone the repository:
git clone https://github.com/codeiaks/MC-calendar-bot.git cd MC-calendar-bot -
Install dependencies:
Create and activate a virtual environment (optional):
python -m venv venv source venv/bin/activate # On Windows, use 'venv\Scripts\activate'
Install the required Python packages:
pip install -r requirements.txt
-
Create and configure your Google API credentials:
- Go to the Google Cloud Console
- Create a new project
- Enable the Google Calendar API
- Create OAuth 2.0 credentials
- Download the
credentials.jsonfile and place it in the root directory of your project
-
Obtain Discord bot token:
- Create a new Discord bot and obtain the token. Follow the instructions on the Discord Developer Portal.
- Replace
TOKENwith your bot token - Replace
ALLOWED_ROLE_IDwith the role ID that is allowed to create events
-
Run the bot:
python mc-calendar-bot.py
-
Authenticate Google Calendar:
The first time you run the bot, you will need to authenticate with Google Calendar. Follow the instructions in the console to complete the authentication process. The credentials will be saved in
token.json. -
Commands:
- /mcevent: Fetch and display upcoming events from the primary Google Calendar.
- /createmcevent [summary] [description] [start_time] [end_time]: Create a new event in the Google Calendar (requires the user to have the specified role).
-
Fetch upcoming events:
/mcevent
-
Create a new event (if you have the required role):
/createmcevent "Meeting" "Discuss project updates" "2024-07-15T10:00" "2024-07-15T11:00"
- Feel free to contribute to this project! Fork the repository and submit a pull request with your changes.