Skip to content

Disable button once it's clicked #2229

Answered by csmir
frontez asked this question in Q&A
Discussion options

You must be logged in to vote
var builder = new ComponentBuilder();

var rows = ComponentBuilder.FromMessage(interaction as IComponentInteraction).Message).ActionRows;

for (int i = 0; i < rows.Count; i++)
{
    foreach (var component in rows[i].Components)
    {
        switch (component)
        {
            case ButtonComponent button:
                builder.WithButton(button.ToBuilder()
                    .WithDisabled(true), i);
                break;
            case SelectMenuComponent menu:
                builder.WithSelectMenu(menu.ToBuilder()
                    .WithDisabled(true), i);
                break;
        }
    }
}
await messageComponent.Message.ModifyAsync(x => x.Components = builder.Build());

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@frontez
Comment options

Answer selected by csmir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants