Browse Source

feat: Add help text response for DMs and mentions

This commit introduces a new feature where the bot will respond with
pre-formatted help text if it receives a direct message or is mentioned
in a channel. This aims to guide users to use the /search and /mode
slash commands, preventing frustration when trying to interact with the
bot through other means.
mitch donaberger 1 month ago
parent
commit
07efaf481a
1 changed files with 21 additions and 0 deletions
  1. 21 0
      bot.py

+ 21 - 0
bot.py

@@ -22,6 +22,13 @@ user_modes = {}
 DEFAULT_OPTIMIZATION_MODE = "balanced"
 DEFAULT_FOCUS_MODE = "webSearch"
 
+HELP_TEXT = """
+Hello! I'm Perplexica Bot.
+To use me, please type `/search <your query>` to search for information.
+You can also change your search effort mode using `/mode`.
+I don't respond to direct messages or mentions outside of these commands.
+"""
+
 # --- Discord Bot Setup ---
 intents = discord.Intents.default()
 intents.message_content = True
@@ -35,6 +42,20 @@ async def on_ready():
     await tree.sync()
     print("Slash commands synced.")
 
+@client.event
+async def on_message(message: discord.Message):
+    """Event handler for when a message is sent."""
+    # Ignore messages from the bot itself
+    if message.author == client.user:
+        return
+
+    # Respond to DMs or mentions
+    if isinstance(message.channel, discord.DMChannel) or client.user.mentioned_in(message):
+        await message.channel.send(HELP_TEXT)
+        return
+
+    await client.process_commands(message) # Important! Allows other commands to be processed.
+
 # --- Slash Commands ---
 
 @tree.command(name="search", description="Search with Perplexica")