-
Notifications
You must be signed in to change notification settings - Fork 12
Setup
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.
First, we'll generate the bot Discord credentials.
- Go to https://discord.com/developers/applications
- Click on New Application and input a name
- 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)
- You can now click to reveal the token, copy it to the bot
config.json
file, in thetokens
→discord
field - (Optional) You can change the Bot Avatar on the bot page
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.
- On your Google account, go to https://console.developers.google.com/apis/credentials
- Click on Create Credentials at the top, and then Create OAuth client ID
- Select Web Application and input a name
- In Authorised Javascript origins, add
http://localhost:8080
- In Authorised redirect urls, add
http://localhost:8080/
(don't miss the extra/
) - Click Create
- On the application page, you can click Download JSON to retrieve your credentials
- Also, copy and paste the Client ID and Client secret on the right, to a safe place, we'll need those later.
- You'll need Python on your computer.
- Copy generate_gdrive_credentials.py from the tools folder near bot.py.
- Install PyDrive with the command
pip install PyDrive
orpython -m pip install PyDrive
from a Windows command prompt - Place
settings.yaml
besidegenerate_gdrive_credentials.py
and open it - Inside, input the Client ID and Client secret you copied earlier and save
- Run
generate_gdrive_credentials.py
, it should open your Web Browser and let you authentificate yourself -
If everything went well, a new file named
credentials.json
should have appeared. Move this file to the bot folder, besidebot.py
. Do the same forsettings.yaml
. - 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.
- Open
config.json
and add the folder IDs intokens
(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 isBunch_of_characters
). - Save data are stored compressed with the LZMA algorithm. Before doing anything, Copy
save.json
from theexample
folder into thetools
folder and drag-n-drop it ontosave_lzma.py
. Asave.lzma
file should have been created. (You can remove the copiedsave.json
) - Upload
save.lzma
to the Goole Drive folder corresponding todrive
inconfig.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.
Some commands interacting with Twitter are enhanced via the Twitter API.
This step is optional and follow the same steps as my Raidfinder application.
- 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.
- Once you have been approved, go to https://developer.twitter.com/en/apps to create a new Project and its App.
- In your app details, go to the "Keys and tokens" tab and copy your bearer token.
- Open
config.json
and put the token, in thetwitter
section at thebearer
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:
You might now want to complete config.json
.
- In Discord, open settings, click on Appearance and enable the Developper Mode. It allows to right click on anything and copy their IDs.
- You want a server for the bot, so please make one. Then right click on the server and copy its ID to
config.json
underids
→debug_server
. Do the same for the channel where you want the bot to put important messages. - Right click on yourself to get your ID and put it under
ids
→owner
. - 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.
- 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 is614733962736042005
). Then, copy the ID to the corresponding emote inconfig.json
.
- Go back to the Bot Page
- Copy the Client ID
- Insert it into
https://discordapp.com/oauth2/authorize?client_id=HERE&permissions=545394785367&scope=bot%20applications.commands
where I putHERE
- 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.
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.
- On your Dashboard, click on New and Create new Pipeline
- Input a name and click Create Pipeline
- Under Production, click on Add App → Create New App
- Input a name and select your region, and click Create App
- Click on your app (the url should be
https://dashboard.heroku.com/apps/your-app-name
) - Go to Deploy and under Deploy using Heroku Git to push the bot to Heroku
- 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
- The invitation link needs the application command scope. Edit your invitation link so it reads:
&scope=bot%20applications.commands
. - 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
.