new_componenthandler

Let's you create a new global component handler for a specific component id. Component ids are used in components to identify which component was used.

E.g your button has the custom_id "button" and the button was pressed, then the custom_id "button" will be registered in the INTERACTION_CREATE event.

But keep in mind this does not apply to text fields in modals. For modals the custom_id for the modal itself is fired and not any custom_id in the modals components.


Example

bot.new_eventlistener({
    Event = "MESSAGE_CREATE", 
    Callback = function(data)
        local is_bot = data.author.bot 
        if is_bot then return end 
        
        local channel_id = data.channel_id
        local example_component = {{
            type = components["Action Row"],
            components = {{
                type = components["Button"],
                label = "I'm a button",
                custom_id = "button_id",
                style = styles["Success"]
            }}
        }}
        -- Arguments which can be provided into the send_raw second arguments:
        --[[ local arguments = {
            components = example_component,
            content = "Hello", -- content is the raw conent so just a text,
            embeds = {}, -- table with embeds. Look in documentation to find out more about embeds
        
        --]]
        send_raw(channel_id, { components = example_component })
    end 
})

bot.new_componenthandler({
    Custom_id = "button_id",
    Callback  = function(info)
        local interaction_token = info.interaction_token
        local interaction_id = info.interaction_id
        update_message(interaction_id, interaction_token, { 
            content = "Button was pressed",
            components = {} -- remove the components from the text
        })
    end     
})

Last updated