-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from rodonguyen/dev-discord-bot
Prototype a POC Discordbot using Interactions.py
- Loading branch information
Showing
6 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.