Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Quahu/Qmmands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qmmands

An asynchronous .NET Standard 2.0 command framework no one asked for.

Build Status NuGet MyGet The Lab

Inspired by Discord.Net.Commands and DSharpPlus.CommandsNext.

Qmmands can be pulled from NuGet. For nightly builds add https://www.myget.org/F/qmmands/api/v3/index.json (the nightly feed) to your project's package sources.

Documentation

There's currently no official documentation for Qmmands other than the very barebones example at the bottom and the bundled XML docstrings. For support you should hop in my Discord guild:

The Lab

Community Examples:

Extremely Basic Usage Example

// CommandHandler.cs
private readonly CommandService _service = new CommandService();

// Imagine this being a message callback, whether it'd be from an IRC bot,
// a Discord bot, or any other chat based commands bot.
private async Task MessageReceivedAsync(Message message)
{
    if (!CommandUtilities.HasPrefix(message.Content, '!', out string output))
        return;
        
    IResult result = await _service.ExecuteAsync(output, new CommandContext(message));
    if (!result.IsSuccessful)
        await message.Channel.SendMessageAsync((result as FailedResult).Reason); 
}

// CommandContext.cs
public sealed class CommandContext : ICommandContext
{
    public Message Message { get; }
    
    public Channel Channel => Message.Channel;
  
    public CommandContext(Message message)
      => Message = message;
}

// CommandModule.cs
public sealed class CommandModule : ModuleBase<CommandContext>
{
    public CommandService Service { get; set; }

    // Invoked with:   !help
    // Responds with:  `help` - Lists available commands.
    //                 `sum` - Sums two given numbers.
    //                 `echo` - Echoes given text.
    [Command("help", "commands")]
    [Description("Lists available commands.")]
    public Task HelpAsync()
        => Context.Channel.SendMessageAsync(
            string.Join('\n', Service.GetAllCommands().Select(x => $"`{x.Name}` - {x.Description}")));

    // Invoked with:  !sum 3 5
    // Responds with: 3 + 5 = 8
    [Command("sum")]
    [Description("Sums two given numbers.")]
    public Task SumAsync(int firstNumber, int secondNumber)
      => Context.Channel.SendMessageAsync(
          $"{firstNumber} + {secondNumber} = {firstNumber + secondNumber}");

    // Invoked with:  !echo Hello, world.
    // Responds with: Hello, world.
    [Command("echo")]
    [Description("Echoes given text.")]
    public Task EchoAsync([Remainder] string text)
      => Context.Channel.SendMessageAsync(text);
}

About

Asynchronous command framework for .NET.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Languages