d4n3436 / Fergun.Interactive

An addon that provides interactive functionality to Discord commands.
MIT License
31 stars 5 forks source link

Possibility to discern an interaction meant for InteractivityService #7

Closed MathieuDR closed 2 years ago

MathieuDR commented 2 years ago

While using Discord.Net.Labs I have my own event handler when an interaction is created.

I also want to send a response when I cannot find a correct handler to the user, however I have no clear cut solution to ID an interaction meant for this library (eg the paginator).

It would be nice to have a possibility for this.

d4n3436 commented 2 years ago

There's already a way to do this, using the Callbacks property.

Callbacks is a dictionary containing the IDs of the messages and their callbacks.

So, to check if an interaction is meant for InteractiveService you simply use ContainsKey() passing the ID of the message the interaction comes from.

Example:

private async Task InteractionCreated(SocketInteraction interaction)
{
    if (interaction is SocketMessageComponent messageComponent && !Interactive.Callbacks.ContainsKey(messageComponent.Message.Id))
    {
        await interaction.RespondAsync("Cannot find a handler for this interaction.", ephemeral: true);
    }
}

This only works with component interactions (paginators and selections) and won't work with other type of interactions.

MathieuDR commented 2 years ago

Thanks, I did not see this