aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Public Cloud
  • Solutions

Build And Run A Discord Bot On Top Of Google Cloud

  • aster.cloud
  • October 1, 2021
  • 3 minute read

Stuck at home these past–checks calendar–732 months, I’ve been spending a lot more time on Discord (an online voice, video and text communications service) than I ever thought I would. Chatting with far-flung friends, playing games, exploring, finding community as I am able, and generally learning about a platform I had not used all that much before the pandemic. And part of that fun was seeing all the cool bots people have made on Discord to liven things up: moderation, trivia, and games: many little, weird, random games.

So I wondered: could I make one? 


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Since bots are just code that interact with Discord’s APIs, they have to have a computer to run on. Cool, I have one of those. But I don’t want my bot to disappear just because my computer is off, so I need something better: a computer that can always stay on. Reliable infrastructure. If only I could find that somewhere…

What would it take to actually run a bot on someone else’s (ie. Google’s) computers?

discord

I’m assuming here that you’ve set up your Discord developer account, made a New Application (with a clever name of course), got the bot token from the menu under Settings > Bot > Token (have to Copy or Reveal), and have that stored safely on a sticky note by your desk.

Now, on to Google Cloud! First make sure you have an account set up and are able to create new resources. We’ll need a Virtual Machine (VM), part of Google Compute Engine. In Google Cloud, make a new project, head to Compute, and create a new instance. The smallest instance is going to be fine for this Hello, World example, so let’s use an f1-micro instance, because it’s free! To get that going I chose us-east1 as my region, Series N1, then Machine type f1-micro.

Read More  Learn Beam Patterns With Clickstream Processing Of Google Tag Manager Data
new vm instance
Click to enlarge

While I love me some serverless architecture, and it’s usually much lower overhead, in this case we want to have a persistent instance so there’s always a process ready to respond to a request, via the Discord API. We want to avoid any timeouts that might emerge if a serverless solution takes time to spin up listeners. At the same time, we need to avoid having more than one process running, otherwise we could have multiple responses to a Discord signal, which will be confusing.

In choosing our VM we need something running Python 3.5+, to support our Discord bot code. The default (as I write) is Debian GNU/Linux 10 (buster) which is running Python 3.7, good enough for us! Once the VM is live we can start getting our code setup on it. You’ve got a few options for connecting to the Linux VMs.  Once you’ve done so, time to install and run some code!

To run our code we want to install and setup pip (package installer for python), using

sudo apt update
sudo apt install python3-pip

Then run

pip3 install discord.py

…to install the Discord library onto your server.

We can drop our code directly into a new bot.py file; organizing it into more structured files will come after we move past the Hello, World! stage. For now you’ll hard code the bot token into bot.py, even though that gives me the shivers.

from discord.ext import commands

bot = commands.Bot(command_prefix='..', description='A simple Discord bot')

token = '<YOUR_TOKEN_HERE>'

@bot.command()
async def hello(ctx):
    await ctx.send("Hello!")

bot.run(token)

And now we’re ready to run our bot!

Read More  Modernize Your Java Apps With Spring Boot And Spring Cloud GCP

python3 bot.py

And you can add it to our server by going back to the Discord Developer portal, select our App, and look under Settings for OAuth2. Once you choose the right scope (we can stick with just bot for now), a new link will appear below the Scopes box, starting with

https://discord.com/api/oauth2/authorize?<lots of numbers here>

Loading that in your browser is all it takes to add you new bot the the server you have permissions to manage, and now you are all set! Test it out by sending the message `..hello` to your server.

You can read more about the Free Tier for Compute Engine and other services, and come back next time for a deeper exploration into operations for your Google Cloud-powered Discord bot.

 

 

By Max Saltonstall, Developer Relations Engineer | David Stanke, Developer Relations Engineer
Source Google Cloud Blog

For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster.cloud

Related Topics
  • Bot
  • Discord
  • Google Cloud
You May Also Like
View Post
  • Computing
  • Public Cloud
  • Technology

United States Army Enterprise Cloud Management Agency Expands its Oracle Defense Cloud Services

  • April 15, 2025
DeepSeek R1 is now available on Azure AI Foundry and GitHub
View Post
  • Public Cloud
  • Technology

DeepSeek R1 is now available on Azure AI Foundry and GitHub

  • February 2, 2025
Cloud platforms among the clouds
View Post
  • Computing
  • Learning
  • Public Cloud

Best Cloud Platforms Offering Free Trials for Cloud Mastery

  • December 23, 2024
Vehicle Manufacturing
View Post
  • Hybrid Cloud
  • Public Cloud

Toyota shifts into overdrive: Developing an AI platform for enhanced manufacturing efficiency

  • December 10, 2024
IBM and AWS
View Post
  • Public Cloud

IBM and AWS Accelerate Partnership to Scale Responsible Generative AI

  • December 2, 2024
COP29 AI and Climate Change
View Post
  • Public Cloud
  • Technology

How Cloud And AI Are Bringing Scale To Corporate Climate Mitigation And Adaptation

  • November 18, 2024
Cloud Workstations
View Post
  • Public Cloud

FEDRAMP High Development in the Cloud: Code with Cloud Workstations

  • November 8, 2024
View Post
  • Public Cloud

PyTorch/XLA 2.5: vLLM support and an improved developer experience

  • October 31, 2024

Stay Connected!
LATEST
  • college-of-cardinals-2025 1
    The Definitive Who’s Who of the 2025 Papal Conclave
    • May 7, 2025
  • conclave-poster-black-smoke 2
    The World Is Revalidating Itself
    • May 6, 2025
  • oracle-ibm 3
    IBM and Oracle Expand Partnership to Advance Agentic AI and Hybrid Cloud
    • May 6, 2025
  • 4
    Conclave: How A New Pope Is Chosen
    • April 25, 2025
  • Getting things done makes her feel amazing 5
    Nurturing Minds in the Digital Revolution
    • April 25, 2025
  • 6
    AI is automating our jobs – but values need to change if we are to be liberated by it
    • April 17, 2025
  • 7
    Canonical Releases Ubuntu 25.04 Plucky Puffin
    • April 17, 2025
  • 8
    United States Army Enterprise Cloud Management Agency Expands its Oracle Defense Cloud Services
    • April 15, 2025
  • 9
    Tokyo Electron and IBM Renew Collaboration for Advanced Semiconductor Technology
    • April 2, 2025
  • 10
    IBM Accelerates Momentum in the as a Service Space with Growing Portfolio of Tools Simplifying Infrastructure Management
    • March 27, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • 1
    Tariffs, Trump, and Other Things That Start With T – They’re Not The Problem, It’s How We Use Them
    • March 25, 2025
  • 2
    IBM contributes key open-source projects to Linux Foundation to advance AI community participation
    • March 22, 2025
  • 3
    Co-op mode: New partners driving the future of gaming with AI
    • March 22, 2025
  • 4
    Mitsubishi Motors Canada Launches AI-Powered “Intelligent Companion” to Transform the 2025 Outlander Buying Experience
    • March 10, 2025
  • PiPiPi 5
    The Unexpected Pi-Fect Deals This March 14
    • March 13, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.