Skip to content

Code in the cloud (codespaces)

Daniel Tischner edited this page Nov 15, 2022 · 7 revisions

Overview

This tutorial shows how to code and run the project in GitHubs cloud.

The service is completely free and allows you to get started in just a few seconds.

This approach is an alternative to setting the project up on your local machine, as explained in:

Tutorial

Create codespace

  1. Visit the landing page
  2. Click on Code > Create codespace on develop

create codespace

GitHub now automatically sets up your codespace. The codespace is essentially a virtual machine with everything installed and configured that you need to work with this project.

Mostly, it will install Java and Gradle for you, and a few other useful plugins and extensions.

setup

This process takes about 2 minutes for the first time. Once the setup is done, it opens an instance of Visual Studio Code in your browser, with the project opened. You can now get started!

VSC opened

Config

Before you can run the bot, you have to adjust the configuration file. Therefore, open the file application/config.json.

By default, it will be filled with some example values and most of them are totally okay for now.

The most important setting you have to change is the bot token. This enables the code to connect to your private bot with which you can then interact from your private server.

You can find the token at the Discord Developer Portal.

See the following guide if you still have to create a server and a bot first:

Discord Developer Portal - Bot Token

Replace <your_token_here> with your bot token; you can also adjust the other settings if you want.

replace token

Run

Once done, you are good to go and can run the bot. Just enter gradle application:run in your terminal.

gradle run

On the first run, this might take around 3 minutes, because it will first have to download all dependencies, generate the database and compile the code.

Once the terminal reads [main] INFO org.togetherjava.tjbot.Application - Bot is ready, you are done!

Have fun

The bot is now running and connected to your server, hurray 🎉

You can now execute commands and see the bot do its magic:

pong

IntelliJ instead of VSC

If you prefer IntelliJ, and have a license, they offer a client called JetBrains Gateway.

While not being all-within your browser, it is essentially an IDE that you can install, which will just remote-connect to your codespace.

Once installed, you have to get the GitHub Codespaces plugin:

plugin

You can then login to your GitHub account and select your codespace:

select codespace

The initial setup takes a few minutes, since it has to install IntelliJ on the codespace first.

Clone this wiki locally