# 3/30 Discord Bot & Google Drive API ###### tags: `experience_sharing` `electrical_system` `NTURT` ##### Author: @KuanChen # Discord Bot integrated with Google Drive API ## Discord Bot ![](https://i.imgur.com/rl3nyVm.png) Discord is a popular communication platform that provides a convenient and efficient way for users to send messages, share files, and participate in voice and video calls. NTU Racing also use Discord to communicate between groups and between individuals, but we found out that type some announcements or notification by hand really takes a lot of time and therefore not very efficient. So we decide to start use the Discord Bot to help us deal with those tasks that we don't want to finish by ourselves. ### What function do we want the Discord Bot to have? >* Remind team members to attend the meeting on time. >* Notification of the Gantt progress. >* Read the files from the NTU Racing. Google Drive. >* G-Mail Inbox Notification. >* Greeting messages. >* Provide the several Command funtions. >* Play music. >* Tell some Jokes. ## Why use Discord.py & Google Drive API ? According to the requirement list above, we need to make use of Google Drive API & Discord.py together when programming by Python. Following are the reasons: * Python is a Programming langrage that is easier for people to understand. * There are lots of information & tutorials that we can obtain on the Internet. * We can make use of Discord.py to make the developement of Discord Bot more convenient. * Google provide the "Google Drive API" to access the file in Google Drive by using Python Coding. * Google API and Discord Bot are both available for Python. ## Discord.py ![](https://i.imgur.com/lgdYVUt.png) Discord.py is a Python wrapper for the Discord API that allows developers to create custom bots to automate tasks and enhance the user experience. ## Google Drive API for Python ![](https://i.imgur.com/MoghUfO.png) Google Drive API allows us to create apps that leverage Google Drive cloud storage. You can develop applications that integrate with Drive, and create robust functionality in your application using the Drive API. We can use the Drive API to: * Download files from Drive and upload files to Drive. * Search for files and folders stored in Drive. * Let users share files, folders, and drives to collaborate on content. * Combine with the Google Picker API to search all files in Drive, then return the file name, URL, last modified date, and user. * Create third-party shortcuts that are external links to data stored outside of Drive, in a different datastore or cloud storage system. etc. ## Prerequisites Before begin, make sure you have the following prerequisites installed: 1. Python 3.10.7 or greater 2. Discord.py library >pip install discord.py 4. Google API client library >pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client 5. A Google Cloud project. 6. A Google Service account 7. Google account with Google Drive enabled. 8. Create a new Discord server and a new Discord bot account with appropriate permissions. ## Step 1: Create a Discord Bot: We can create a Discord Bot using the Discord Developer Portal. Follow the instructions provided to create a new application, add a bot to it, and get the bot's token. >https://discord.com/developers/docs/intro ## Step 2: Authorize the Bot to Access Your Discord Server: Once we have created a Discord Bot, we will need to invite it to our Discord Server. To do this, generate an invite link for our bot and authorize it to access our server. ## Step 3: Set up the Google Drive API: To access our Google Drive files, we will need to set up the Google Drive API. We can follow the instructions provided by Google to set up a project and enable the Google Drive API. ## Step 4: Create a Google Service Account: After setting up the Google Drive API, we will need to create a service account to access the files on your Google Drive. Follow the instructions provided by Google to create a new service account and download the key file. ## Step 5: Install Required Libraries: Install the required libraries to your development environment. You will need the Discord.py and Google API Python libraries. ## Step 6: Write the Code Write the code to connect to the Discord Server and access the Google Drive files using the Google Drive API. We can use the Discord.py library to connect to the Discord Server, and the Google API Python library to access the Google Drive files. We will need to authenticate the service account using the JSON key file, and use the Google Drive API to retrieve the Doc from our Google Drive. ## References : * https://www.freecodecamp.org/news/create-a-discord-bot-with-python/ * https://discord.com/developers/docs/getting-started * https://developers.google.com/drive/activity/v2/quickstart/python?hl=en