#Passing variables though message components

1 messages · Page 1 of 1 (latest)

hoary jacinth
#

basically i have a command that displays certain player's info via their discord ID with a user mention argument.
it works fine, but when i add a button for displaying other information on the message returned in the original command, i obviously can't access the variable that was made inside the slashcommand task inside the button task.
how would i get the ID of the player mentioned in the button component task and even in more button components?

cobalt maple
#

You can add the userId to the custom id of the button, similar to this:

// …
.WithButton("Do something", $"my.button.action:{userId}", ButtonStyle.Primary)
// …

Then in your interaction handler you can use some basic regex:

[ComponentInteraction("my.button.action:*", ignoreGroupNames: true)]
    public async Task The ButtonHandler(string userId)
    {
        // implementation …

    }
hoary jacinth
#

will try it out