diff --git a/DSbot.py b/DSbot.py index 53f2ce2..11846e2 100644 --- a/DSbot.py +++ b/DSbot.py @@ -15,9 +15,9 @@ load_dotenv() # Configuration API_BASE_URL = os.getenv("API_BASE_URL") # Configure in .env -BEARER_TOKEN = os.getenv("BEARER_TOKEN") # Configure in .env +BEARER_TOKEN = os.getenv("BEARER_TOKEN") # Configure in .env DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") # Configure in .env -ALLOWED_CHANNELS = [123456789] # REPLACE WITH YOUR CHANNEL IDS +ALLOWED_CHANNELS = [123456789] # Replace with your channel IDs # UUID validation pattern UUID_PATTERN = re.compile(r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') @@ -34,6 +34,7 @@ class SearchResultsView(View): def __init__(self, results): super().__init__(timeout=60) self.results = results + self.original_message = None self.add_buttons() def add_buttons(self): @@ -50,6 +51,11 @@ class ResultButton(Button): self.item = item async def callback(self, interaction: discord.Interaction): + if self.view.original_message: + try: + await self.view.original_message.delete() + except (discord.NotFound, discord.Forbidden): + pass await self.show_addon_embed(interaction) async def show_addon_embed(self, interaction: discord.Interaction): @@ -110,13 +116,10 @@ async def on_message(message): if message.author == bot.user: return - # Channel check - # the below line will make it so the bot does not reply in DMs - # if message.channel.id not in ALLOWED_CHANNELS: + # Allow DMs and specified channels if not isinstance(message.channel, discord.DMChannel) and message.channel.id not in ALLOWED_CHANNELS: return - # Command prefix check if not message.content.startswith('!mpbot'): return @@ -175,7 +178,8 @@ async def perform_search(ctx, query): ) view = SearchResultsView(search_data) - await ctx.send(embed=embed, view=view) + sent_message = await ctx.send(embed=embed, view=view) + view.original_message = sent_message except requests.exceptions.HTTPError as e: embed = discord.Embed( @@ -256,4 +260,4 @@ async def process_uuid(ctx, uuid): await ctx.send(embed=embed, ephemeral=True) if __name__ == '__main__': - bot.run(DISCORD_TOKEN) + bot.run(DISCORD_TOKEN) \ No newline at end of file