From ea7e142494ed90bd5c0b128a0c0902bea6f20071 Mon Sep 17 00:00:00 2001 From: Kingsley Zhong <40475664+Generaleoley@users.noreply.github.com> Date: Thu, 3 Sep 2020 08:23:03 -0600 Subject: [PATCH] Add hierarchy checks to `[p]warn` (#4100) * Update warnings.py * Cleanup the code and pass style check. Co-authored-by: Kowlin --- redbot/cogs/warnings/warnings.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/redbot/cogs/warnings/warnings.py b/redbot/cogs/warnings/warnings.py index 89e35830c..c08788534 100644 --- a/redbot/cogs/warnings/warnings.py +++ b/redbot/cogs/warnings/warnings.py @@ -380,14 +380,19 @@ class Warnings(commands.Cog): `` can be a registered reason if it exists or a custom one is created by default. """ - channel = ctx.channel guild = ctx.guild if user == ctx.author: - await ctx.send(_("You cannot warn yourself.")) - return + return await ctx.send(_("You cannot warn yourself.")) if user.bot: - await ctx.send(_("You cannot warn other bots.")) - return + return await ctx.send(_("You cannot warn other bots.")) + if user == ctx.guild.owner: + return await ctx.send(_("You cannot warn the server owner.")) + if user.top_role >= ctx.author.top_role and ctx.author != ctx.guild.owner: + return await ctx.send( + _( + "The person you're trying to warn is equal or higher than you in the discord hierarchy, you cannot warn them." + ) + ) guild_settings = await self.config.guild(ctx.guild).all() custom_allowed = guild_settings["allow_custom_reasons"]