How do I send a message with components (buttons) in discord_components? (discord.py)

Viewed 110

I can't figure out how to send a message without using ctx in the discord_components module, which extends discord.py for using buttons and other components. The fact is that in some guides uses ctx, but this does not suit me. I want to send a message according to the following principle: message.channel.send(embed=embed, components = components), but in this module (discord_components) I can't figure out why this doesn't work for me, and why I encounter the error "TypeError: send() got an unexpected keyword argument 'components'". I also tried using "send_component_msg" instead of "send", but I got the error " Attribute error: the "TextChannel" object does not have the "send_component_msg " attribute".

My code:

import discord
from discord_components import DiscordComponents, Button, Select, SelectOption

async def info(msg):
    embed = my_embed

    ...

    components = [Button(label = ""), Button(label = ""), Button(label = ""), Button(label = "")]
    try:
        await message.edit(embed = embed, components = components)
    except Exception:     
        message = await msg.channel.send_component_msg(embed=embed, components = components)
1 Answers

While I haven't used discord-components, I've used discord-py-slash-commands (https://discord-py-slash-command.readthedocs.io/en/latest/index.html), which has support for slash commands, buttons, and dropdown menus.

If you want to create a button using discord-py-slash-commands, it is pretty simple, here's the code:

buttons = [
     create_button(style=ButtonStyle.green, label=""),               
     create_button(style=ButtonStyle.green, label=""),
     create_button(style=ButtonStyle.green, label="")
]
action_row = create_actionrow(*buttons)
message = await ctx.send("hello there")

await message.edit(components=[action_row])

While this doesn't use discord-components, hopefully this helps.

Related