#Very simple Discord bot. Kinda silly.

8 messages · Page 1 of 1 (latest)

elfin meteor
#

Friends and I had some fun conversing with this discord bot that calls the API. This one even takes reactions into account.

import os
import openai
import discord
from discord.ext import commands


openai.api_key = "YOUR_OPENAI_API_KEY_HERE"

start_sequence = "\nA:"
restart_sequence = "\n\nQ: "

################################
description = "A discord bot that uses GPT3 API to converse with users. "
TOKEN = "YOUR_DISCORD_API_KEY_HERE"
AUTHORIZED_CHANNEL = 0 # the channel where you want it to be restricted to.

intents = discord.Intents.default()
intents.members = True
Embed = discord.Embed

intents.reactions = True
intents.members = True
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix="$", description=description, intents=intents)
data = []

async def getBotResponse(question):
    response = openai.Completion.create(
        model="text-davinci-003",
        prompt=question,
        temperature=0.5,
         max_tokens=500,
    )
    return response["choices"][0]["text"]

# take into account users' reactions.
@client.event
async def on_raw_reaction_add(reaction):
    if (reaction.channel_id != AUTHORIZED_CHANNEL or reaction.user_id == client.user.id):
        return

    data.append(str(reaction.emoji))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    else:
        if message.channel.id == client.get_channel(AUTHORIZED_CHANNEL).id:
            async with message.channel.typing():
                data.append(message.content)
                lastMessages = "\n".join(data)
                response = await getBotResponse(lastMessages)
                await message.channel.send(response)

client.run(TOKEN)

Have fun!

sick oracle
#
import os
import openai
import discord
from discord.ext import commands


openai.api_key = "YOUR_OPENAI_API_KEY_HERE"

start_sequence = "\nA:"
restart_sequence = "\n\nQ: "

################################
description = "A discord bot that uses GPT3 API to converse with users. "
TOKEN = "YOUR_DISCORD_API_KEY_HERE"
AUTHORIZED_CHANNEL = 0 # the channel where you want it to be restricted to.

intents = discord.Intents.default()
intents.members = True
Embed = discord.Embed

intents.reactions = True
intents.members = True
client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix="$", description=description, intents=intents)
data = []

async def getBotResponse(question):
    response = openai.Completion.create(
        model="text-davinci-003",
        prompt=question,
        temperature=0.5,
         max_tokens=500,
    )
    return response["choices"][0]["text"]

# take into account users' reactions.
@client.event
async def on_raw_reaction_add(reaction):
    if (reaction.channel_id != AUTHORIZED_CHANNEL or reaction.user_id == client.user.id):
        return

    data.append(str(reaction.emoji))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    else:
        if message.channel.id == client.get_channel(AUTHORIZED_CHANNEL).id:
            async with message.channel.typing():
                data.append(message.content)
                lastMessages = "\n".join(data)
                response = await getBotResponse(lastMessages)
                await message.channel.send(response)

client.run(TOKEN)

Have fun!

#

Oops lol sorry

upper token
sick oracle
#

I'm learning myself and couldn't really tell you but if you wanted to try and learn you need a program to run code on like Python while you're on the python site there's a lot of basic information to get you started. Don't worry about learning everything all at once. There is a lot to learn. Just focus on one step at a time, for instance find Python's website and check it out and see what you learn right away. Like I said there's an infinite amount of knowledge on the subject I'm sure you're aware. When you get the program, you'll notice there's examples of code and such out there and usually there's a copy button right there with it somewhere. It's as easy as copy and paste as far as that goes. Just keep it simple and take it as slow as you can. You really don't want to rush into something like this. With all the possibilities you don't want to be in a hurry and overlook something that could possibly make things easier and go faster anyway. That being said, don't fall for the short gains. work on just learning what is posssible so you can see what your peak interest is and follow that path. Don't force yourself to learn something bcause it just looks cool. If you

sick oracle
upper token
#

thats true

#

i agree