Skip to content

Selects#

Role Select

A Role Select

One of the most versatile message components provided by Discord are select menus. Users can select from channels, roles, users, or even custom options you provided! To get started, you first need to decide which type of select menu would best suit your needs.

To add a select menu to your view, you can use the decorator, or call the .add_item() method on a view and pass an instance of a select, similarly to buttons and other items.

Here's a short example showcasing how select menus work with the decorator syntax:

import hikari
import miru

class SelectView(miru.View):

    @miru.text_select(
        placeholder="Select me!",
        options=[
            miru.SelectOption(label="Option 1"),
            miru.SelectOption(label="Option 2"),
        ],
    )
    async def get_text(self, ctx: miru.ViewContext, select: miru.TextSelect) -> None:
        await ctx.respond(f"You've chosen {select.values[0]}!")

    @miru.user_select(placeholder="Select a user!")
    async def get_users(self, ctx: miru.ViewContext, select: miru.UserSelect) -> None:
        await ctx.respond(f"You've chosen {select.values[0].mention}!")

    # We can control how many options should be selected
    @miru.role_select(placeholder="Select 3-5 roles!", min_values=3, max_values=5)
    async def get_roles(self, ctx: miru.ViewContext, select: miru.RoleSelect) -> None:
        await ctx.respond(
            f"You've chosen {' '.join([r.mention for r in select.values])}!"
        )

    # A select where the user can only select text and announcement channels
    @miru.channel_select(
        placeholder="Select a text channel!",
        channel_types=[
            hikari.ChannelType.GUILD_TEXT,
            hikari.ChannelType.GUILD_NEWS
        ],
    )
    async def get_channels(self, ctx: miru.ViewContext, select: miru.ChannelSelect) -> None:
        await ctx.respond(f"You've chosen {select.values[0].mention}!")

Note

Select menus take up an entire row of a view, meaning that there can be a maximum of 5 per given message.