Skip to content

Commit

Permalink
Merge pull request #9 from rodonguyen/dev-discord-bot
Browse files Browse the repository at this point in the history
Prototype a POC Discordbot using Interactions.py
  • Loading branch information
rodonguyen authored Feb 11, 2024
2 parents d078140 + e188b48 commit 9f53e32
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DISCORD_BOT_TOKEN="EXAMPLETokenTTTTT.Grz0fK.IUi1IONPcLHZsnyjROTt8lR2fuYCeK4grzRoSQ"

# THIS SHOULD BE ASSIGNED TO THE BOT'S `scopes` WHEN DEPLOYED
DISCORD_GUILD_ID="99999999999999999999999"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

bin
local_sandbox
66 changes: 66 additions & 0 deletions discord_bot/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
from dotenv import load_dotenv
import asyncio
import interactions

bot = interactions.Client(intents=interactions.Intents.DEFAULT)


@interactions.listen()
async def on_ready():
print("Ready")
print(f"This bot is owned by {bot.owner}")


@interactions.listen()
async def on_message_create(event):
print(f"message received: {event.message.content}")


@interactions.slash_command(name="my_short_command", description="My first command :)")
async def my_short_command(ctx: interactions.SlashContext):
await ctx.send("Hello World")


@interactions.slash_command(name="my_long_command", description="My second command :)")
async def my_long_command_function(ctx: interactions.SlashContext):
await ctx.defer() # use defer for time-comsuming commands
await asyncio.sleep(600)
await ctx.send("Hello World")


@interactions.slash_command(name="ask", description="Ask an LLM")
@interactions.slash_option(
name="model",
description="Choose an LLM model",
required=True,
opt_type=interactions.OptionType.STRING,
autocomplete=True,
)
async def ask_model(ctx: interactions.SlashContext, model: str):
await ctx.send(f"You asked model {model}")


@ask_model.autocomplete("model")
async def autocomplete(ctx: interactions.AutocompleteContext):
string_option_input = ctx.input_text # note: can be empty
print(f"input: {string_option_input}")
# you can use ctx.kwargs.get("name") to get the current state of other options - note they can be empty too
# make sure you respond within three seconds

choices = ["gpt3", "gpt4"]
filtered_choices = [choice for choice in choices if string_option_input in choice]

await ctx.send(
choices=[
{
"name": choice,
"value": choice,
}
for choice in filtered_choices
]
)


load_dotenv()
bot.start(os.getenv("DISCORD_BOT_TOKEN"))
54 changes: 54 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python = "^3.10"
litellm = {extras = ["proxy"], version = "^1.23.7"}
openai = "^1.11.1"
python-dotenv = "^1.0.1"
discord-py-interactions = "5.11.0"


[build-system]
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

0 comments on commit 9f53e32

Please sign in to comment.