Exemplo n.º 1
0
        public static bool CheckChannelPermission(this IMessageChannel channel, ChannelPermission permission, IGuildUser guildUser)
        {
            var guildchannel = channel as IGuildChannel;

            ChannelPermissions perms;

            perms = guildchannel != null?guildUser.GetPermissions(guildchannel) : ChannelPermissions.All(null);

            return(perms.Has(permission));
        }
Exemplo n.º 2
0
        PreconditionResult CheckUser(IUser user, IChannel channel)
        {
            var guildUser = user as IGuildUser;

            // If user is server owner or has the administrator role
            // they get a free pass.
            if (guildUser != null &&
                (guildUser.IsServerOwner() ||
                 guildUser.GuildPermissions
                 .Has(Discord.GuildPermission.Administrator)))
            {
                return(PreconditionResult.FromSuccess());
            }
            if (GuildPermission != null)
            {
                if (guildUser == null)
                {
                    return(PreconditionResult.FromError("Command must be used in a guild channel"));
                }
                foreach (GuildPermission guildPermission in GuildPermission)
                {
                    if (!guildUser.GuildPermissions.Has(guildPermission))
                    {
                        return(PreconditionResult.FromError($"Command requires guild permission {guildPermission.ToString().SplitCamelCase().Code()}"));
                    }
                }
            }

            if (ChannelPermission != null)
            {
                var guildChannel = channel as IGuildChannel;
                ChannelPermissions perms;
                if (guildChannel != null)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(guildChannel);
                }
                foreach (ChannelPermission channelPermission in ChannelPermission)
                {
                    if (!perms.Has(channelPermission))
                    {
                        return(PreconditionResult.FromError($"Command requires channel permission {channelPermission.ToString().SplitCamelCase().Code()}"));
                    }
                }
            }
            return(PreconditionResult.FromSuccess());
        }
Exemplo n.º 3
0
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context,
                                                                              CommandInfo command, IServiceProvider services)
        {
            if (
                services.GetService <Configuration>().OwnerIds.Contains(context.User.Id))
            {
                return(PreconditionResult.FromSuccess());
            }
            IGuildUser guildUser = null;

            if (context.Guild != null)
            {
                guildUser = await context.Guild.GetCurrentUserAsync().ConfigureAwait(false);
            }

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(PreconditionResult.FromError(
                               $"This command can only be used in a {"server".InlineCode()} channel"));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(PreconditionResult.FromError(
                               $"I need the permission {GuildPermission.Value.Humanize(LetterCasing.Title).ToLower().InlineCode()} to do this"));
                }
            }

            if (!ChannelPermission.HasValue)
            {
                return(PreconditionResult.FromSuccess());
            }
            ChannelPermissions perms;

            if (context.Channel is IGuildChannel guildChannel)
            {
                perms = guildUser.GetPermissions(guildChannel);
            }
            else
            {
                perms = ChannelPermissions.All(context.Channel);
            }

            return(!perms.Has(ChannelPermission.Value)
                ? PreconditionResult.FromError(
                       $"I need the channel permission {ChannelPermission.Value.Humanize(LetterCasing.Title).ToLower().InlineCode()} to do this")
                : PreconditionResult.FromSuccess());
        }
Exemplo n.º 4
0
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command,
                                                                        IServiceProvider services)
        {
            if (services.GetService <Configuration>().OwnerIds.Contains(context.User.Id))
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }
            var guildUser = context.User as IGuildUser;

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(Task.FromResult(
                               PreconditionResult.FromError(
                                   $"This command is only available in {"server".InlineCode()} channels")));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(Task.FromResult(
                               PreconditionResult.FromError(
                                   $"You need the permission {GuildPermission.Value.Humanize(LetterCasing.Title).ToLower().InlineCode()} to do this")));
                }
            }

            if (!ChannelPermission.HasValue)
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }
            ChannelPermissions perms;

            if (context.Channel is IGuildChannel guildChannel)
            {
                perms = guildUser.GetPermissions(guildChannel);
            }
            else
            {
                perms = ChannelPermissions.All(context.Channel);
            }

            if (!perms.Has(ChannelPermission.Value))
            {
                return(Task.FromResult(PreconditionResult.FromError(
                                           $"You need the channel permission {ChannelPermission.Value.Humanize(LetterCasing.Title).ToLower().InlineCode()} to do this")));
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
Exemplo n.º 5
0
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext ctx, CommandInfo command, IServiceProvider services)
        {
            var context = (ShadeContext)ctx;

            // Includes owner and trusted users.
            var isTrusted = await new RequireTrustedUserAttribute().CheckPermissionsAsync(ctx, command, services);

            if (isTrusted.IsSuccess)
            {
                return(PreconditionResult.FromSuccess());
            }

            var guildUser = context.PermissionUser;

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel."));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(PreconditionResult.FromError(ErrorMessage ?? $"User requires guild permission {GuildPermission.Value}."));
                }
            }

            if (ChannelPermission.HasValue)
            {
                ChannelPermissions perms;
                if (context.Channel is IGuildChannel guildChannel)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(context.Channel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(PreconditionResult.FromError(ErrorMessage ?? $"User requires channel permission {ChannelPermission.Value}."));
                }
            }

            return(PreconditionResult.FromSuccess());
        }
Exemplo n.º 6
0
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            IGuildUser guildUser = null;

            if (context.Guild != null)
            {
                guildUser = await context.Guild.GetCurrentUserAsync().ConfigureAwait(false);
            }

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(PreconditionResult.FromError("Command must be used in a guild channel"));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(PreconditionResult.FromError($"Bot requires guild permission {GuildPermission.Value}"));
                }
            }

            if (ChannelPermission.HasValue)
            {
                var guildChannel = context.Channel as IGuildChannel;

                ChannelPermissions perms;
                if (guildChannel != null)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(guildChannel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(PreconditionResult.FromError($"Bot requires channel permission {ChannelPermission.Value}"));
                }
            }

            return(PreconditionResult.FromSuccess());
        }
        /// <inheritdoc />
        public override async Task <PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo command, IServiceProvider services)
        {
            IGuildUser guildUser = null;

            if (context.Guild != null)
            {
                guildUser = await context.Guild.GetCurrentUserAsync().ConfigureAwait(false);
            }

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel."));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(PreconditionResult.FromError(ErrorMessage ?? $"Bot requires guild permission {GuildPermission.Value}."));
                }
            }

            if (ChannelPermission.HasValue)
            {
                ChannelPermissions perms;
                if (context.Channel is IGuildChannel guildChannel)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(context.Channel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(PreconditionResult.FromError(ErrorMessage ?? $"Bot requires channel permission {ChannelPermission.Value}."));
                }
            }

            return(PreconditionResult.FromSuccess());
        }
Exemplo n.º 8
0
        public async Task Usage()
        {
            ChannelPermissions perms;
            var user = Context.User as IGuildUser;

            await ReplyAsync($"Command is {Current ?? "_not set_"}");

            if (Context.Channel is IGuildChannel guildChannel)
            {
                perms = user.GetPermissions(guildChannel);
            }
            else
            {
                perms = ChannelPermissions.All(Context.Channel);
            }

            if (perms.Has(ChannelPermission.ManageChannels))
            {
                await ReplyAsync($"!enable {string.Join("|", Config.Command)}");
            }
        }
Exemplo n.º 9
0
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            var guildUser = context.User as IGuildUser;

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(Task.FromResult(PreconditionResult.FromError("Command must be used in a guild channel")));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError($"User requires guild permission {GuildPermission.Value}")));
                }
            }

            if (ChannelPermission.HasValue)
            {
                var guildChannel = context.Channel as IGuildChannel;

                ChannelPermissions perms;
                if (guildChannel != null)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(guildChannel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError($"User requires channel permission {ChannelPermission.Value}")));
                }
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
Exemplo n.º 10
0
        public override Task <PreconditionResult> CheckPermissions(IUserMessage context, Command executingCommand, object moduleInstance)
        {
            var guildUser = context.Author as IGuildUser;

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(Task.FromResult(PreconditionResult.FromError("Command must be used in a guild channel")));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError($"Command requires guild permission {GuildPermission.Value}")));
                }
            }

            if (ChannelPermission.HasValue)
            {
                var guildChannel = context.Channel as IGuildChannel;

                ChannelPermissions perms;
                if (guildChannel != null)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(guildChannel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError($"Command requires channel permission {ChannelPermission.Value}")));
                }
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
        {
            var guildUser = await context.Guild.GetCurrentUserAsync();

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(PreconditionResult.FromError("Command must be used in a guild channel"));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(PreconditionResult.FromError($"Command requires guild permission {GuildPermission.Value}"));
                }
            }

            if (ChannelPermission.HasValue)
            {
                var guildChannel = context.Channel as IGuildChannel;

                ChannelPermissions perms;
                if (guildChannel != null)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(guildChannel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(PreconditionResult.FromError($"Command requires channel permission {ChannelPermission.Value}"));
                }
            }

            return(PreconditionResult.FromSuccess());
        }
Exemplo n.º 12
0
        /// <summary>
        /// <see cref="RequireUserPermissionAttribute"/>, but it isn't an attribute
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="permission">The permission the user needs</param>
        /// <returns>True if the user has permissions, else false. Also returns false if the command wasn't executed in a guild.</returns>
        public static bool CheckForPermissions(ICommandContext context, ChannelPermission permission)
        {
            var guildUser = context.User as IGuildUser;
            ChannelPermissions perms;

            if (context.Channel is IGuildChannel guildChannel)
            {
                perms = guildUser.GetPermissions(guildChannel);
            }
            else
            {
                perms = ChannelPermissions.All(context.Channel);
            }

            if (perms.Has(permission))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 13
0
        public override Task <CheckResult> CheckAsync(ICommandContext ctx, IServiceProvider provider)
        {
            var context = (QuiccbanContext)ctx;

            var responseService = provider.GetService <ResponseService>();

            var guildUser = context.Guild.CurrentUser;


            if (GuildPermission.HasValue)
            {
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(Task.FromResult(new CheckResult(string.Format(responseService.Get("bot_require_guild_permission"), GuildPermission.Value))));
                }
            }

            if (ChannelPermission.HasValue)
            {
                ChannelPermissions perms;
                if (context.Channel is IGuildChannel guildChannel)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(context.Channel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(Task.FromResult(new CheckResult(string.Format(responseService.Get("bot_require_channel_permission"), ChannelPermission.Value))));
                }
            }

            return(Task.FromResult(CheckResult.Successful));
        }
        /// <inheritdoc />
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            var guildUser = context.User as IGuildUser;

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(Task.FromResult(PreconditionAttributeResult.FromError("Command must be used in a guild channel.", this)));
                }
                if (guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(Task.FromResult(PreconditionPermissionResult.FromError($"User requires guild permission {GuildPermission.Value}.", GuildPermission.Value & ~((GuildPermission)guildUser.GuildPermissions.RawValue), 0, this)));
                }
            }

            if (ChannelPermission.HasValue)
            {
                ChannelPermissions perms;
                if (context.Channel is IGuildChannel guildChannel)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(context.Channel);
                }

                if (perms.Has(ChannelPermission.Value))
                {
                    return(Task.FromResult(PreconditionPermissionResult.FromError($"User requires channel permission {ChannelPermission.Value}.", 0, ChannelPermission.Value & ~((ChannelPermission)perms.RawValue), this)));
                }
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
        /// <inheritdoc />
        public override Task <PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
        {
            var guildUser = context.User as IGuildUser;

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                {
                    return(Task.FromResult(PreconditionResult.FromError(NotAGuildErrorMessage ?? "Command must be used in a guild channel.")));
                }
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires guild permission {GuildPermission.Value}.")));
                }
            }

            if (ChannelPermission.HasValue)
            {
                ChannelPermissions perms;
                if (context.Channel is IGuildChannel guildChannel)
                {
                    perms = guildUser.GetPermissions(guildChannel);
                }
                else
                {
                    perms = ChannelPermissions.All(context.Channel);
                }

                if (!perms.Has(ChannelPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError(ErrorMessage ?? $"User requires channel permission {ChannelPermission.Value}.")));
                }
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
Exemplo n.º 16
0
        public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider map)
        {
            var guildUser = context.User as IGuildUser;
            //If the user is the owner of the bot, skip checking for permissions
            if ((await context.Client.GetApplicationInfoAsync().ConfigureAwait(false)).Owner.Id == context.User.Id)
                return PreconditionResult.FromSuccess();

            if (GuildPermission.HasValue)
            {
                if (guildUser == null)
                    return PreconditionResult.FromError("Command must be used in a guild channel");
                if (!guildUser.GuildPermissions.Has(GuildPermission.Value))
                    return PreconditionResult.FromError($"Command requires guild permission {GuildPermission.Value}");
            }

            if (ChannelPermission.HasValue)
            {
                var guildChannel = context.Channel as IGuildChannel;

                ChannelPermissions perms;
                perms = guildChannel != null ? guildUser.GetPermissions(guildChannel) : ChannelPermissions.All(guildChannel);

                if (!perms.Has(ChannelPermission.Value))
                    return PreconditionResult.FromError($"Command requires channel permission {ChannelPermission.Value}");
            }
            return PreconditionResult.FromSuccess();
        }
Exemplo n.º 17
0
        public override Task <PreconditionResult> CheckPermissionsAsync(
            ICommandContext context,
            CommandInfo command,
            IServiceProvider services)
        {
            IGuildUser user = context.User as IGuildUser;

            if (context.User.IsWebhook)
            {
                return(Task.FromResult(_webhookNames.Contains(context.User.Username) ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Command must be used by an authorized webhook.")));
            }

            if (this.GuildPermission.HasValue)
            {
                if (user == null)
                {
                    return(Task.FromResult(PreconditionResult.FromError(this.NotAGuildErrorMessage ?? "Command must be used in a guild channel.")));
                }
                if (!user.GuildPermissions.Has(this.GuildPermission.Value))
                {
                    return(Task.FromResult(PreconditionResult.FromError(this.ErrorMessage ?? string.Format("User requires guild permission {0}.", (object)this.GuildPermission.Value))));
                }
            }
            Discord.ChannelPermission?channelPermission = this.ChannelPermission;
            if (channelPermission.HasValue)
            {
                ChannelPermissions     channelPermissions = !(context.Channel is IGuildChannel channel) ? ChannelPermissions.All((IChannel)context.Channel) : user.GetPermissions(channel);
                ref ChannelPermissions local = ref channelPermissions;
                channelPermission = this.ChannelPermission;
                long num = (long)channelPermission.Value;
                if (!local.Has((Discord.ChannelPermission)num))
                {
                    string reason = this.ErrorMessage;
                    if (reason == null)
                    {
                        channelPermission = this.ChannelPermission;
                        reason            = string.Format("User requires channel permission {0}.", (object)channelPermission.Value);
                    }
                    return(Task.FromResult(PreconditionResult.FromError(reason)));
                }
            }
Exemplo n.º 18
0
        private async Task OnCommandExecutedAsync(Optional <CommandInfo> optionalCommand, ICommandContext context, IResult result)
        {
            // We have access to the information of the command executed,
            // the context of the command, and the result returned from the
            // execution in this event.

            // command is unspecified when there was a search failure (command not found)
            if (!optionalCommand.IsSpecified)
            {
                await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Command", $"Unknown command: \"{context.Message.Content}\", sent by {context.User} in {context.Display()}"));

                return;
            }
            var command = optionalCommand.Value;

            if (command.Module.Name != Constants.DevelopmentModuleName)
            {
                // Update the command stats
                lock (_cmdStatsLock)
                {
                    var stats = DatabaseConfig.CommandStats;
                    if (stats.ContainsKey(command.Name))
                    {
                        stats[command.Name]++;
                    }
                    else
                    {
                        stats.Add(command.Name, 1);
                    }
                    DatabaseConfig.Update(x => x.CommandStats = stats);
                }
            }

            // the command was successful, we don't care about this result, unless we want to log that a command succeeded.
            if (result.IsSuccess)
            {
                return;
            }

            double ignoreTime = Constants.DefaultIgnoreTime;

            switch (result.Error)
            {
            //case CommandError.UnknownCommand:
            //    await SendEmbedAsync(context.Message, string.Format(LocalizationService.Locate("CommandNotFound", context.Message), GetPrefix(context.Channel)));
            //    break;
            case CommandError.BadArgCount:
            case CommandError.ParseFailed:
                string language = GuildUtils.GetLanguage(context.Channel);
                string prefix   = GuildUtils.GetPrefix(context.Channel);
                await SendEmbedAsync(context.Message, command.ToHelpEmbed(language, prefix), _services);

                break;

            case CommandError.UnmetPrecondition when command.Module.Name != Constants.DevelopmentModuleName:
                ChannelPermissions permissions;
                if (context.Guild == null)
                {
                    permissions = ChannelPermissions.All(context.Channel);
                }
                else
                {
                    var guildUser = await context.Guild.GetCurrentUserAsync().ConfigureAwait(false);

                    permissions = guildUser.GetPermissions((IGuildChannel)context.Channel);
                }

                if (!permissions.Has(Constants.MinimumRequiredPermissions))
                {
                    var builder = new EmbedBuilder()
                                  .WithDescription($"\u26a0 {result.ErrorReason}")
                                  .WithColor(FergunClient.Config.EmbedColor);
                    try
                    {
                        await context.User.SendMessageAsync(embed : builder.Build());
                    }
                    catch (HttpException e) when(e.DiscordCode == 50007)
                    {
                        await _logService.LogAsync(new LogMessage(LogSeverity.Warning, "Command", "Unable to send a DM about the minimum required permissions to the user."));
                    }
                }
                else
                {
                    if (result.ErrorReason.StartsWith("(Cooldown)", StringComparison.OrdinalIgnoreCase))
                    {
                        ignoreTime = Constants.CooldownIgnoreTime;
                    }
                    await SendEmbedAsync(context.Message, $"\u26a0 {GuildUtils.Locate(result.ErrorReason, context.Channel)}", _services);
                }
                break;

            case CommandError.ObjectNotFound:
                // reason: The error reason (User not found., Role not found., etc)
                string reason = result.ErrorReason;
                // Delete the last char (.)
                reason = reason.Substring(0, result.ErrorReason.Length - 1);
                // Convert to title case (User Not Found)
                reason = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(reason);
                // Remove spaces (UserNotFound)
                reason = reason.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase);
                // Locate the string to the current language of the guild
                reason = GuildUtils.Locate(reason, context.Channel);
                await SendEmbedAsync(context.Message, $"\u26a0 {reason}", _services);

                break;

            case CommandError.MultipleMatches:
                await SendEmbedAsync(context.Message, $"\u26a0 {GuildUtils.Locate("MultipleMatches", context.Channel)}", _services);

                break;

            case CommandError.Unsuccessful:
                await SendEmbedAsync(context.Message, $"\u26a0 {result.ErrorReason}".Truncate(EmbedBuilder.MaxDescriptionLength), _services);

                break;

            case CommandError.Exception when result is ExecuteResult execResult:
                var exception = execResult.Exception;

                if (exception is HttpException httpException && httpException.HttpCode >= HttpStatusCode.InternalServerError)
                {
                    await Task.Delay(2000);

                    var builder = new EmbedBuilder()
                                  .WithTitle(GuildUtils.Locate("DiscordServerError", context.Channel))
                                  .WithDescription($"\u26a0 {GuildUtils.Locate("DiscordServerErrorInfo", context.Channel)}")
                                  .AddField(GuildUtils.Locate("ErrorDetails", context.Channel),
                                            Format.Code($"Code: {(int)httpException.HttpCode}, Reason: {httpException.Reason}", "md"))
                                  .WithColor(FergunClient.Config.EmbedColor);

                    try
                    {
                        await SendEmbedAsync(context.Message, builder.Build(), _services);
                    }
                    catch (HttpException) { }
                    break;
                }

                var builder2 = new EmbedBuilder()
                               .WithTitle($"\u274c {GuildUtils.Locate("FailedExecution", context.Channel)} {Format.Code(command.Name)}")
                               .AddField(GuildUtils.Locate("ErrorType", context.Channel), Format.Code(exception.GetType().Name, "cs"))
                               .AddField(GuildUtils.Locate("ErrorMessage", context.Channel), Format.Code(exception.Message, "cs"))
                               .WithColor(FergunClient.Config.EmbedColor);

                var owner = (await context.Client.GetApplicationInfoAsync()).Owner;

                if (context.User.Id != owner.Id)
                {
                    builder2.WithFooter(GuildUtils.Locate("ErrorSentToOwner", context.Channel));
                }

                await SendEmbedAsync(context.Message, builder2.Build(), _services);

                if (context.User.Id == owner.Id)
                {
                    break;
                }
                // if the user that executed the command isn't the bot owner, send the full stack trace to the errors channel

                var channel = await context.Client.GetChannelAsync(FergunClient.Config.LogChannel);

                if (!(channel is IMessageChannel messageChannel))
                {
                    await _logService.LogAsync(new LogMessage(LogSeverity.Warning, "Command", $"Invalid log channel Id ({FergunClient.Config.LogChannel}). Not possible to send the embed with the error info."));

                    break;
                }

                var builder3 = new EmbedBuilder()
                               .WithTitle($"\u274c Failed to execute {Format.Code(command.Name)} in {context.Display()}".Truncate(EmbedBuilder.MaxTitleLength))
                               .AddField(GuildUtils.Locate("ErrorType", messageChannel), Format.Code(exception.GetType().Name, "cs"))
                               .AddField(GuildUtils.Locate("ErrorMessage", messageChannel), Format.Code(exception.ToString().Truncate(EmbedFieldBuilder.MaxFieldValueLength - 10), "cs"))
                               .AddField("Jump url", context.Message.GetJumpUrl())
                               .AddField("Command", context.Message.Content.Truncate(EmbedFieldBuilder.MaxFieldValueLength))
                               .WithColor(FergunClient.Config.EmbedColor);

                try
                {
                    await messageChannel.SendMessageAsync(embed : builder3.Build());
                }
                catch (HttpException e)
                {
                    await _logService.LogAsync(new LogMessage(LogSeverity.Warning, "Command", "Error while sending the embed in the log channel", e));
                }
                break;
            }

            _ = IgnoreUserAsync(context.User.Id, TimeSpan.FromSeconds(ignoreTime));
            await _logService.LogAsync(new LogMessage(LogSeverity.Info, "Command", $"Failed to execute \"{command.Name}\" for {context.User} in {context.Display()}, with error type: {result.Error} and reason: {result.ErrorReason}"));
        }