Discord Bot Deployment Guide
This guide will walk you through deploying a Discord bot to Google Cloud Run.
Prerequisites
- Google Cloud Account
- Google Cloud SDK
- Discord Developer Account
- Docker (for local testing)
Step-by-Step Deployment Guide
1. Clone this repo
- Clone this repository:
git clone https://github.com/langchain-ai/lang-memgpt.git cd lang-memgpt/event_server
2. Set Up Discord Bot
- Go to the Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" tab and click "Add Bot"
- Under the "Token" section, click "Copy" to copy your bot token
- In the "General Information" tab, copy the "Public Key"
- Create a
.envfile in your project directory and add:Note: You can add any additional environment variables your bot might need to this file.DISCORD_TOKEN=your_copied_token_here DISCORD_PUBLIC_KEY=your_copied_public_key_here
3. Set Up Google Cloud Project
-
Create a new Google Cloud project or select an existing one:
To create a new one:
# To create a new project: PROJECT_ID="your-project-id" gcloud projects create $PROJECT_IDNote: Project ID must be globally unique and contain only lowercase letters, numbers, or hyphens.
Or if you have an existing one:
PROJECT_ID="your-existing-project-id" # Set the current project gcloud config set project $PROJECT_IDOr if you already have it configured:
PROJECT_ID=$(gcloud config get-value project) -
Enable necessary APIs:
gcloud services enable cloudbuild.googleapis.com run.googleapis.com containerregistry.googleapis.com -
Set up permissions for the Cloud Build service account:
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)') gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:$PROJECT_NUMBER@cloudbuild.gserviceaccount.com \ --role=roles/run.admin gcloud iam service-accounts add-iam-policy-binding \ $PROJECT_NUMBER-compute@developer.gserviceaccount.com \ --member=serviceAccount:$PROJECT_NUMBER@cloudbuild.gserviceaccount.com \ --role=roles/iam.serviceAccountUser
4. Deploy to Cloud Run
-
Submit the build to Cloud Build:
sh deploy_server.shThis reads the DISCORD_TOKEN and DISCORD_PUBLIC_KEY from your local
.envfile. -
After deployment, get your Cloud Run URL:
gcloud run services describe discord-bot --platform managed --region us-central1 --format 'value(status.url)'
5. Add Bot to Your Server
- In the Discord Developer Portal, go to the "OAuth2" tab
- In the "Scopes" section, select "bot"
- In the "Bot Permissions" section, select the permissions your bot needs
- Copy the generated URL and open it in a new tab
- Select the server you want to add the bot to and click "Authorize"
Troubleshooting
If you encounter any issues:
-
Check the Cloud Build logs:
gcloud builds list --limit=1 --format='value(id)' | xargs gcloud builds log -
Check the Cloud Run logs:
gcloud run logs read discord-bot --region us-central1
If you still face issues, please open an issue in this repository with the error details.
Contributing
If you'd like to contribute to this project, please fork the repository and create a pull request, or open an issue for discussion.