Documentación / Developers / Cookbook / 10) Role menu (dropdown)
BuildSDK 0.10.1

10) Role menu (dropdown)

These docs are public. To publish a plugin you need a YourBot account: sign in to open the Dev Portal.

Admin runs /role-menu, gets a dropdown listing self-assignable roles.

from yourbot_sdk import ActionRow, SelectMenu, SelectOption

@plugin.on_slash_command("role-menu")
def menu(ctx: Context, event: dict):
    roles = ctx.kv.get("self_roles") or []  # list of {"id": "...", "label": "..."}
    options = [SelectOption(label=r["label"], value=r["id"]) for r in roles]
    ctx.interaction.respond(content="Pick your role(s):",
        components=[ActionRow(SelectMenu("pick_role", options, min_values=1, max_values=len(options)))])

@plugin.on_component("pick_role")
def picked(ctx: Context, event: dict):
    selected_ids = event.get("values") or []
    for rid in selected_ids:
        ctx.discord.add_role(user_id=event["user_id"], role_id=rid)
    ctx.interaction.respond(content="Roles updated.", ephemeral=True)
YourBot docs Reference tables are generated from the code that is running. Ask in Discord Suggest a correction