Introduction: Make Your Very Own ChatGPT Discord Bot - in Python!

About: It's dark. You are likely to be eaten by a grue.

Today, we'll be making a general purpose Discord bot for use with an OpenAI API token and a Discord bot token written completely from scratch in Python. You may edit the commands and events as you see fit!


Always check the repo for the latest changes and file versions:


https://github.com/esper2142/python_OpenAI_Discord_Bot

Supplies

A computer with Python 3.X installed, and an editor of your choice!

Step 1: Create Discord Bot

Create a Discord bot and add it to your server with the appropriate permissions. More information here: https://discordpy.readthedocs.io/en/stable/discord.html

Step 2: OpenAPI Account & Key

Create an OpenAI account and create an API key: https://platform.openai.com/account/api-keys . Please note this is NOT free.

Step 3: Download Botvar.py and Change Variables

Download botvar.py (attached). Copy and paste your created tokens into the appropriate variables inside of botvar.py (attached).

Step 4: Get Your Discord Channel ID

Find the channel ID you'd like to post messages in your discord server, and paste over INSERT CHANNEL ID HERE in bot.py (attached). More information on how to find your channel ID here: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-

Attachments

Step 5: Add Images and Change Filepath

Upload your images for the script into a folder or the same directory as bot.py . Edit INSERT_FILEPATH_HERE to match your file path and file names in bot.py (attached in previous step).

Step 6: Host and Run Your Script

Host your script somewhere and run it. Suggestions are: your own PC/NAS/Raspberry Pi, or a cloud online service like pythonanywhere or Amazon EC2.


Enjoy!