Okategoriserad

Skapa en Discord-bot som använder OpenAI för att generera svar på meddelanden med Python

Author

This article intends to explain how to create a simple Discord bot that replies as OpenAI’s chat would do. And gives you a walkthrough of containerizing the application.

Vad behöver du?

Let’s override the asynchronous function on_message, which is triggered when a message is sent to the channel you added to your discord bot.

Here we can explain the content and functionality of our new files, .env will hold the Discord and OpenAI tokens.

Now let’s explain Dockerfile, first, we’ll use python:3.8-slim-buster as the base image to build our container on, then set /bot as our working directory, copy bot the directory from the project root to the container and install the required dependencies:

Simple docker-compose.yml configuration with a single container which is built based on the instructions on Dockerfile:

Build the docker image and spin up the container:

docker-compose up --build -d

And now you have the OpenAI discord bot running in a container.

Låt oss börja bygga relationer

Kontakta oss

Låt oss arbeta tillsammans Låt oss arbeta tillsammans