Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
MizaGBF edited this page May 28, 2022 · 11 revisions

Note: Don't ask for help if you have troubles, I wrote this mostly for educational purpose. I don't recommend you run a copy of my bot.

You'll need a few things before starting.
The Example folders contain config.json and settings.yaml, retrieve and put those beside the bot.py file. Disclaimer, the procedure might evolve in the future, I'm sorry if those instructions are inaccurate.
Also, you'll need to be familiar with git and Python.

Setting up the Discord Application

First, we'll generate the bot Discord credentials.

  1. Go to https://discord.com/developers/applications
  2. Click on New Application and input a name
  3. On your application page, click on the Bot tab on the left, then Add Bot and Yes, do it (rename your bot if you get an error)
  4. You can now click to reveal the token, copy it to the bot config.json file, in the tokensdiscord field
  5. (Optional) You can change the Bot Avatar on the bot page

Setting up Google Drive

Google Drive is used to load and save data, as Heroku offers no persistent storage.
In the same way as discord, you'll need credentials, and it's a bit more complicated.

  1. On your Google account, go to https://console.developers.google.com/apis/credentials
  2. Click on Create Credentials at the top, and then Create OAuth client ID
  3. Select Web Application and input a name
  4. In Authorised Javascript origins, add http://localhost:8080
  5. In Authorised redirect urls, add http://localhost:8080/ (don't miss the extra /)
  6. Click Create
  7. On the application page, you can click Download JSON to retrieve your credentials
  8. Also, copy and paste the Client ID and Client secret on the right, to a safe place, we'll need those later.
  9. You'll need Python on your computer.
  10. Copy generate_gdrive_credentials.py from the tools folder near bot.py.
  11. Install PyDrive with the command pip install PyDrive or python -m pip install PyDrive from a Windows command prompt
  12. Place settings.yaml beside generate_gdrive_credentials.py and open it
  13. Inside, input the Client ID and Client secret you copied earlier and save
  14. Run generate_gdrive_credentials.py, it should open your Web Browser and let you authentificate yourself
  15. If everything went well, a new file named credentials.json should have appeared. Move this file to the bot folder, beside bot.py. Do the same for settings.yaml.
  16. Now go to Google Drive in your Web Browser and create two folders (one for the save data, one for the various files the bot might need). You can also create a third for the Bot Uploads but it's unused at the time of this writing.
  17. Open config.json and add the folder IDs in tokens (drive is the save folder ID, files is the file folder ID, upload is the upload folder ID). Put them between " quotes or you'll get an error. You can retrieve a folder ID from its URL in your browser (example: https://drive.google.com/drive/folders/Bunch_of_characters, the ID is Bunch_of_characters).
  18. Save data are stored compressed with the LZMA algorithm. Before doing anything, Copy save.json from the example folder into the tools folder and drag-n-drop it onto save_lzma.py. A save.lzma file should have been created. (You can remove the copied save.json)
  19. Upload save.lzma to the Goole Drive folder corresponding to drive in config.json and you are done.

Additional note: If you ever need to decompress a save.lzma file, you can also drag-n-drop it onto save_lzma.py to decompress it.

Setting up Twitter (Optional)

Some commands interacting with Twitter are enhanced via the Twitter API.
This step is optional and follow the same steps as my Raidfinder application.

  1. Go to https://developer.twitter.com/en/apply/account to apply for a Developper account. You'll need a phone number linked to your account like in the past, but they also request a bit more informations to be sure you won't be misusing the API. You don't need to give personal informations.
  2. Once you have been approved, go to https://developer.twitter.com/en/apps to create a new Project and its App.
  3. In your app details, go to the "Keys and tokens" tab and copy your bearer token.
  4. Open config.json and put the token, in the twitter section at the bearer key, between " quotes (In doubt, check the example config.json, you'll see where it is).

At this point in time, your bot folder should look that way, or similar:
Folder

Complete config.json

You might now want to complete config.json.

  1. In Discord, open settings, click on Appearance and enable the Developper Mode. It allows to right click on anything and copy their IDs.
  2. You want a server for the bot, so please make one. Then right click on the server and copy its ID to config.json under idsdebug_server. Do the same for the channel where you want the bot to put important messages.
  3. Right click on yourself to get your ID and put it under idsowner.
  4. Fill the rest of the IDs if you want to but I recommend putting 0 instead as you won't need them for a test run.
  5. You gotta do the same for the bot custom emotes, under emotes. Upload an emote of your choice to your bot discord, type an antislash \ followed by your emote to retrieve the id (example, if it gives you <:fire:614733962736042005>, the emote ID is 614733962736042005). Then, copy the ID to the corresponding emote in config.json.

Inviting your bot to your server

  1. Go back to the Bot Page
  2. Copy the Client ID
  3. Insert it into https://discordapp.com/oauth2/authorize?client_id=HERE&permissions=545394785367&scope=bot%20applications.commands where I put HERE
  4. Visit the url in your browser and select the server where to invite the bot
    You also can edit the permissions part, in the url, using this tool.

Setting up Heroku

Before starting, you'll need the Heroku CLI and git.
Keep in mind a free account can only run the bot for around 22 days per month.

  1. On your Dashboard, click on New and Create new Pipeline
  2. Input a name and click Create Pipeline
  3. Under Production, click on Add AppCreate New App
  4. Input a name and select your region, and click Create App
  5. Click on your app (the url should be https://dashboard.heroku.com/apps/your-app-name)
  6. Go to Deploy and under Deploy using Heroku Git to push the bot to Heroku
  7. The bot should be up and running. If not, check under Worker if there is a worker sets to python3 bot.py. You can also click on More and view logs to check error messages

Additional Informations

  1. The invitation link needs the application command scope. Edit your invitation link so it reads: &scope=bot%20applications.commands.
  2. You can edit the invitation link default permissions by editing the value in the url. There is a calculator in the Discord Developer portal, under your application > Bot, at the bottom of the page. I use 1644905889015.