This guide will walk you through deploying a Discord bot to Google Cloud Run.
- Google Cloud Account
- Google Cloud SDK
- Discord Developer Account
- Docker (for local testing)
- Clone this repository:
git clone https://github.com/langchain-ai/lang-memgpt.git cd lang-memgpt/event_server
- 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
.env
file 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
-
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_ID
Note: 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_ID
Or 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[email protected] \ --member=serviceAccount:$PROJECT_NUMBER@cloudbuild.gserviceaccount.com \ --role=roles/iam.serviceAccountUser
-
Submit the build to Cloud Build:
sh deploy_server.sh
This reads the DISCORD_TOKEN and DISCORD_PUBLIC_KEY from your local
.env
file. -
After deployment, get your Cloud Run URL:
gcloud run services describe discord-bot --platform managed --region us-central1 --format 'value(status.url)'
- 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"
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.
If you'd like to contribute to this project, please fork the repository and create a pull request, or open an issue for discussion.