Home > Net >  button not removed from view when pressed
button not removed from view when pressed

Time:01-26

I am using discord.py and the pycord library to build a discord bot. I have a class called "menu" which contains a button called "btn", and I am trying to remove the button from the view when it is pressed, but it is not being removed. My code looks like this:

class menu(discord.ui.View):
def __init__(self):
    super().__init__()
    self.btn = skipbutton()
    self.add_item(self.btn)
async def interaction_check(self, interaction: discord.Interaction):
    self.remove_item(self.btn)

if i remove the item without using async def it will be removed but not when i use async it will not do anything and if i tried to add something before and after to print it will be printed before and after

CodePudding user response:

That's because you've only removed it from the view locally - you need to actually edit the message and updated it with the new view.

interaction.response.edit_message(view=self)

Check pycord's docs here on disabling buttons on press. Similar logic, but we're removing the button from the view rather than disabling it. But we still need to edit the message to register with Discord that it has changed.

  • Related