Skip to content

Commit

Permalink
Updated the warn command to include an option for the mod/owner to ba…
Browse files Browse the repository at this point in the history
…n a user if he is not present in the guild
  • Loading branch information
Ascensionn committed Nov 28, 2024
1 parent 113dd06 commit 80bdf14
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions redbot/cogs/warnings/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ async def actionlist(self, ctx: commands.Context):
async def warn(
self,
ctx: commands.Context,
identifier: str,
identifier: str,
points: UserInputOptional[int] = 1,
*,
reason: str,
Expand All @@ -389,30 +389,49 @@ async def warn(
member = None
user = None
"""User can be warned by ID or warned by their name."""

if identifier.isdigit():
member = ctx.guild.get_member(int(identifier))
# await ctx.send("Got member by ID")
else:
member = ctx.guild.get_member_named(identifier)
# await ctx.send("Got member by name")
if not member:
await ctx.send(f"User with ID `{identifier}` was not found in discord guild.")
await ctx.send(f"User `{identifier}` not found in discord guild")

# Because he has not been found, he will be banned.
try:
user = await self.bot.fetch_user(int(identifier))
await ctx.send(f"User `{user.name}` is not in the server but has been found globally.")
await ctx.send(
f"User `{user.name}` is not in the server but has been found globally. Would you like to ban them instead? [Y/N]"
)
try:

def check(m):
return (
m.author == ctx.author
and m.channel == ctx.channel
and m.content.lower() in {"y", "n"}
)

response = await self.bot.wait_for("message", check=check, timeout=30.0)
if response.content.lower() == "y":
await ctx.guild.ban(user, reason=reason)
await ctx.send(f"User `{user.name}` has been banned for: {reason}")
elif response.content.lower() == "n":
await ctx.send("No action taken.")
else:
# This should not happen due to the check, but it's good to cover edge cases
await ctx.send("I do not recognize that answer. No action taken.")
except asyncio.TimeoutError:
await ctx.send("No response received. No action taken.")
await ctx.guild.ban(user, reason=reason)
await ctx.send(f"User `{user.name}` has been banned for: {reason}")
except discord.Forbidden:
await ctx.send("I don't have permission to ban this user.")
except discord.NotFound:
await ctx.send(f"User with ID `{identifier}` not found globally.")
return

return

if member == ctx.author:
return await ctx.send(_("You cannot warn yourself."))
if member.bot:
Expand Down

0 comments on commit 80bdf14

Please sign in to comment.