import os
import discord
from discord.ext import commands
import openai
Set up your OpenAI API key
openai.api_key = ""
Initialize the Discord bot
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
bot = commands.Bot(command_prefix='!', intents=intents)
Define privileged_users (replace with actual user IDs)
privileged_users = ["Deadsg", "user_id_2"]
Define event handler for when the bot is ready
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
Define event handler for when a message is received
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('!ask_gpt3'):
# Define a prompt to send to ChatGPT
prompt = "Translate the following English text to French:"
# Extract user query from message
user_query = message.content[len('!ask_gpt3 '):]
# Combine prompt and user query
full_prompt = f"{prompt} {user_query}"
# Use the model to get a response from ChatGPT
response = openai.Completion.create(
engine="davinci", # Choose your preferred model here
prompt=full_prompt,
max_tokens=50 # Adjust as needed
)
# Extract the answer from the response
answer = response.choices[0].text.strip()
# Send the answer back to the Discord channel
await message.channel.send(answer)
token = ""
client = discord.Client()
Define intents
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
Create a bot instance with a command prefix
bot = commands.Bot(command_prefix='Ask ', intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
client.run(token)
Run the bot
bot.run('') # Replace with your bot token
import os
import discord
from discord.ext import commands
import openai
Set up your OpenAI API key
openai.api_key = ""
Initialize the Discord bot
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
bot = commands.Bot(command_prefix='!', intents=intents)
Define privileged_users (replace with actual user IDs)
privileged_users = ["Deadsg", "user_id_2"]
Define event handler for when the bot is ready
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
Define event handler for when a message is received
@bot.event
async def on_message(message):
if message.author == bot.user:
return
token = ""
client = discord.Client()
Define intents
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
Create a bot instance with a command prefix
bot = commands.Bot(command_prefix='Ask ', intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
client.run(token)
Run the bot
bot.run('') # Replace with your bot token