HelperLib 1.3.0
dotnet add package HelperLib --version 1.3.0
NuGet\Install-Package HelperLib -Version 1.3.0
<PackageReference Include="HelperLib" Version="1.3.0" />
<PackageVersion Include="HelperLib" Version="1.3.0" />
<PackageReference Include="HelperLib" />
paket add HelperLib --version 1.3.0
#r "nuget: HelperLib, 1.3.0"
#:package HelperLib@1.3.0
#addin nuget:?package=HelperLib&version=1.3.0
#tool nuget:?package=HelperLib&version=1.3.0
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:
MAJORchanges for breaking public API or runtime requirements.MINORchanges for backward-compatible features, behavior fixes, and new helpers.PATCHchanges 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, andGuildUsersResult. - Improved
IonicHelpertestability with internal seams for reconnect timing and lookup logic. Public initialization APIs are unchanged. - Improved
ReliabilityServicetestability with internal injectable timing/restart/termination seams. Public constructor behavior is preserved. - Fixed
IonicHelper.HasRolesAllso 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
GetGuildUserAsyncfor cache-first guild user lookup with REST fallback.
Breaking changes:
- Runtime requirement changed from
.NET 9to.NET 10. Consumers must target a compatible framework.
Non-breaking public API notes:
- Bot initialization through
IonicHelperdid 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 returntruewhen 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 runningDiscordSocketClient, including guild/channel/role lookups, guild user enumeration, role checks, cancellation token access, and simple reconnect handling.Services.ReliabilityService: Reconnect/reset strategy forDiscordSocketClient.Util.MentionUtils: Create and parse Discord mentions for users, channels, and roles.Util.Extensions: Extension helpers for sendingEmbed/EmbedBuilderand 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
HelperLibis a convenience layer over Discord.NET.IonicHelperstores a staticDiscordSocketClient, 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 | Versions 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. |
-
net10.0
- Discord.Net (>= 3.19.1)
- Discord.Net.Commands (>= 3.19.1)
- Discord.Net.WebSocket (>= 3.19.1)
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 |