Open stefanlight8 opened 2 months ago
And so, let's think about it. Initially, the general concept should be that components always have a parent (command or view) and should be initialized through interaction.
from aurum.context import InteractionContext
from aurum.commands import SlashCommand
from aurum.components import Button, decorators
# or from aurum.components.decorators import button
class ButtonCommand(SlashCommand):
def __init__(self) -> None:
super().__init__("button", description="Get button")
@decorators.button(label="Magic", emoji="🪄") # or @button(label=...
async def magic_button(self, context: InteractionContext, button: Button) -> None:
await context.create_response("Woah, you clicked that button!", ephemeral=True)
async def callback(self, context: InteractionContext) -> None:
await context.create_response(components=[context.init_component(self.magic_button)]) # doubtful, but OK
Furthermore, the concept for objects is likely to be similar to that of commands, with a get_builder
function. I think it would be possible to return these to commands by implementing a proxy (CommandBuilder), thus avoiding unnecessary complexity in the code.
It's difficult.
we can command components initialize through metaclass automatically and just creating response with component=self.magic_button
I think, but that will be little difficult and add some complexity :b
but with the view – all the same way, because it's can't be an independent object without interaction.
beh
from aurum.context import InteractionContext
from aurum.commands import SlashCommand
from aurum.components import View, Button, decorators
class ButtonView(View):
@decorators.button(label="Magic", emoji="🪄")
async def magic_button(self, context: InteractionContext, button: Button) -> None:
await context.create_response("Woah, you clicked that button!", ephemeral=True)
class ButtonCommand(SlashCommand):
def __init__(self) -> None:
super().__init__("button", description="Get button")
async def callback(self, context: InteractionContext) -> None:
await context.create_response(components=context.init_view(ButtonView()))
https://discord.com/developers/docs/interactions/message-components#message-components