#Idea Button Callback

1 messages · Page 1 of 1 (latest)

silent sapphire
#

Hello everyone,

I'm exploring ways to implement different callbacks for the same button functionality. Let me elaborate.

I've developed a view class to generate custom embeds, which I intend to use across multiple cogs for various purposes such as creating welcome messages, leave messages, and more. However, instead of duplicating the entire class just to modify the finish button behavior, I'm seeking a more efficient approach.

My current plan involves passing the callback function as an argument. Then, within the finish_callback method, I'll execute this function to dynamically change the view based on the provided functionality. Specifically, I'll pass the callback function as an argument, and then invoke it within the finish_callback method using await func(interaction).

I'm open to suggestions for better approaches or improvements. Any insights would be greatly appreciated!

#

update i cant pass the function as argument

#
class Bot_Embed_View(discord.ui.View):
    def __init__(self, bot, translator, author_id):
        super().__init__(timeout=None)
        self.bot: Lumabot = bot
        button_finish = discord.ui.Button(emoji="✅", style=discord.ButtonStyle.green)
        button_finish.callback = self.button_finish_callback
        self.add_item(button_finish)

        button_reset = discord.ui.Button(emoji="🔄", style=discord.ButtonStyle.grey)
        button_reset.callback = self.button_reset_callback
        self.add_item(button_reset)

        button_delete = discord.ui.Button(emoji="🗑️", style=discord.ButtonStyle.grey)
        button_delete.callback = self.button_delete_callback
        self.add_item(button_delete)

    async def button_finish_callback(self, interaction: discord.Interaction):
        pass
    async def button_reset_callback(self, interaction: discord.Interaction):
        pass
    async def button_delete_callback(self, interaction: discord.Interaction):
        pass
#
other file : 
    async def embed_callback(self, interaction: discord.Interaction):
        await interaction.reponse.edit_message(Bot_Embed_View(self.bot, translator, author_id)
#

any idea of how i can change those callback ?

unborn lava
#

Just change the name?

#

Or use on_interaction and use custome ids

silent sapphire
#

but i think i will just pass it as arg

#

it was not my favorite option but if it work it work