Esempio n. 1
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;
            var guild   = arg.Channel as IGuildChannel;

            if (message == null)
            {
                return;
            }

            int  argPos = 0;
            char prefix = '*';

            if (_prefixRepository.CheckIfGuildHasPrefix(guild.GuildId))
            {
                prefix = _prefixRepository.GetPrefixForGuild(guild.GuildId).PrefixCommand;
            }

            if (!(message.HasCharPrefix(prefix, ref argPos)) || message.Author.IsBot)
            {
                return;
            }

            var context = new SocketCommandContext(_client, message);
            var result  = await _commands.ExecuteAsync(
                context : context,
                argPos : argPos,
                services : _serviceProvider);

            if (result.Error.HasValue)
            {
                if (result.Error == CommandError.Exception)
                {
                    EmbedBuilder errorEmbed = EmbedService.BuildErrorEmbed(result.ErrorReason, context.Guild);
                    await context.Channel.SendMessageAsync(embed : errorEmbed.Build());
                }
            }
        }