Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.

Creating your first command

Mikhail edited this page Jan 11, 2021 · 5 revisions

Creating your first command

Creating command is the similar to handler creating process, but with one restriction: command method return type should be Task or ValueTask.

Let's define constant string which we will use as an identifier for all command handlers and command processor builder which is related to Message handling:

public string const MessagesCommandProcessorId = "Messages";

Example of Ping command:

[MessageCommandHandler("ping")]
public async Task Ping(ICommandContext<Message> commandContext)
{
    await commandContext.BotClient.SendTextMessageAsync(commandContext.Entity.Chat, "Pong!");
}

Where MessageCommandHandlerAttribute is:

public class MessageCommandHandlerAttribute : CommandHandlerAttributeBase
{
    public string CommandFormat { get; }

    public MessageCommandHandlerAttribute(string commandFormat) : base(MessagesCommandProcessorId, UpdateType.Message)
    {
        CommandFormat = commandFormat;
    }
}

Clone this wiki locally