- Discord Bot
- Table of Contents
I wanted something to do on my spare time outside of my work as a DevSecOps Engineer and my studies at Nackademin. So i decided to create a discord bot for use in my class discord server. I also wanted to experiment with setting up github actions.
This is a discord bot that currently has a few functionalities
- OpenAI ChatGPT
- OpenAI Image Generation
- Able to show a schedule
- Github Stats
Once the Discord Bot is running in your server, you can interact with it using the following methods:
- Use a specific command:
/command_name arguments
Commands available:
/chatgpt <message>
: Interact with ChatGPT using the provided message./image <message>
: DALL-E will generate a image for you based on the message.- Takes 2 optional inputs. Size and number of images
/dm
: Send a direct message to the specified user with the provided message.- Takes an optional input of a message
/github_stats
: Shows simple github stats- Takes an optional input of a username.
/schedule
: Shows a schedule for the next n days- n = number of days (excluding weekends). Take the optional input of number of days. If not supplied it will default to 7 days.
/about
: Get information about the ChatGPT Discord Bot./help
: Display a list of available commands and their usage.
Example:
Sender: /chatgpt What is the capital of France?
Theodore: @Sender: The capital of France is Paris.
- When running
/github_stats
the console will spit outx_order_2: colinear!
- Give the ChatGPT part of the bot a memory
- DONE!
Add image generating AI - Add more options to config.json for AI image generation
- Make the schedule be more dynamic and take more inputs from the user
If you want to contribute to this project, please read the CONTRIBUTING file.
- Docker
I have not provided either the OpenAI API key or the discord bot token. You will need to create your own.
- Go to developer applications and log in with your discord account.
- Click on "New Application" and give it a name.
- Click on "Bot" in the menu on the left.
- Click on "Reset Token"
- Copy the token and save it somewhere safe, you're going to need it later
- Make sure that that you tick the 3 bottoms checks (like this)
- Click on "Add Bot" and confirm.
- Click on "OAuth2"
- Click on "URL Generator"
- Select "bot" and "applications.commands"
- Make sure that that you set the correct permissions (example)
- Copy the link and paste it in your browser.
- Select the server you want to add the bot to.
- Click on "Authorize"
- You should now see the bot in your server.
- Go to OpenAI and log in with your OpenAI account.
- Click on your account in the op right
- Click on "View API keys"
- Click on "Create new secret key"
- Copy the key and save it somewhere safe, you're going to need it later
The config.json file is used to configure some settings of the bot.
The file is located in the src/config
folder.
Variable | What it is | Default |
---|---|---|
openai.model | The OpenAI model to use | chatgpt-3.5-turbo |
openai.temperature | The temperature to use for OpenAI model responses | 1 |
openai.max_tokens | The maximum number of tokens to generate for OpenAI model responses | 4000 |
Variable | What it is | Default |
---|---|---|
discord.dedicated_channel_id | The ID of the dedicated channel for the bot to listen to messages on | None |
discord.log_folder | The folder where logs will be stored | /logs |
discord.log_path_channel | The path for channel logs | Showlogs/channel_{time: YYYY-MM-DD-HH-mm-ss! UTC}.log |
discord.log_path_command | The path for command logs | Showlogs/command_{time: YYYY-MM-DD-HH-mm-ss! UTC}.log |
discord.log_path_discord | The path for discord logs | Showlogs/discord_{time: YYYY-MM-DD-HH-mm-ss! UTC}.log |
discord.log_level | Log level for the discord logger | DEBUG |
Variable | What it is | Default |
---|---|---|
logger.log_path_info | The path for info logs | Showlogs/info_{time: YYYY-MM-DD-HH-mm-ss! UTC}.log |
logger.log_level | The level of logging to use | DEBUG |
logger.log_rotation | The maximum size of each log file before it is rotated | 100000000 |
logger.log_retention | The length of time to retain log files for | 730 days |
logger.log_compression_format | The format of the compressed log files | zip |
Variable | What it is | Default |
---|---|---|
schedule.url | URL to your class schedule | None |
Variable | What it is | Default |
---|---|---|
github.user_stats | API link for stats | |
github.user_streak | API link for streak | |
github.default_user | Default user for stats and streak API of no username is provided in the command | mindriddler |
You can change these values to whatever (as long as they're valid) you want and the bot will respect them
- Clone the repo
- Rename the file called
.env.template
in the root of the project to.env
- Add the following lines to the file:
OPENAI_API_KEY=<your api key>
DISCORD_TOKEN=<your bot token>
- Make your desired changes in
Discord_bot/src/config/config.json
- Change your working directory to
Docker
- Run
docker-compose up -d
If you prefer not to build the Docker image yourself, you can pull the pre-built images from GitHub Container Registry (GHCR). However, you will still need to provide your own OpenAI API key and Discord bot token.
To pull the images from GHCR, use the following command:
docker pull ghcr.io/mindriddler/discord-bot:<tag>
Replace <tag>
with the appropriate tag for the version you want to use (e.g., latest
).
After pulling the image, you can run the container using the following command:
docker run -d --name discord-bot --env-file .env ghcr.io/mindriddler/discord-bot:<tag>
Replace <tag>
with the same tag used when pulling the image.
If you encounter any issues while setting up or using the ChatGPT Discord Bot, please consult the following resources:
- Check the OpenAI API documentation and ensure your API key is set up correctly.
- Review the discord.py documentation for possible issues related to Discord interactions.
- If you still need help, please create an issue on this repository or contact me through one of the methods provided in the "Contact" section of this README.
This project is licensed under the GNU License - see the LICENSE file for details
If you want to contact me you can reach me at
- Discord:
Wikipedia#5457
- Email:
[email protected]
- Github: mindriddler
- LinkedIn: Link
This project is not affiliated with OpenAI or Discord in any way.