-
Can buttons be enabled dynamically?I want to send a message with both a SelectMenu and Button component. However I want to have the button be disabled until something in the SelectMenu is chosen. Once an option is selected, the button can be updated to be enabled without having to resend the message or edit it. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Well, yes but no. You can enable the button dynamically, but this will send a edit request to the api, so you would kind of edit the message. In the current version, this can be done by enabling all components in the message ...
# send the message
msg = await ctx.send("this is a test", components=[
# disable the button with disabled=True
Button("hmm", "test", disabled=True),
SelectMenu("test", [SelectOption("2", "test")])
])
# wait for a selection
select = await msg.wait_for("select", bot)
# respond to the selected menu
await select.respond()
# enable all components, setting the disable parameter to False,
# so for every component the `.disabled` property will be set to False, which means that they will be eanabled
await msg.disable_components(False) If you want to make sure only the first component (the button) is going to be enabled, you would need to create a workaround for that, because in the current version enabling/disabling components is limited to setting all components msg = await ctx.send("this is a test", components=[
# disable the button with disabled=True
Button("hmm", "test", disabled=True),
SelectMenu("test", [SelectOption("2", "test")])
])
# wait for a selection
select = await msg.wait_for("select", bot)
# respond to the selected menu
await select.respond()
# make a "backup" for the components
components = msg.components
# enable the first component
components[0].disabled = False
# edit the message and update the components
await msg.edit(components=components) If you're using the preview version you don't have to use the workaround for just enabling the first component # send the message
msg = await ctx.send("this is a test", components=[
# disable the button with disabled=True
Button("hmm", "test", disabled=True),
SelectMenu("test", [SelectOption("2", "test")])
])
# wait for a selection
select = await msg.wait_for("select", bot)
# respond to the selected menu
await sel.send()
# enable the first component
await msg.disable_component(0, False) |
Beta Was this translation helpful? Give feedback.
Well, yes but no. You can enable the button dynamically, but this will send a edit request to the api, so you would kind of edit the message.
In the current version, this can be done by enabling all components in the message