Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Discord bot conversational model integration #124

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions examples/discord-bot/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# TextBase Discord Bot

A Discord bot that leverages the OpenAI GPT-3 API to answer questions and engage in text-based conversations. You can add this bot to your Discord server and interact with it by mentioning the bot in a channel and asking your questions. The bot will respond with text generated by the GPT-3 model.

## Getting Started
Take a quick look at the youtube video to get a clear understanding - https://youtu.be/OkTw3LCIoQQ

To get started with the TextBase Discord Bot, follow these steps:

1. **Clone the Textbase Repository**

Clone the TextBase Discord Bot repository to your local machine using the following command:

```
git clone https://github.com/c0d3-br34k3r/textbase.git
```

2. **Set Up OpenAI API Key**

You need to obtain an API key from OpenAI to use this bot. Replace `openai.api_key` in the code with your API key.

```python
openai.api_key = "your_openai_api_key_here"
```

3. **Set Up Discord Bot Token**

You'll also need to create a Discord bot and obtain a token for it. Replace `token` in the code with your Discord bot token.

```python
token = "your_discord_bot_token_here"
```

4. **Install Dependencies**

Install the required Python libraries by running the following command:

```
pip install discord.py openai
```

5. **Run the Bot**

Run the bot using the following command:

```
python your_bot_filename.py
```

Replace `your_bot_filename.py` with the address of the main.py file under discord-bot folder containing the bot code.

6. **Invite the Bot to Your Server**

Create a Discord invite link for your bot and add it to your Discord server. Make sure to grant the bot necessary permissions to read and send messages in the channels where you want it to respond.

## Usage

Once the bot is added to your Discord server and running, you can interact with it by mentioning the bot and asking questions or providing prompts in a text channel. The bot will respond with text generated by the GPT-3 model.

For example, you can mention the bot in a message like this:

```
@TextBase What is the capital of France?
```

The bot will process your message, send it to the GPT-3 model, and reply with an answer.

## Customization

You can customize the bot's behavior by modifying the bot's code. For instance, you can change the GPT-3 model, adjust the temperature, or fine-tune the response settings according to your preferences.

## Dependencies

- [discord.py](https://github.com/Rapptz/discord.py): A Python library for interacting with the Discord API.
- [openai](https://github.com/openai/openai-python): Python library for accessing the OpenAI GPT-3 API.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
35 changes: 35 additions & 0 deletions examples/discord-bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# bot.py

import discord
import os
import openai

openai.api_key = "" #Give the OpenAI API key
token = "" #Give the Discord Bot API key

class MyClient(discord.Client):
async def on_ready(self):
print(f'Logged on as {self.user}!')

async def on_message(self, message):
print(f'Message from {message.author}: {message.content}')
if self.user!= message.author:
if self.user in message.mentions:
channel = message.channel
response = openai.Completion.create(
model="text-davinci-003",
prompt = message.content,
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
messageToSend = response.choices[0].text
await channel.send(messageToSend)

intents = discord.Intents.default()
intents.message_content = True

client = MyClient(intents=intents)
client.run(token)