How can I get the option object from a command for a button response?

Viewed 34

The idea of this command is to send a message in a specific channel from an administration channel.

I'm trying to get the channel object from the "send" command (l.20/35) in the "send_button_response" function (l.39).

Thanks in advance

send_button = interactions.Button(
    custom_id = "send_button_id",
    label = "Send",
    style = interactions.ButtonStyle.SUCCESS
)
cancel_button = interactions.Button(
    custom_id = "cancel_button_id",
    label = "Cancel",
    style = interactions.ButtonStyle.DANGER
)
row_buttons = interactions.ActionRow(
    components = [send_button, cancel_button]
)

@bot.command(
    name = "send",
    description = "Send the message in the channel of your choice",
    scope = [my scope],
    options = [
        interactions.Option(
            name = "channel",
            description = "The channel in which to send the message",
            type = interactions.OptionType.CHANNEL,
            channel_types = [0],
            required = True
        ),
        interactions.Option(
            name = "message",
            description = "The message to send",
            type = interactions.OptionType.STRING,
            required = True
        )
    ]
)
async def send(ctx, channel, message):
    await ctx.send(content = message, components = row_buttons, ephemeral = True)

@bot.component("send_button_id")
async def send_button_response(ctx):
    # here the missing instruction to send the message to the specified channel
    await ctx.edit(content = "Your message has been successfully sent to the [channel] channel.")
0 Answers
Related