This discord named Cletus was a personal project designed and programmed by me for the Astrum discord based nation simulator. This bot could take a set order form from a player, and process the game structures they wished to build and then add the structures they built to a players structures totals, as well as calculating the cost of their projects. This Discord bot was connected to a Google Sheet using Google Developers Google Sheet API. The discord bot was fully programmed in Python 3. This bot is designed to pull from a preset form with edited values, it then breaks the form down into structures, and numbers of structures, and puts those values into 2 sperate index’s. Using those index’s, and values pulled from the Astrum Master Sheet the bot can calculate how many structures a player has, how much their order cost, as well as updating their national bank after the daily income is processed. This bot allowed for an in depth, and complex playing system for players to have a unique and free experience on discord, while also taking the work load off the admins when it comes to building orders.
[INSERT VIDEO OF CODE WORKING HERE]
Setting up the Discord Bot.
I set up the discord bot using the following website as a guide.
https://discordpy.readthedocs.io/en/stable/discord.html
Connecting the Discord Bot to a Google Sheet.
The first step in this project was setting up a google developer account to get access to the google sheet API. https://developers.google.com/profile
The second step would be to set up the Google Sheets API.
For this you will need to go to the google cloud console at https://console.cloud.google.com/
Next you will select your google account.
You will then go to the project manager, which is the menu next to the google cloud logo.
You will then make a new project and name this project then hit create.
You will then select the project once its made and appears in notifications.
You will then go to the navigation menu, and select API and services, and then hit Enabled APIs and services.
Then hit the Enable APIs and services tab at the top of the screen and search for the google sheets API.
You will then Enable the google sheets API.
You will then click the create credentials button.
You will then select the Application Data, hit next.
You will then create a service account, hit create and continue, make sure to give this service account the editor role, click continue, then done.
You will then hit the credentials tab, click the service account you made, click the keys tab, click add key, click create new key, then select JSON as key type, then click create.
You will then add that JSON file to the project directory for your Python Project.
You will then need to make a google sheet, and add your service account as an editor to the google sheet.
The third step in this process is to connect the bot python code to your google sheet.
You will need to install a few packages to interact with the google sheet.
The command to do this is as follows.
pip install –upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib gspread
Below is the code needed to set up the connection to the google sheet.
Once you do this your python code will be connected to your google sheet.
Here is a in-depth video if you get lost. https://www.youtube.com/watch?v=zCEJurLGFRk
Next you will need to connect your code to your discord bot, to do this you will need to the discord.py library
pip install Discord.py
You will also need your discord API Key. At the bottom of your program you will put
Client.run(Put your discord API Key here)
Here is an Example a fully working discord-python-google sheet bot
Once you do all of this you should have a functioning discord to google sheets bot.
Recent Comments