izolabella.Discord 7.0.2

.NET 6.0
dotnet add package izolabella.Discord --version 7.0.2
NuGet\Install-Package izolabella.Discord -Version 7.0.2
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="izolabella.Discord" Version="7.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add izolabella.Discord --version 7.0.2
#r "nuget: izolabella.Discord, 7.0.2"
#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 izolabella.Discord as a Cake Addin
#addin nuget:?package=izolabella.Discord&version=7.0.2

// Install izolabella.Discord as a Cake Tool
#tool nuget:?package=izolabella.Discord&version=7.0.2

💞 izolabella.Discord

This project is an alternative to the command handler provided by Discord.NET for providing more detail to commands in a lightweight manner.

🌸 Quality Status

CodeFactor

👩‍💻 Getting Started

This project is available through NuGet.org;

  • Package Manager (Visual Studio)
Install-Package izolabella.Discord
  • .NET CLI
dotnet add package izolabella.Discord

This project uses Discord.NET to function!*

⌨️ Code

A new instance of the IzolabellaDiscordClient class must be initialized. The class takes a DiscordSocketConfig argument for the client, and a bool for whether or not the commands should be updated per guild or globally.

IzolabellaDiscordClient Client = new(new DiscordSocketConfig(), false);

The current version of this library uses classes for commands. To create a command, create a class that inherits the abstract class IzolabellaCommand. These classes must have parameterless constructors.

public class MyCommand : IzolabellaCommand
{
    public override string Name => "Command";

    public override string Description => "My command's description.'";

    public override bool GuildsOnly => true;

    public override List<IIzolabellaCommandConstraint> Constraints { get; } = new()
    {
        new WhitelistPermissionsConstraint(false, GuildPermission.Administrator)
    };

    public override List<IzolabellaCommandParameter> Parameters { get; } = new()
    {
        new IzolabellaCommandParameter("Param", "This is my parameter!", ApplicationCommandOptionType.Channel, true)
    };

    public override Task RunAsync(CommandContext Context, IzolabellaCommandArgument[] Arguments)
    {
        // command runs here!
    }

    public override Task OnLoadAsync(IIzolabellaCommand[] AllCommands)
    {
        // runs when all commands have been initialized - fired once.
    }

    public override Task OnConstrainmentAsync(CommandContext Context, IzolabellaCommandArgument[] Arguments, IIzolabellaCommandConstraint ConstraintThatFailed)
    {
        // when one of the constrainments don't pass the validity check by the handler, this method gets called.
    }
        
    public override Task OnErrorAsync(HttpException Error)
    {
        // when an error happens, this method will run.
    }
}

To create sub-commands, a class that inherits from IzolabellaSubCommand must be created, initialized, and placed in a list of a normal IzolabellaCommand. For example:

public class ExampleSub : IzolabellaSubCommand
{
    public override string Name => "Example Name";

    public override string Description => "Example!";

    public override bool GuildsOnly => true;

    public override List<IzolabellaCommandParameter> Parameters => new()
    {
        new("Channel", "Pick a channel!", ApplicationCommandOptionType.Channel, new() { ChannelType.Text }, false)
    };

    public override List<IIzolabellaCommandConstraint> Constraints => new();

    public override async Task RunAsync(CommandContext Context, IzolabellaCommandArgument[] Arguments)
    {
        await Context.UserContext.RespondAsync(text: "abc!!");
    }
}

Then, in an IzolabellaCommand, you can place it in the SubCommands property. As a shorter example (borrowing from the previous IzolabellaCommand example):

public class MyCommand : IzolabellaCommand
{
    public override List<IzolabellaSubCommand> SubCommands => new() { new ExampleSub() };
}

To get things going, call the following method on the IzolabellaDiscordClient instance you have created:

await Client.StartAsync();

Further, the client itself offers numerous events to hook on to. Browse intellisense context menus to see all the options.

Arguments will be in kebab case when passed back to the RunAsync methods!!! When comparing arguments by name, please keep this in mind. For example, if I have a parameter named "Channel Id", I should check in the arguments for an argument named "channel-id".

I want to make this as useable as possible for you. I have no in-depth documentation since things are currently changing rapidly. For questions and how-tos, please send me a request on Discord at izolabella.bin#0216.

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
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
7.0.2 187 7/8/2022
7.0.1 164 7/8/2022
7.0.0 164 7/8/2022
6.3.0 166 7/4/2022
6.2.0 165 7/4/2022
6.1.7 164 7/4/2022
6.1.6 167 6/3/2022
6.1.5 157 6/3/2022
6.1.4 167 6/3/2022
6.1.3 161 6/3/2022
6.1.2 158 6/3/2022
6.1.1 161 6/2/2022
6.1.0 174 5/27/2022
6.0.0 159 5/27/2022
5.1.0 167 5/23/2022
5.1.0-beta 76 5/22/2022
5.0.0-beta 74 5/22/2022
4.1.1 165 5/22/2022
4.1.0 168 5/22/2022
4.0.0 197 3/28/2022
3.0.1 165 3/21/2022
3.0.0 169 3/21/2022
2.3.4 171 3/21/2022
2.3.3 170 3/21/2022
2.3.2 167 3/20/2022
2.3.1 174 3/18/2022
2.3.0 173 3/18/2022
2.2.1 183 3/17/2022
2.2.0 181 3/16/2022
2.1.0 180 3/11/2022
2.0.4 177 3/11/2022
2.0.3 175 3/11/2022
2.0.2 176 3/11/2022
2.0.1 177 3/11/2022
2.0.0 176 3/11/2022
1.0.5 212 3/9/2022
1.0.4 213 3/9/2022
1.0.3 208 3/9/2022
1.0.2 207 3/7/2022
1.0.1 207 3/7/2022
1.0.0 205 3/7/2022

Fixed the part where it didn't work.