Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tux/cogs/moderation/ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, bot: Tux) -> None:
async def ban(
self,
ctx: commands.Context[Tux],
member: discord.Member,
user: discord.User,
*,
flags: BanFlags,
) -> None:
Expand All @@ -48,19 +48,19 @@ async def ban(
assert ctx.guild

# Check if moderator has permission to ban the member
if not await self.check_conditions(ctx, member, ctx.author, "ban"):
if not await self.check_conditions(ctx, user, ctx.author, "ban"):
return

# Execute ban with case creation and DM
await self.execute_mod_action(
ctx=ctx,
case_type=CaseType.BAN,
user=member,
user=user,
reason=flags.reason,
silent=flags.silent,
dm_action="banned",
actions=[
(ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
Comment on lines 61 to -63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Banning by discord.User may fail if the user is not in the guild and the API expects a user ID.

If the user isn't cached or present in the guild, pass user.id to ctx.guild.ban to prevent API errors.

Suggested change
dm_action="banned",
actions=[
(ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
actions=[
(ctx.guild.ban(user.id, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
],

(ctx.guild.ban(user, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
],
)

Expand Down