A Discord bot that pulls media from your Google Drive, and sends it to your servers. You can also DM the bot!
The link in the description points to a private bot, and is only meant for demonstration purposes. You need to Setup your own bot to try it out.
As the bot deals with Google OAuth and requires access to sensitive scopes
, I have not deployed it as a customizable public bot. The server admins must deploy it themselves.
- Clone this repository
- Install all dependencies using
yarn
*
*Node.js v12+
must be installed on your system. npm
commands are also supported
- Create a new Google Cloud Platform (GCP) project
- Configure the OAuth Consent Screen. In this step, select the scope
https://www.googleapis.com/auth/drive
when prompted. - Create credentials and choose Desktop credentials
- Download the credentials and save the JSON file as
credentials.json
in the base directory of the project - Run
yarn generate
in the base directory of the project. This step should open a link in your browser - Select the Google Account associated with your drive
- This will take you to an OAuth consent screen. Click on
show advanced
andGo to <app-name> (unsafe)
# - Paste the generated code in the terminal from step 5
- The script will generate the tokens, test them and save them in
token.json
# This appears if GCP app requires access to sensitive scopes and the OAuth consent screen is not approved by Google. As this is your own app, you don't need to worry about this.
credentials.json
format
{
"installed": {
"client_id": "<client-id>.apps.googleusercontent.com",
"project_id": "<project-name>-<project-id>",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "<client-secret>",
"redirect_uris": [
"abc:defg:hi:oauth:2.0:jkl",
]
}
}
token.json
format
{
"access_token": "<access-token>",
"refresh_token": "<refresh-token>",
"scope": "https://www.googleapis.com/auth/drive",
"token_type": "Bearer",
"expiry_date": "time-in-ms-since-epoch"
}
- Create a Discord Application
- Select your application and create a Discord Bot
In your project directory, create a .env
file and add the following fields
DRIVE_DIR=
APP_ID=
BOT_TOKEN=
BOT_NAME=
BOT_COMMAND=
FOF=https://42f2671d685f51e10fc6-b9fcecea3e50b3b59bdc28dead054ebc.ssl.cf5.rackcdn.com/illustrations/page_not_found_su7k.svg
Variable | Description |
---|---|
DRIVE_DIR |
root . |
APP_ID |
The Application ID of your Discord Application |
BOT_TOKEN |
The authorization token of your Discord Application's Bot |
BOT_NAME |
The name of your bot |
BOT_COMMAND |
The command that the bot should respond to. Example: !fs used by Rhythm |
FOF |
Fallback 404 image URI when the requested media is not found |
The project can be deployed using any cloud provider (Azure, GCP, AWS, etc). I used Azure App Services / Azure Pipelines and chose the Node.js configuration.
NOTE:
- Discord Bots use websockets for real-time communication. So it can't be deployed on a serverless platform like Vercel.
- Free services like Heroku, Glitch, etc. will force your app to sleep after some time of inactivity. Your bot will go offline and not respond in this case.
- This can be fixed using workers or cron jobs, but you may run out of your monthly limits.
- Head over to your deployment url, (or
localhost:3000
, when testing) or openhttps://discord.com/oauth2/authorize?client_id=APP_ID&scope=bot
and replace theAPP_ID
with your Discord Application ID - Login to Discord and add the bot to your server. If the bot is private, only the owner of the bot can do this.
- Add files in your selected drive folder with keywords in the file name. Example:
tinder meme 2020.png
- Send a command in your server/Bot DM. Example:
BOT_COMMAND tinder meme
, where<BOT_COMMAND>
is the command stored in the.env
file (like!fs
). - The bot will send any random file from your selected folder that contains these keywords.
phrases.json
is a set of reply messages. The bot will use one of these in standard replies.errors.json
is a set of error messages. The bot will use one of these if the command is incorrect or the requested file(s) is/are missing.