Scradditor is a Discord bot that allows you to track new posts for any subreddit. The bot is developed with Python using the discord.py and Async PRAW library. Hosted on Google Cloud Platform.
There are four main steps to set up this bot: creating a Reddit app, creating a Discord app, setting up Google Cloud, and configuring the Python code.
- Navigate to https://www.reddit.com/prefs/apps
- Click the "create another app..." button
- Name the app anything you want
- Select "script" as the application type
- Click "create app"
- After the app is created, save the ID under "personal use script"
- Click "edit"
- Save the ID next to "secret"
- Navigate to the Discord Developer Portal
- Sign in to your Discord account
- On the "Applications" page, click on "New Application" on the top right corner
- Name the app to your liking
- On the "Bot" page, click on "Add Bot"
- Toggle all the options in the "Privileged Gateway Intents" section1
- Click "Reset Token" and save this token somewhere in your local machine
- Create a Google Cloud account if you haven't already
- Create a new project with any name
- Click on "Create a VM" on the project welcome page
- It will prompt you to create a billing account as it is required to use Google Cloud's free tier2
- Set up billing account
- You should now be at the "Create an instance" page
- Choose a name for your VM instance
- For the region, choose either
us-west1
,us-central1
, orus-east1
- The zone can be any of the ones available
- For the machine family, choose "GENERAL-PURPOSE"
- For series, choose
E2
- For the series type, choose
e2-micro
- Next, at the "Boot disk" section, click "CHANGE"
- For the OS, choose
Ubuntu
- For the version, choose
Ubuntu 22.04 LTS
forx86/64
- Set boot disk type as
Standard persistent disk
- Set size to
30
GB, as shown in the free tier documentation - Although it might say that you will be charged for creating this instance, you won't
- Install the gcloud CLI with these instructions
- In the "VM instances" tab, click on the name of your VM instance
- Click the dropdown arrow next to the "SSH" button
- Click "View gcloud command"
- The command should look something like this:
$ gcloud compute ssh --zone "ZONE" "VM_NAME" --project "PROJECT_ID"
- Copy the command and run it in your terminal
- Now you have your VM running!
- In your VM terminal, create a new folder for your bot and navigate to the folder
$ mkdir YOUR_BOT_NAME
$ cd YOUR_BOT_NAME
- For this step, you can either
git clone
this repo3 or manually create each file and copy paste the code
$ git clone https://github.com/ysadamt/scradditor.git
$ touch bot.py
$ touch scraper.py
- If you are doing the second option, do this for
bot.py
andscraper.py
- Run
vim <filename>
- Type
i
(enter insert mode in Vim) - Paste code using
CTRL V
or right-click - Press
ESC
(exit insert mode) - Type
:w
then:q
(write the code to file, then quit Vim)
- Run
- Create two files
$ touch .env
$ touch praw.ini
- Using the Vim instructions above, copy this code to
.env
DISCORD_TOKEN=
DISCORD_GUILD=
- Paste the token you saved when creating a Discord app after
DISCORD_TOKEN=
- Similarly, paste the name of your server you plan to use the bot in after
DISCORD_GUILD=
- Using the Vim instructions above, copy this code to
praw.ini
[scraper]
client_id=
client_secret=
- Paste the ID you saved when creating a Reddit app after
client_id=
- Similarly, paste the secret ID after
client_secret=
- Run the command
screen
- Run
python3 bot.py
- Press
CTRL A D
- You can exit the VM by running
exit
, and your bot is now running in the background of the VM
Run the $help
command in your server to view all the commands. You can set the subreddits, keywords, and channel to send new submissions in. If you made it this far, congrats! You will now be notified whenever a submission that matches your keywords is posted.