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

Issue

This Content is from Stack Overflow. Question asked by Leums

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.")



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?