Fergun.Interactive 1.9.0-beta.1

This is a prerelease version of Fergun.Interactive.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Fergun.Interactive --version 1.9.0-beta.1
                    
NuGet\Install-Package Fergun.Interactive -Version 1.9.0-beta.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fergun.Interactive" Version="1.9.0-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fergun.Interactive" Version="1.9.0-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="Fergun.Interactive" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fergun.Interactive --version 1.9.0-beta.1
                    
#r "nuget: Fergun.Interactive, 1.9.0-beta.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Fergun.Interactive&version=1.9.0-beta.1&prerelease
                    
Install Fergun.Interactive as a Cake Addin
#tool nuget:?package=Fergun.Interactive&version=1.9.0-beta.1&prerelease
                    
Install Fergun.Interactive as a Cake Tool

Fergun.Interactive

License: MIT NuGet Discord

Fergun.Interactive is an addon that provides interactive functionality to Discord commands.

This is a fork of Discord.InteractivityAddon that adds several features, including more customization and support for interactions (buttons and select menus).

Features

  • Methods for sending and deleting a message after a timeout

  • Methods for receiving incoming messages, reactions, or interactions

  • Customizable paginator:

    • Uses pages that can be navigated through reactions or buttons
    • Supports button customization (emote, label, style, etc.)
    • Includes two types of paginators: static and lazy-loaded
    • Supports restricting usage to specific users
    • Provides canceled and timeout pages
    • Supports timeout and cancellation via a special option or cancellation token
    • Supports actions that are executed when a paginator stops, such as modifying/deleting the message or removing/disabling the reactions/components
    • Supports extension methods that can be used in any paginator builder
    • Supports custom paginators, inheriting from the Paginator and PaginatorBuilder classes
    • Allows jumping (skipping) to a specific page using message input or modals (more info here)
  • 🆕 Component paginator:

    • A new type of paginator separate from the regular ones, written from scratch with customization and flexibility in mind, with support for components V2
    • Information about its usage can be found here.
  • Customizable selection:

    • Uses a list of options for users to select from
    • Supports messages, reactions, buttons, and select menus
    • Supports restricting usage to specific users
    • Provides success, canceled, and timeout pages
    • Supports timeout and cancellation via a special option or cancellation token
    • Supports actions that are executed when a selection stops, such as modifying/deleting the message or removing/disabling the reactions/components
    • Supports extension methods that can be used in any selection builder
    • Fully generic, supports any type of option (by providing a string/emote converter for that type)
    • Supports custom selections, inheriting from the BaseSelection and BaseSelectionBuilder classes

Usage

  • Install via NuGet

  • Add the InteractiveService into your service provider:

using Fergun.Interactive;
...

var provider = new ServiceCollection()
    .AddSingleton(new InteractiveConfig { DefaultTimeout = TimeSpan.FromMinutes(5) }) // Optional config
    .AddSingleton<InteractiveService>()
    ...
  • Inject the service via DI (constructor/property injection).

Examples

The Example Bot contains multiple examples with comments. The modules are registered as slash commands.

Example modules:

Q&A

Q: Why the paginator/selection doesn't do anything after I press a reaction/button? / I'm getting an "A MessageReceived handler is blocking the gateway task." message in the console

A: You're blocking the gateway task with a method from the interactive service. Make sure your command is running in a different thread using RunMode.Async:

[Command("command", RunMode = RunMode.Async)]
public async Task Command()
...

Q: Why is my reaction/message to the paginator/selection not automatically deleted even if I specified to delete valid or invalid responses?

A: The bot doesn't have the ManageMessages permission in the channel you're using the paginator/selection. This is required to delete messages and reactions.

Q: When responding an interaction with a paginator/selection, Why does the response message have no components even if I specified to use buttons or select menus?

  • A: Your paginator only has one page. The library doesn't include components in this case.
  • A: You're not passing the correct response type. The default value is ChannelMessageWithSource, but if you've deferred the interaction, you'll have to use either DeferredChannelMessageWithSource (send a message) or DeferredUpdateMessage (update a message).

Q: How can I get the last interaction of a paginator/selection to use it elsewhere, eg. send a modal?

A: You can get the interaction that stopped the paginator/selection through the StopInteraction property in InteractiveMessageResult.

Note that this interaction will already be deferred by default (if nothing else has already been done to the interaction before, like update the message).

You can prevent the library from doing this by setting the following options in InteractiveConfig to false:

var collection = new ServiceCollection()
    ...
    .AddSingleton(new InteractiveConfig
    {
        DeferStopPaginatorInteractions = false,
        DeferStopSelectionInteractions = false
    })
    .AddSingleton<InteractiveService>()
    ...

Additions/Changes from Discord.InteractivityAddon (outdated)

  • Paginators now support buttons.

  • Selections now support buttons and select menus.

  • Merged MessageSelection and ReactionSelection into Selection.

  • Added EmoteConverter and StringConverter to SelectionBuilder. These properties are used to properly convert the generic options in the selection into the options that can be used to receive the incoming inputs, like messages (from StringConverter), reactions (from EmoteConverter), buttons and select menus (emotes and labels)

  • Added EqualityComparerto SelectionBuilder. This is used to determine there are no duplicate options.

  • Added EmoteSelectionBuilder and EmoteSelectionBuilder<TValue>, they are a variant of SelectionBuilder that uses emotes as input and provides overriden properties with default values, making them ready to use in selections using reactions and buttons.

  • Added InteractiveStatus to InteractiveResult, containing all the possible status of an interactive result.

  • In PaginatorBuilder, now Emotes, WithEmotes() and AddEmote() are named Options, WithOptions() and AddOption(), respectively.

  • In the methods that waits for a socket entity (NextMessageAsync, NextReactionAsync, etc.), now the bool parameter in action returns whether the entity passed the filter (the previous behavior was the same but inverted, not sure if this was intended).

  • Now the paginator/selection builders implement the fluent builder pattern using recursive generics. This makes creating custom builders much easier.

  • Now multiple input types (messages, reactions, buttons, etc.) can be used in a single paginator/selection.

  • Now SendPaginatorAsync() and SendSelectionAsync() returns an InteractiveMessageResult. This is the same as InteractiveResult but contains the message that has the paginator/selection.

  • Added a messageAction parameter to SendPaginatorAsync() and SendSelectionAsync(). This allows to execute any action after the message containing the paginator/selection is sent or modified.

  • Now the paginators don't reset their internal timeout timer when a valid input is received. This option can be enabled again using the resetTimeoutOnInput parameter.

  • Now SendPaginatorAsync() only sends a message and returns when a paginator with a single page is passed.

  • When using paginators/selections with reactions, now the process of adding the initial reactions will be canceled if the paginator/selection is canceled.

  • Added more post-execution actions to paginators and selections. Now it's possible to tell the paginator/selection to do the following after a cancellation/timeout (or a valid input in case of selections):

    • DeleteInput (remove the reactions/buttons/select menu from the message)
    • DisableInput (disable the buttons/select menu from the message)

    Plus the previously existing options:

    • ModifyMessage (Modifies the message to the Cancelled/Timeout/Success page)
    • DeleteMessage

    These options can also be combined, so you can modify the message and delete/disable the input. Note that using the option DeleteMessage will override any other option, and DeleteInput/DisableInput can't be used at the same time (for obvious reasons).

  • Now the incoming inputs (messages, reactions, interactions) are handled via callbacks. These callbacks are stored in a dictionary. This eliminates the need to subscribe to a local event handler each time an input is received, since now they are received in a single event handler, and also allows to cancel/remove/dispose any callback.

  • The following methods now wait for completion:

    • DelayedSendMessageAndDeleteAsync()
    • DelayedDeleteMessageAsync()
    • DelayedSendFileAndDeleteAsync()

    If you don't want to wait for completion, simply discard the Task:

    _ = Interactive.DelayedSendMessageAndDeleteAsync(...);
    
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Fergun.Interactive:

Repository Stars
fmbot-discord/fmbot
.fmbot is a social Discord bot that provides music statistics for you and your friends.
Version Downloads Last updated
1.9.0-beta.2 157 5/29/2025
1.9.0-beta.1 129 5/27/2025
1.8.3-dev3 462 5/9/2025
1.8.3-dev2 266 5/8/2025
1.8.1 4,280 11/23/2024
1.8.0 1,662 9/20/2024
1.7.7 3,469 5/28/2024
1.7.6 1,854 5/16/2024
1.7.5 3,648 1/21/2024
1.7.5-dev 295 1/4/2024
1.7.3 4,767 7/29/2023
1.7.2 1,516 6/14/2023
1.7.1 1,601 4/8/2023
1.7.0 244 4/7/2023
1.6.0 9,326 6/2/2022
1.5.4 2,506 4/9/2022
1.5.3 547 4/6/2022
1.5.0 1,370 3/24/2022
1.4.2 795 3/3/2022
1.4.1 1,305 1/25/2022
1.4.0 474 1/25/2022
1.4.0-pre 219 1/18/2022
1.3.0 547 12/19/2021
1.3.0-dev3 210 12/9/2021
1.3.0-dev 3,897 11/24/2021
1.2.0 484 9/19/2021
1.1.0 407 8/24/2021
1.0.1-dev 215 8/10/2021
1.0.0 392 8/10/2021