#Changing buttons view in miru

1 messages · Page 1 of 1 (latest)

tender cosmos
#

I'm trying to change buttons view using miru and lightlulb, but second button view do not works. Here is the code:

class ButtonView(miru.View):
    @miru.button(label="Dodaj uczestnika")
    async def btn_uczestnik(self, button: miru.Button, ctx:miru.Context):
        modal = NameModal(title="Dodaj uczestnika")
        # await ctx.edit_response("You clicked me")
        # await modal.send(ctx.interaction)
        await ctx.respond_with_modal(modal)
    @miru.button(label="Done")
    async def btn_done(self, button: miru.Button, ctx:miru.Context):
        view = ButtonView2(timeout=7200)
        await ctx.edit_response(components=view.build())
    
class ButtonView2(miru.View):
    @miru.button(label="Punkty")
    async def btn_punkty(self, button: miru.Button, ctx:miru.Context):
        print("Klik")
        modal = PunktModal(title="Podaj punktu")
        await ctx.respond_with_modal(modal)
velvet token
#

you never start the view (view.start())

#

also, not sure if there is probably a nicer way to replace view [cc @crude forum]

tender cosmos
#

o wait you are sure!

#

but with response how do i start it?

#

message = await ctx.edit_response(components=view.build())
await view.start(message)
?

velvet token
#

Yep

tender cosmos
#

thanks

velvet token
#

Np

#

@tender cosmos you probably want to stop the one you are replacing too

tender cosmos
#

yes, that would be nice too

tender cosmos
velvet token
#

im assuming just view.stop()

#

yep

tender cosmos
#

hmm... okey thanks

crude forum
#

Edit self

velvet token
#

@crude forum what about changing the buttons?

#

I have never used miru before, I'm asking for them :P

velvet token
#

Oh, must have missed that

#

@tender cosmos ^

#

Ty hyper!

crude forum
#

np

tender cosmos
#

Hmm okey, I'll try

#

Thanks

#

Okey that looks nicer I'll try it

tender cosmos
#

okey I think I doing something wrong
that is code from site

import random

import hikari
import miru

class EditView(miru.View):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        self.counter = 0

    @miru.button(label="Counter: 0", style=hikari.ButtonStyle.PRIMARY)
    async def counter_button(self, button: miru.Button, ctx: miru.ViewContext) -> None:
        self.counter += 1
        button.label = f"Counter: {self.counter}" # Change the property we want to edit
        await ctx.edit_response(components=view) # Re-send the view components

    @miru.button(label="Disable Menu", style=hikari.ButtonStyle.DANGER)
    async def disable_button(self, button: miru.Button, ctx: miru.ViewContext) -> None:
        for item in self.children:
            item.disabled = True # Disable all items attached to the view
        await ctx.edit_response(components=view)
        view.stop()
#

from where that variable view comes from?

        await ctx.edit_response(components=view)
        view.stop()
#

after disabling all items

velvet token
#

i think that should be self.stop()

tender cosmos
#

YES!

#

exactly

#

thanks