mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[p]warn ask to ban when user not in server (#6481)
Co-authored-by: Michael Oliveira <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
parent
33e0eac741
commit
48b2fe77c0
@ -15,9 +15,10 @@ from redbot.cogs.warnings.helpers import (
|
||||
)
|
||||
from redbot.core import Config, commands, modlog
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.commands import UserInputOptional
|
||||
from redbot.core.commands import UserInputOptional, RawUserIdConverter
|
||||
from redbot.core.i18n import Translator, cog_i18n
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.views import ConfirmView
|
||||
from redbot.core.utils.chat_formatting import warning, pagify
|
||||
from redbot.core.utils.menus import menu
|
||||
|
||||
@ -373,7 +374,7 @@ class Warnings(commands.Cog):
|
||||
async def warn(
|
||||
self,
|
||||
ctx: commands.Context,
|
||||
member: discord.Member,
|
||||
user: Union[discord.Member, RawUserIdConverter],
|
||||
points: UserInputOptional[int] = 1,
|
||||
*,
|
||||
reason: str,
|
||||
@ -386,6 +387,49 @@ class Warnings(commands.Cog):
|
||||
or a custom reason if ``[p]warningset allowcustomreasons`` is set.
|
||||
"""
|
||||
guild = ctx.guild
|
||||
member = None
|
||||
if isinstance(user, discord.Member):
|
||||
member = user
|
||||
elif isinstance(user, int):
|
||||
if not ctx.channel.permissions_for(ctx.guild.me).ban_members:
|
||||
await ctx.send(_("User `{user}` is not in the server.").format(user=user))
|
||||
return
|
||||
user_obj = self.bot.get_user(user) or discord.Object(id=user)
|
||||
|
||||
confirm = ConfirmView(ctx.author, timeout=30)
|
||||
confirm.message = await ctx.send(
|
||||
_(
|
||||
"User `{user}` is not in the server. Would you like to ban them instead?"
|
||||
).format(user=user),
|
||||
view=confirm,
|
||||
)
|
||||
await confirm.wait()
|
||||
if confirm.result:
|
||||
try:
|
||||
await ctx.guild.ban(user_obj, reason=reason)
|
||||
await modlog.create_case(
|
||||
self.bot,
|
||||
guild,
|
||||
ctx.message.created_at,
|
||||
"hackban",
|
||||
user,
|
||||
ctx.author,
|
||||
reason,
|
||||
until=None,
|
||||
channel=None,
|
||||
)
|
||||
except discord.HTTPException as error:
|
||||
await ctx.send(
|
||||
_("An error occurred while trying to ban the user. Error: {error}").format(
|
||||
error=error
|
||||
)
|
||||
)
|
||||
else:
|
||||
confirm.message = await ctx.send(_("No action taken."))
|
||||
|
||||
await ctx.tick()
|
||||
return
|
||||
|
||||
if member == ctx.author:
|
||||
return await ctx.send(_("You cannot warn yourself."))
|
||||
if member.bot:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user