Beispiel #1
0
    public async Task HandleCommand(IMessage paramMessage)
    {
        // Cast paramMessage to an IUserMessage, return if the message was a System message.
        var msg = paramMessage as IUserMessage;

        if (msg == null)
        {
            return;
        }
        // Internal integer, marks where the command begins
        int argPos = 0;
        // Get the current user (used for Mention parsing)
        var currentUser = await client.GetCurrentUserAsync();

        // Determine if the message is a command, based on if it starts with '!' or a mention prefix
        if (msg.HasCharPrefix('!', ref argPos) || msg.HasMentionPrefix(currentUser, ref argPos))
        {
            // Execute the command. (result does not indicate a return value,
            // rather an object stating if the command executed succesfully)
            var result = await _commands.Execute(msg, argPos);

            if (!result.IsSuccess)
            {
                await msg.Channel.SendMessageAsync(result.ErrorReason);
            }
        }
    }
    public async Task Install(DiscordSocketClient client)
    {
        var commands = new CommandService();
        var map      = new DependencyMap();

        map.Add <IDiscordClient>(client);
        var self = await client.GetCurrentUserAsync();

        map.Add <ISelfUser>(self);
        await commands.LoadAssembly(Assembly.GetCurrentAssembly(), map);
    }