Frequent questions

Before asking a question, look at these :)

Before, check you are using the correct library (discord-components not discord-buttons) and if your library is in the newest version.

Select is not visible.

Selects are currently (2021.6.5) visible only for beta users so normal users can't see the component. But you can see selects on ephemeral messages!

How to make buttons inline?

Your code must be something like

await <discord.abc.Messageable>.send(
    ...,
    components = [
        Button(...),
        Button(...),
        Button(...)
    ]
)

You should use a two-dimensional array like below to make buttons inline.

await <discord.abc.Messageable>.send(
    ...,
    components = [
        [
            Button(...),
            Button(...),
            Button(...)
        ]
    ]
)

How do I remove components?

Simple. Edit the message with parameter components set to [].

msg = await <discord.abc.Messageable>.send(
    ...,
    components = [
        Button(...),
        Button(...)
    ]
)
interaction = await <discord.ext.commands.Bot or discord.Client>.wait_for("button_click")

# First option
await msg.edit(components = [])
# Second option
await interaction.respond(
    type = 7,
    components = []
)

How do I ignore the interaction?

Just respond with the type 6 with no other parameters.

Handle all interactions

There is an event on_button_click. You can use this as normal events.

@<discord.ext.commands.Bot or discord.Client>.event
async def on_button_click(interaction):
    if interaction.responded:
        return
    await interaction.respond(content = "Yay!")

Using with cogs.

There is an example using cogs on GitHub.

TypeError: send() got an unexpected keyword argument 'components'

Have you put DiscordComponents(<discord.Client or discord.ext.commands.Bot>) inside the on_ready event?

Handle multiple clicks

You should put a while on discord.Client.wait_for to handle multiple clicks

while True:
    interaction = await <discord.ext.commands.Bot or discord.Client>.wait_for("button_click")
    await interaction.respond(content = "Wow")

Disabling the components for specific users

This is impossible but you can ignore the interaction by putting a check.

interaction = await <discord.ext.commands.Bot or discord.Client>.wait_for(
    "button_click",
    check = lambda i: i.user.id == "something"
)

Last updated