Skip to content

Setup project locally

Chris Sdogkos edited this page Jan 30, 2024 · 21 revisions

Overview

This tutorial shows how to download, setup and start the TJ-Bot project locally on your machine.

Alternatively, you can also work directly in the cloud, for free, and get started in just a few seconds. See:

Prerequisites

What you will learn

  • use git to download the project
  • use gradle to download dependencies
  • use gradle to build the project
  • connect your bot to the program
  • use gradle to start the bot
  • interact with the bot from your server

Tutorial

Clone repository

First of all, you have to download the project to your machine. Visit the projects GitHub website and copy the .git link, which is this

https://github.com/Together-Java/TJ-Bot.git

.git link

IntelliJ git plugin

IntelliJ comes by default with a git plugin. You can easily clone repositories to your disk by clicking a few buttons.

  1. open your IntelliJ and select Get from VCS.
  2. select Git, enter the .git link and select a directory for the project; smack that Clone button
  3. IntelliJ will now open the project

Get from VSC IntellIJ UI .git url IntellIj UI

Manual usage of git

To download the project, use the following command:

git clone https://github.com/Together-Java/TJ-Bot.git TJ-Bot

You now have the project and all its data locally.

git clone command line TJ-Bot folder

Gradle

Next up, you have to download all the dependencies, generate the database and build the project.

IntelliJ Gradle plugin

IntelliJ comes by default with a gradle plugin. If not started already automatically, you can command it to do all of above by clicking a bunch of buttons.

  1. open the Gradle view
  2. expand the view and click on TJ-Bot > Tasks > build > build, or just click on the elephant icon and enter gradle build

Gradle tasks IntelliJ UI Gradle command IntelliJ UI Gradle output

ℹ️ If you get any gradle errors... Make sure that your project and gradle is setup to use the latest Java version. Sometimes IntelliJ might guess it wrong and mess up, leading to nasty issues.

Therefore, review your Project Structure settings and the Gradle settings: project settings gradle settings

Manual usage of gradle

You can also just execute Gradle from the command line.

  1. open a command line in the root directory of the project
  2. execute gradle build

Gradle command line start Gradle command line end

Start the bot

Last but not least, you want to start the bot with your bot token and let it connect to your private bot with which you can interact from one of your servers.

For this step, you need to hold your bot token ready, you can find it 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

To run the bot, you will need a config.json file with specific content. You can find a template for this file, with meaningful default values, in application/config.json.template.

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

IntelliJ

  1. put the configuration file to TJ-Bot\application\config.json or run the program with a single argument, the path to your config file
  2. in the Gradle view, click the run task and start it

Bot runs

Command line, runnable jar

  1. build a runnable jar of the project by executing gradle shadowJar
    1.1. the jar can now be found at TJ-Bot\application\build\libs
  2. unless you move the jar around, you have to adjust the database path in the config to ../../../build/database.db
  3. put the configuration file right next to the jar or run the program with a single argument, the path to your config file
  4. run java -jar TJ-Bot.jar

shadowJar jar

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:

Bot command

Clone this wiki locally