Add chat feature to discord_bot example (#643)
This commit is contained in:
@@ -53,6 +53,10 @@ python -m embedchain.bots.discord --include-question
|
|||||||
```text
|
```text
|
||||||
/query <question>
|
/query <question>
|
||||||
```
|
```
|
||||||
|
- You can chat with the bot using the slash command:
|
||||||
|
```text
|
||||||
|
/chat <question>
|
||||||
|
```
|
||||||
📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`.
|
📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`.
|
||||||
|
|
||||||
🎉 Happy Chatting! 🎉
|
🎉 Happy Chatting! 🎉
|
||||||
|
|||||||
@@ -48,13 +48,24 @@ async def add(ctx, data_type: str, *, url_or_text: str):
|
|||||||
async def query(ctx, *, question: str):
|
async def query(ctx, *, question: str):
|
||||||
print(f"User: {ctx.author.name}, Query: {question}")
|
print(f"User: {ctx.author.name}, Query: {question}")
|
||||||
try:
|
try:
|
||||||
response = chat_bot.chat(question)
|
response = chat_bot.query(question)
|
||||||
await send_response(ctx, response)
|
await send_response(ctx, response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await send_response(ctx, "An error occurred. Please try again!")
|
await send_response(ctx, "An error occurred. Please try again!")
|
||||||
print("Error occurred during 'query' command:", e)
|
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):
|
async def send_response(ctx, message):
|
||||||
if ctx.guild is None:
|
if ctx.guild is None:
|
||||||
await ctx.send(message)
|
await ctx.send(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user