From 8e0f05055e2dfd76c06ad3565f9a3f68452ec620 Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Sun, 24 Sep 2023 22:19:59 +0530 Subject: [PATCH] Add chat feature to discord_bot example (#643) --- docs/examples/discord_bot.mdx | 4 ++++ examples/discord_bot/discord_bot.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/examples/discord_bot.mdx b/docs/examples/discord_bot.mdx index 200810e9..e23a672b 100644 --- a/docs/examples/discord_bot.mdx +++ b/docs/examples/discord_bot.mdx @@ -53,6 +53,10 @@ python -m embedchain.bots.discord --include-question ```text /query ``` +- You can chat with the bot using the slash command: +```text +/chat +``` 📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`. 🎉 Happy Chatting! 🎉 diff --git a/examples/discord_bot/discord_bot.py b/examples/discord_bot/discord_bot.py index c07868aa..c7bad268 100644 --- a/examples/discord_bot/discord_bot.py +++ b/examples/discord_bot/discord_bot.py @@ -48,13 +48,24 @@ async def add(ctx, data_type: str, *, url_or_text: str): async def query(ctx, *, question: str): print(f"User: {ctx.author.name}, Query: {question}") try: - response = chat_bot.chat(question) + response = chat_bot.query(question) await send_response(ctx, response) except Exception as e: await send_response(ctx, "An error occurred. Please try again!") print("Error occurred during 'query' command:", e) +@bot.command() +async def chat(ctx, *, question: str): + print(f"User: {ctx.author.name}, Query: {question}") + try: + response = chat_bot.chat(question) + await send_response(ctx, response) + except Exception as e: + await send_response(ctx, "An error occurred. Please try again!") + print("Error occurred during 'chat' command:", e) + + async def send_response(ctx, message): if ctx.guild is None: await ctx.send(message)