Remora.Discord.Gateway 10.1.1 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET 5.0 .NET Standard 2.1
Install-Package Remora.Discord.Gateway -Version 10.1.1
dotnet add package Remora.Discord.Gateway --version 10.1.1
<PackageReference Include="Remora.Discord.Gateway" Version="10.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Remora.Discord.Gateway --version 10.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Remora.Discord.Gateway, 10.1.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Remora.Discord.Gateway as a Cake Addin
#addin nuget:?package=Remora.Discord.Gateway&version=10.1.1

// Install Remora.Discord.Gateway as a Cake Tool
#tool nuget:?package=Remora.Discord.Gateway&version=10.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Remora.Discord.Gateway

This package provides a fully-featured implementation of a Discord gateway client, complete with resume capabilities and user-facing events.

Structure

The package consists of two main parts - the client itself, and the event dispatch system. The latter will be familiar to users of the mediator pattern, wherein an intermediate type handles communication between separate objects; in Remora.Discord.Gateway's case, all incoming Discord events are dispatched and executed concurrently with each other, and the user may register responders to handle these events.

Provided you yourself do not inject services with a shared mutable state, all responders are thread-safe and do not require additional synchronization through semaphores or mutexes.

The client is a singleton service by design.

Usage

First and foremost, the gateway client must be registered with your dependency injection container.

services.AddDiscordGateway(serviceProvider => GetTokenFromSomewhere(serviceProvider));

Two things to note:

  • You are not required to call any other methods from dependency libraries (such as Remora.Discord.API) - this call takes care of all transitive dependencies itself.
  • You must, at this point, provide a way to access your bot's token in plain text. This access only happens after the container is constructed, and an API instance is requested, so you have access to the built container.

After this point, you may inject the gateway client into your own services. In order to connect and start dispatching events, you must call RunAsync somewhere, and subsequently either await the task directly or store it for later use. This task represents the entire lifetime of the gateway client, and will run until you explicitly request its termination via the cancellation token passed to this method.

If you wish to explicitly send a gateway command (for example, to update presence information), you may do so via the SubmitCommand method on the client. Note that no validations are performed on this command, so you can cause unexpected termination of your session if the data is malformed or inappropriate for the current state of the client.

Responders - the types which react to and handle incoming events - are created by declaring a class that implements one or more instances of the IResponder<T> interface, and then registering these types with the service container.

public class MyResponder : IResponder<IMessageCreate>
{
    public async Task<Result> RespondAsync
    (
        IMessageCreate gatewayEvent,
        CancellationToken ct = default
    )
    {
        // ...
    }
}

...

services.AddResponder<MyResponder>();

There are no restrictions placed on how long an individual responder may run, but you should strive to keep it short in order to avoid thread pool exhaustion.

Responders have no guarantees related to sequential execution, but you are able to sort them into one of three "groups", which do run sequentially to one another.

services.AddResponder<MyResponder>(ResponderGroup.Early); // executes before...
services.AddResponder<MyResponder>(ResponderGroup.Normal); // executes before...
services.AddResponder<MyResponder>(ResponderGroup.Late);

This is useful in cases where two responders to the same event depend on each other in some way.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Remora.Discord.Gateway:

Package Downloads
Remora.Discord.Commands The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Glue code for using Remora.Commands with Remora.Discord

Remora.Discord.Hosting The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Implementation of a hosted Discord gateway service for the .NET Generic Host

Remora.Discord.Caching The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Caching implementations of Remora.Discord's services

Remora.Discord.Interactivity The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Framework for using Discord's interaction-driven message components

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
10.1.1 57 6/23/2022
10.1.0 101 6/20/2022
10.0.0 92 6/19/2022
9.0.0 156 6/18/2022
8.1.5 114 6/14/2022
8.1.4 163 6/8/2022
8.1.3 169 6/3/2022
8.1.2 240 5/25/2022
8.1.1 167 5/23/2022
8.1.0 290 5/15/2022
8.0.6 194 5/10/2022
8.0.5 360 5/3/2022
8.0.4 329 4/25/2022
8.0.3 268 4/18/2022
8.0.2 338 4/2/2022
8.0.1 225 4/2/2022
8.0.0 396 3/21/2022
7.2.0 177 3/17/2022
7.1.0 140 3/15/2022
7.0.1 661 2/20/2022
7.0.0 182 2/19/2022
7.0.0-rc1 60 2/14/2022
6.2.10 184 2/14/2022
6.2.9 482 1/27/2022
6.2.7 731 1/11/2022
6.2.6 8,955 1/2/2022
6.2.5 503 12/23/2021
6.2.4 234 12/21/2021
6.2.3 423 12/16/2021
6.2.2 269 12/11/2021
6.2.1 317 12/5/2021
6.2.0 2,043 11/26/2021
6.1.0 6,001 11/24/2021
6.0.0 1,197 11/20/2021
5.0.4 974 11/9/2021
5.0.3 532 11/6/2021
5.0.2 658 10/30/2021
5.0.1 462 10/28/2021
5.0.0 1,708 10/15/2021
4.0.15 1,022 10/7/2021
4.0.13 548 10/3/2021
4.0.12 426 10/2/2021
4.0.11 430 9/30/2021
4.0.10 608 9/26/2021
4.0.9 413 9/24/2021
4.0.8 435 9/23/2021
4.0.7 423 9/16/2021
4.0.6 488 9/15/2021
4.0.5 549 9/8/2021
4.0.4 1,501 9/4/2021
4.0.3 1,849 8/21/2021
4.0.2 508 8/18/2021
4.0.1 748 8/12/2021
4.0.0 343 8/11/2021
3.5.8 526 8/11/2021
3.5.7 548 8/2/2021
3.5.6 603 8/2/2021
3.5.5 701 7/31/2021
3.5.4 510 7/29/2021
3.5.3 457 7/28/2021
3.5.2 375 7/28/2021
3.5.1 588 7/22/2021
3.5.0 478 7/17/2021
3.4.6 437 7/14/2021
3.4.5 516 7/12/2021
3.4.4 428 7/11/2021
3.4.3 429 7/5/2021
3.4.2 447 7/3/2021
3.4.1 397 7/1/2021
3.4.0 636 6/14/2021
3.3.1 334 6/10/2021
3.3.1-beta2 335 5/30/2021
3.3.1-beta1 477 5/28/2021
3.3.0 400 5/23/2021
3.2.1 475 5/20/2021
3.2.0 543 5/4/2021
3.1.14 411 4/22/2021
3.1.13 407 4/15/2021
3.1.12 505 4/10/2021
3.1.11 489 4/5/2021
3.1.10 480 4/4/2021
3.1.9 748 3/28/2021
3.1.8 769 3/25/2021
3.1.7 386 3/25/2021
3.1.6 614 3/16/2021
3.1.5 454 3/14/2021
3.1.4 392 3/13/2021
3.1.3 413 3/11/2021
3.1.2 537 3/6/2021
3.1.1 440 3/1/2021
3.1.0 482 3/1/2021
3.0.7 468 2/28/2021
3.0.6 406 2/23/2021
3.0.5 589 2/22/2021
3.0.4 400 2/21/2021
3.0.3 296 2/16/2021
3.0.2 462 2/13/2021
3.0.1 523 2/11/2021
3.0.0 427 2/10/2021
2.2.3 391 2/6/2021
2.2.2 404 2/5/2021
2.2.1 400 1/29/2021
2.2.0 389 1/27/2021
2.1.1 520 1/21/2021
2.1.0 454 1/17/2021
2.0.1 446 1/10/2021
2.0.0 455 1/10/2021
1.1.2 471 1/9/2021
1.1.1 545 12/31/2020
1.1.0 445 12/27/2020
1.0.1 734 12/25/2020
1.0.0 408 12/25/2020
1.0.0-beta9 285 12/10/2020
1.0.0-beta8 319 11/26/2020
1.0.0-beta7 281 11/15/2020
1.0.0-beta6 299 11/14/2020
1.0.0-beta5 321 11/8/2020
1.0.0-beta4 303 11/8/2020
1.0.0-beta3 236 10/17/2020
1.0.0-beta2 266 10/6/2020
1.0.0-beta11 276 12/23/2020
1.0.0-beta10 301 12/18/2020
1.0.0-beta1 249 10/6/2020
1.0.0-alpha1 240 9/27/2020

Update dependencies.