HelperLib 1.3.0

dotnet add package HelperLib --version 1.3.0
                    
NuGet\Install-Package HelperLib -Version 1.3.0
                    
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="HelperLib" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HelperLib" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="HelperLib" />
                    
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 HelperLib --version 1.3.0
                    
#r "nuget: HelperLib, 1.3.0"
                    
#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.
#:package HelperLib@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HelperLib&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=HelperLib&version=1.3.0
                    
Install as a Cake Tool

HelperLib

HelperLib is a small utility library for Discord bots built with Discord.NET. It provides convenience helpers for mentions, embeds, guild lookups, role checks, command preconditions, and basic reconnect handling.

Current version: 1.3.0

Target framework: .NET 10

Versioning

Starting with 1.3.0, this project follows semantic versioning:

  • MAJOR changes for breaking public API or runtime requirements.
  • MINOR changes for backward-compatible features, behavior fixes, and new helpers.
  • PATCH changes for backward-compatible bug fixes, documentation, or test-only changes.

Breaking changes must be listed in the changelog below.

Changelog

1.3.0

Released: in progress

Changes:

  • Updated the library target framework to .NET 10.
  • Updated Discord.NET packages to 3.19.1.
  • Added an xUnit test project with coverage collection.
  • Added tests for mention parsing/formatting, embed send helpers, IonicHelper, ReliabilityService, RequireRoleAttribute, and GuildUsersResult.
  • Improved IonicHelper testability with internal seams for reconnect timing and lookup logic. Public initialization APIs are unchanged.
  • Improved ReliabilityService testability with internal injectable timing/restart/termination seams. Public constructor behavior is preserved.
  • Fixed IonicHelper.HasRolesAll so it now checks that the user has every requested role.
  • Fixed reconnect timeout cancellation handling so stale disconnect checks do not continue after reconnect.
  • Added GetGuildUserAsync for cache-first guild user lookup with REST fallback.

Breaking changes:

  • Runtime requirement changed from .NET 9 to .NET 10. Consumers must target a compatible framework.

Non-breaking public API notes:

  • Bot initialization through IonicHelper did not change:
var helper = new IonicHelper(token, defaultGuildId);
await helper.RunAsync(config, logger);
  • The public IonicHelper(string token, ulong? defaultGuildId = null) constructor is still available.
  • The public RunAsync(DiscordSocketConfig config, Func<LogMessage, Task> logger) method is still available.
  • Existing static lookup helpers such as GetGuild, GetTextChannel, GetRole, GetGuildAdmins, and role-check helpers remain available.

Behavior changes:

  • HasRolesAll(user, roleIds) now means "the user has all requested role ids." Previously it could return true when all of the user's roles were inside the requested set, even if the user was missing some requested roles.

Features

  • IonicHelper: Common helpers for a running DiscordSocketClient, including guild/channel/role lookups, guild user enumeration, role checks, cancellation token access, and simple reconnect handling.
  • Services.ReliabilityService: Reconnect/reset strategy for DiscordSocketClient.
  • Util.MentionUtils: Create and parse Discord mentions for users, channels, and roles.
  • Util.Extensions: Extension helpers for sending Embed/EmbedBuilder and sending images from URLs.
  • Preconditions.RequireRoleAttribute: Discord.Commands precondition attribute that restricts usage to a role id.
  • Models.GuildUsersResult: Lightweight result type for guild user enumeration.

Quick Start

Add the project or compiled DLL to your bot solution.

Simple start using IonicHelper:

var token = "YOUR_BOT_TOKEN";
var defaultGuildId = 123456789012345678UL;

var helper = new IonicHelper(token, defaultGuildId);

await helper.RunAsync(
    new DiscordSocketConfig(),
    message =>
    {
        Console.WriteLine(message);
        return Task.CompletedTask;
    });

The IonicHelper static helpers expect RunAsync to have initialized the static DiscordSocketClient.

Examples

Parse a user mention:

if (MentionUtils.TryParseUser("<@!123456>", out var userId))
{
    // use userId
}

Send an embed:

await textChannel.SendEmbedAsync(
    new EmbedBuilder()
        .WithTitle("Hello")
        .Build());

Require a role on a command:

[RequireRole(123456789012345678)]
public async Task MyCommand()
{
    // command body
}

Check roles:

if (IonicHelper.HasRolesAll(guildUser, moderatorRoleId, trustedRoleId))
{
    // user has both roles
}

Fetch a guild user with REST fallback:

var user = await IonicHelper.GetGuildUserAsync(defaultGuildId, userId);

Notes

  • HelperLib is a convenience layer over Discord.NET.
  • IonicHelper stores a static DiscordSocketClient, so static lookup helpers require the client to be initialized.
  • Reconnect handling is intentionally simple. If reset attempts fail or time out, the process can exit so an external host can restart the bot.

Testing

Run the test suite:

dotnet test HelperLib.Tests\HelperLib.Tests.csproj --no-restore -v q

Run tests with coverage:

dotnet test HelperLib.Tests\HelperLib.Tests.csproj --no-restore --collect:"XPlat Code Coverage" -v q

Contributing

Keep changes focused and add tests for behavior changes.

License

Add the project license here.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 490 4/12/2026
1.2.0 351 3/28/2026
1.1.3 173 3/28/2026
1.1.2 363 7/7/2024
1.1.1 229 5/2/2024
1.1.0 208 5/2/2024
1.0.11 276 4/15/2024
1.0.10 265 4/11/2024
1.0.9 387 7/22/2023
1.0.8 249 7/22/2023
1.0.7 264 7/20/2023
1.0.6 263 7/16/2023
1.0.5 555 7/29/2022
1.0.4 538 7/29/2022
1.0.3 627 1/17/2022
1.0.2 564 1/17/2022
1.0.1 479 12/26/2021
1.0.0 473 12/25/2021