Discord.Addons.CommandsExtension 1.0.4

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!

Install-Package Discord.Addons.CommandsExtension -Version 1.0.4
dotnet add package Discord.Addons.CommandsExtension --version 1.0.4
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 &gt;= 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

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 &gt;= 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

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.4 244 1/6/2019
1.0.3 136 1/4/2019