-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
token=MTA5MDc4NTA4MjgyODE0MDU4NA.G8sE-m.nqCM23WjchWXcsvAk7420V5kad9UYImZ_Rn4W4 | ||
api_key=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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
token={Your Discord bot token} | ||
api_key={Your ChatGPT API Key} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Discord-ChatGPT-Bot | ||
|
||
This Python Discord bot uses the ChatGPT 3.5 Turbo API to generate text and images based on user input. | ||
|
||
**Prerequisites** </br> | ||
You need to have your Discord bot set up on the Discord Developer Portal with all intents and necessary permissions enabled, and your OpenAI API key ready. | ||
|
||
You can create and configure a Discord bot at https://discord.com/developers/applications, and you can find your personal OpenAI API key at https://platform.openai.com/account/api-keys. | ||
|
||
**Installation** </br> | ||
1. Clone this repository: </br> | ||
`git clone https://github.com/yourusername/your-discord-bot.git` | ||
2. Change into the cloned directory: </br> | ||
`cd your-discord-bot` | ||
3. Install the required dependencies: </br> | ||
`pip install -r requirements.txt` | ||
4. Create a .env file with your Discord bot token and ChatGPT API key: </br> | ||
`DISCORD_TOKEN=<your-discord-bot-token>` </br> | ||
`OPENAI_API_KEY=<your-openai-api-key>` </br> | ||
Make sure to reference the .env.example file for guidance. | ||
5. Run the bot: </br> | ||
`python bot.py` | ||
|
||
**Usage** </br> | ||
This bot's prefix for text is "!" and its prefix for images is "/". </br> | ||
Use the following commands to interact with the bot: | ||
|
||
!chat [prompt] - Generates a response to the given prompt using ChatGPT 3.5 Turbo API.</br> | ||
|
||
/image [prompt] - Generates and sends an image based on the given prompt using ChatGPT 3.5 Turbo API.</br> | ||
|
||
<img width="640" alt="Screenshot 2023-03-29 at 8 12 26 PM" src="https://user-images.githubusercontent.com/49298134/228702804-1f347893-3baa-4745-94e6-581c62726dc1.png"> | ||
|
||
<img width="612" alt="Screenshot 2023-03-30 at 11 26 17 AM" src="https://user-images.githubusercontent.com/49298134/228902473-62a8bc12-5ab4-484a-b468-9c96bd88e4a3.png"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import discord | ||
import responses | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
|
||
def configure(): | ||
load_dotenv() | ||
|
||
|
||
async def send_message(message, user_message, is_private): | ||
try: | ||
if not is_private: | ||
response = responses.get_response(user_message) | ||
else: | ||
response = responses.get_response_private(user_message) | ||
await message.author.send(response) if is_private else await message.channel.send(response) | ||
|
||
except Exception as e: | ||
print(e) | ||
|
||
|
||
def run_discord_bot(): | ||
configure() | ||
token = os.getenv('token') | ||
intents = discord.Intents.default() | ||
intents.message_content = True | ||
client = discord.Client(intents=intents) | ||
|
||
@client.event | ||
async def on_ready(): | ||
print(f'{client.user} is now running!') | ||
|
||
@client.event | ||
async def on_message(message): | ||
if message.author == client.user: | ||
return | ||
|
||
username = str(message.author) | ||
user_message = str(message.content) | ||
channel = str(message.channel.type) | ||
|
||
print(f'{username} said: "{user_message}" ({channel})') | ||
|
||
if channel == "private": | ||
await send_message(message, user_message, is_private=True) | ||
else: | ||
await send_message(message, user_message, is_private=False) | ||
|
||
client.run(token) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import bot | ||
from dotenv import load_dotenv | ||
|
||
|
||
def configure(): | ||
load_dotenv() | ||
|
||
|
||
if __name__ == '__main__': | ||
configure() | ||
bot.run_discord_bot() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.