Discord.Addons.CommandsExtension 1.0.4

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

// Install Discord.Addons.CommandsExtension as a Cake Tool
#tool nuget:?package=Discord.Addons.CommandsExtension&version=1.0.4                

Discord.Net.Addons.CommandsExtension

An extension of Discord.Net.Commands, mainly to get information about your commands as string, ideally to build a help command. Comes with a extension of the CommandService to build a help command easily!

Getting Started

This package is uploaded to NuGet:

Prerequisites

First of all, you need a C# discord bot, using the Discord.Net version >= 2.0. If you don't have one yet, check out some tutorials here to get started with Discord bots!

Using the default help embed

If you're looking for an auto-generated embed for your help command, and you don't care about how it looks, this is what you're looking for!

All you need to do is add the CommandService to your dependency container if you haven't it yet, and inject it into the Command Module where the help command is.

using System.Threading.Tasks;
using Discord.Commands;
using Discord.Addons.CommandsExtension;

namespace MyBot.Modules
{
    public class HelpModule : ModuleBase
    {
        private readonly CommandService _commandService;

        public HelpModule(CommandService commandService)
        {
            _commandService = commandService;
        }

        [Command("help"), Alias("assist"), Summary("Shows help menu.")]
        public async Task Help([Remainder] string command = null)
        {
            var botPrefix = ">"; //replace this with your own prefix.
            var helpEmbed = _commandService.GetDefaultHelpEmbed(command, botPrefix);
            await Context.Channel.SendMessageAsync(embed: helpEmbed);
        }
    }
}

However, as much as we want to encourage the use of the Dependency Injection pattern, it's not easy to understand for starters, or there might be someone with a project, in a point where setting up DI would take a lot of work. If you've followed Peter .Net Framework tutorials, then most likely you don't have the Dependency Injection setted up. I will use his tutorials as a reference to explain how to set this up without Dependency Injection. You have to add a global variable, in your Global.cs class, to reference the CommandService:

using Discord.Commands;
using System;

namespace DiscordTutorialBot
{
    internal static class Global
    {
        internal static CommandService commandService { get; set;}
    }
}

The next step, is use that variable to reference your commnad service, you can do that right where you initialize the CommandService, in the CommandHandler class, in the InitializeAsync method:

public async Task InitializeAsync(DiscordSocketClient client)
{
  _client = client;
  _service = new CommandService();
  Global.commandService = _service;
  await _service.AddModulesAsync(Assembly.GetEntryAssembly());
  _client.MessageReceived += HandleCommandAsync;
}

After that, the CommandService will be accesible from your help command with Global.commandService.

using System.Threading.Tasks;
using Discord.Commands;
using Discord.Addons.CommandsExtension;

namespace MyBot.Modules
{
    public class HelpModule : ModuleBase
    {      

        [Command("help"), Alias("assist"), Summary("Shows help menu.")]
        public async Task Help([Remainder] string command = null)
        {
            var botPrefix = ">"; //replace this with your own prefix.
            var helpEmbed = Global.commandService.GetDefaultHelpEmbed(command, botPrefix);
            await Context.Channel.SendMessageAsync(embed: helpEmbed);
        }
    }
}

After that, you're ready to go! <p align="center"> <img src="https://thumbs.gfycat.com/ImpossibleIllustriousIaerismetalmark-small.gif"> </p>

Authors

  • Charly6596 - CommandService extensions and default embed generation - Github profile - Discord: Charly#7094

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

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 was computed.  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. 
.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 was computed. 
.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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 6,306 1/6/2019
1.0.3 1,176 1/4/2019