From ff4b3ce40bbe8d924bf5414f0cae8de7c224ae6a Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Mon, 8 Jun 2026 23:20:57 -0700 Subject: [PATCH 1/2] Create delete button for factoid call command --- modules/operation/factoids.py | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/operation/factoids.py b/modules/operation/factoids.py index c86d9961..c7c0ffd9 100644 --- a/modules/operation/factoids.py +++ b/modules/operation/factoids.py @@ -1039,7 +1039,15 @@ async def factoid_call_command( try: # define the message and send it - await interaction.response.send_message(content=content, embed=embed) + view = DeleteView(interaction.user.id) + + await interaction.response.send_message( + content=content, + embed=embed, + view=view, + ) + + view.message = await interaction.original_response() # log it in the logging channel with type info and generic content log_channel = configuration.get_config_entry( interaction.guild.id, "core_logging_channel" @@ -2834,3 +2842,39 @@ async def enable( await auxiliary.send_confirm_embed( message=f"`{factoid_name}` is now enabled", channel=ctx.channel ) + + +class DeleteView(discord.ui.View): + def __init__(self: Self, author_id: int) -> None: + super().__init__(timeout=60) + self.author_id = author_id + self.message: discord.Message | None = None + + async def on_timeout(self: Self) -> None: + """Is called after the timeout, with the goal of deleting the buttons from the message""" + + if self.message: + await self.message.edit(view=None) + + @discord.ui.button(label="Delete", style=discord.ButtonStyle.danger, emoji="🗑️") + async def delete_button( + self: Self, + interaction: discord.Interaction, + button: discord.ui.Button, + ) -> None: + """The function called when the delete button is pressed + + Args: + interaction (discord.Interaction): The interaction that pressed the button + button (discord.ui.Button): The button object itself + """ + + if interaction.user.id != self.author_id: + await interaction.response.send_message( + "Only the original caller can delete this message.", + ephemeral=True, + ) + return + + if interaction.message: + await interaction.message.delete() From a3fda7759b55c5846f81832082f408ceab2ca360 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Mon, 8 Jun 2026 23:25:55 -0700 Subject: [PATCH 2/2] Add docstring --- modules/operation/factoids.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/operation/factoids.py b/modules/operation/factoids.py index c7c0ffd9..008f8ecb 100644 --- a/modules/operation/factoids.py +++ b/modules/operation/factoids.py @@ -2845,6 +2845,12 @@ async def enable( class DeleteView(discord.ui.View): + """The class to hold the view for the delete button on /factoid call + + Args: + author_id (int): The ID of the author of the factoid + """ + def __init__(self: Self, author_id: int) -> None: super().__init__(timeout=60) self.author_id = author_id