-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Eric Lu edited this page Nov 26, 2021
·
10 revisions
The following are the steps to take to set this bot up yourself:
- Download the repository and save it wherever you want on your local machine.
- In the console, download the necessary dependencies with
gradle build
.
- In the console, download the necessary dependencies with
- In the
primary
package (with the other Java files), create a newConfig.java
file with the following code:
package primary;
public class Config {
static final String DISCORDBOTTOKEN = // Bot's Discord token
static final String REDDITBOTID = // Reddit ID of the bot's owner
static final String REDDITBOTSECRET = // Bot's Reddit token
static final String REDDITUSERUSERNAME = // Reddit username of the bot's owner
static final String REDDITUSERPASSWORD = // Reddit password of the bot's owner
static final String MONGOURI = // Link that connects Bot to MongoDB database
}
Following the proceeding steps will get you the values you need.
- Go to the Discord Developer Console and click "New application".
- On the left sidebar, select "Bot".
- Click "Add Bot"
- In the "Bot" section, press "Click to Reveal Token" and copy the listed token. That token corresponds to
"DISCORDBOTTOKEN"
inConfig.java
. - On the left sidebar, select "OAuth2".
- Under "Scopes", check off "bot" and "applications.commands".
- Under "Bot permissions", select the permissions you wish to give the bot.
- At minimum, you will need to give the bot the following permissions:
Send Messages
Read Message History
Use Slash Commands
Read Messages/View Channels
Embed Links
- Alternatively, you can give the bot
Administrator
and be done with it, although depending on the server you might not want to or be allowed to do so.
- At minimum, you will need to give the bot the following permissions:
- After Step 7), Discord will auto generate a link to you. Go to that address. From there, you will be able to select which server(s) you'd like to add the bot to.
- To create a brand new server to add the bot to, press the green plus button on the left sidebar on the normal Discord window ("Add a server"), then click "Create a server", input whatever server name you want and then finally click "Create".
- Log into the Reddit account on which you wish to host the bot. (While you're at it, fill out
"REDDITUSERUSERNAME"
and"REDDITUSERPASSWORD"
inConfig.java
. - Go to the Reddit Application Console. Scroll down and click on "create app".
- For the name field, put whatever you want.
- Click on "Script for personal use. Will only have access to the developers accounts".
- For the description field, put whatever you want.
- Don't put anything for the "about url".
- For "redirect uri", enter "https://reddit.com".
- Click on "edit" on the app you just created.
- The string underneath "personal use script" corresponds to
"REDDITBOTID"
inConfig.java
. - "secret" corresponds to
"REDDITBOTSECRET"
inConfig.java
.
- The string underneath "personal use script" corresponds to
Follow this guide to create a free MongoDB Atlas cluster.
- The URL with
mongodb+srv:...
corresponds toMONGOURI
in"Config.java"
.
(Credit to this guide; much of this part is adopted from that guide, and adjusted correspondingly for Java.)
- Download the corresponding
.jar
file (Reddit-Discord-Bot-1.0-all.jar
) withgradle shadowJar
.- Make sure your
Config.java
is complete before doing this. - After running the gradle command, the
.jar
file can be found in the...\build\libs\
directory.
- Make sure your
- Set up a free AWS EC2 VPS (for one year), and host your bot on it.
- Go to the Amazon EC2 Page and sign up for an account.
- Navigate to the Amazon web services console.
- Click on "EC2" (top left of page).
- Select "Launch Instance".
- Select "Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-5189a661". (You are welcome to use others, but this one worked for me.)
- Pick "General Purpose" (free tier micro)
- Select "Review and Launch"; launch
- You’ll then see a prompt about your "key/pair". The key pair consists of a public key that AWS stores, and a private key file that you store. They come together in a file "something.pem" which you will need in order to login to your account. Select "create new pair" and enter a title for your key/pair.
- Download the key pair, and save it to somewhere you'll remember to find it on the computer.
- Now you should see a message that "Your instances are launching" (it may take a few minutes before they are available.)
- Select "View Instances." Record the "Public IPv4 address".
- Navigate terminal to the directory where you have your "pem" file. First you must make sure your key is not “publicly” viewable. This has to do with file permissions.
- Do
$ chmod 400 yourkeyfile.pem
to check.
- Do
- In the terminal, enter
$ ssh -i "yourkeyfile.pem" ubuntu@[Instance Public IPv4 address]
to login to the key, where [Instance Public IPv4 address] is the "Public IPv4 address" you recorded earlier. - In the key, download Java 15 with the following commands:
$ wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
$ sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
$ sudo apt-get install adoptopenjdk-15-hotspot
- In the key, download tmux with the following commands:
$ sudo apt install tmux
- This will allow the bot to run even when the terminal is closed.
- Upload the
Reddit-Discord-Bot-1.0-all.jar
file to the server.- You can do this with SFTP software like Cyberduck. Log onto Cyberduck with the "Public IPv4 address" as the Server and your
.pem
file uploaded as the SSH Private Key, as shown below: After logging in, it should be trivial to drag and drop theReddit-Discord-Bot-1.0-all.jar
file into Cyberduck, or direct upload theReddit-Discord-Bot-1.0-all.jar
file from its absolute path into Cyberduck.
- You can do this with SFTP software like Cyberduck. Log onto Cyberduck with the "Public IPv4 address" as the Server and your
- Start running the bot as follows:
$ tmux new -s bot
$ java -jar Reddit-Discord-Bot-1.0-all.jar
- After doing the above commands, it is safe to close the terminal. The bot will now run until something happens to your AWS EC2 VPS, or you tell it to stop with
$ tmux kill-session
in the key terminal.