How to create views

Md Shahriyar Alam

23 days ago

View is a collection of multiple components that work togather

Create a view

pyclass AgreeView(View):
  def __init__(self):
    self.agree = False # initialize agree with false
  
  @button(label="Yes", style="success")
  async def yes(self, interaction, button):
    await defer(interaction, action="update")
    respond_interaction(interaction, empty=True)

    self.agree = True # sets agree = True because yes button clicked
    self.stop() # stops the view when this button is pressed
    

  @button(label="No", style="danger")
  async def stopper(self, interaction, button):
    await defer(interaction, action="update")
    respond_interaction(interaction, components=None, content="Cancelled")

    self.stop() # stops the view when this button is pressed

view = CustomView()
respond_interaction(interaction, content="Do you agree?", components=view) # send the view

exit_code = await view.wait(scope=scope)  # wait untill the view is stopped

if exit_code == "timeout": # if the view times out
  set_error("Timeout")

After that you can access view.agree anywhere and execute code based on conditions

Need help?

If you still need any kind of help, have a suggestion for us or having a question in mind? Feel free to reach us out.

DiscordJoin support server
logoCustom Commands

#1 Custom commands discord bot available on the internet

stripe

Contact

20-22 Wenlock RoadEnglandN1 7GU

© WEiRDSOFT LTD. All rights reserved.