A simple Python-based Discord bot for the OpenAI API
NOTE: This bot is heavily WIP and is currently only intended for special use case purposes. Many of the features have not been implemented yet. For a more sophisticated project, see i.e. my Telegram bot.
Although merely a crude initial sketch, this bot basis uses (as of January 2024) the up-to-date version of OpenAI's Python library (v1.6.1
) as well as discord.py
(v2.3.2
).
- Clone the repo:
git clone https://github.com/FlyingFathead/DiscordBot-OpenAI-API/
=>cd DiscordBot-OpenAI-API/
- Install the prerequisites:
pip install -r requirements.txt
or:
discord.py==2.3.2
configparser>=6.0.0
httpx>=0.26.0
openai>=1.6.1
transformers>=4.36.2
requests>=2.31.0
- Get your Discord bot token: 1) Go the Discord Developer Portal => select your bot 2) Click on "Reset Token" to generate a new one, use that.
- Set your Discord bot token: either set it to the environment variable
DISCORD_BOT_TOKEN
or place it in the program directory asdiscord_bot_token.txt
. - When setting up the bot, remember to activate this option with your bot in order for it to be able to receive messages (in the Discord
Bot
settings tab in the Developer Portal):Message Content Intent Required for your bot to receive message content in most messages. NOTE: Once your bot reaches 100 or more servers, this will require verification and approval. Read more here
- Get your OpenAI API token and set it to either
OPENAI_API_KEY
environment variable or intoapi_key.txt
in the program directory. - Adjust your settings in the
config.ini
- Launch the bot with:
python main.py
- v0.14 - Various small fixes, not implemented in this version yet.
- v0.08 -
Timezone
added to options. - v0.07 - Chat history trimming adjusted, hello message on join; still WIP!
- v0.05 - Well, it works. Initial early release. Expect nothing much.
- All contributions appreciated! Feel free to also post any bugs and other issues on the repo's "Issues" page. However, please do note the heavy WIP status of this project. No warranties!
- Written by FlyingFathead
- Digital ghost code by ChaosWhisperer