Skip to content

fix: enable the banning nonserver users #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

fix: enable the banning nonserver users #981

wants to merge 2 commits into from

Conversation

cherryl1k
Copy link
Collaborator

@cherryl1k cherryl1k commented Jul 26, 2025

Description

Changed ban.py to allow non-server members to be banned previously

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

tested with an admin account and unprivileged alt both attempting to ban a current guild member and a non-guild member

Additional Information

it does give a warning for not being able to DM a user (obviously this is because they're not apart of the guild)
i also got a warning for "No guild config found for guild_id" but i am pretty sure this is due to my server

Summary by Sourcery

Bug Fixes:

  • Allow banning of non-server members by changing the ban command parameter to discord.User

Copy link
Contributor

sourcery-ai bot commented Jul 26, 2025

Reviewer's Guide

The ban command has been refactored to accept discord.User instead of discord.Member, enabling the bot to ban users who are not members of the server by updating the signature, permission check, and ban execution accordingly.

Sequence diagram for banning a non-server member

sequenceDiagram
    actor Moderator
    participant Bot
    participant Guild
    participant User
    Moderator->>Bot: Invoke ban command with User (not a member)
    Bot->>Bot: check_conditions(ctx, user, ctx.author, "ban")
    alt Permission granted
        Bot->>Guild: ban(user, reason, delete_message_seconds)
        Bot->>User: Attempt DM (may fail)
    else Permission denied
        Bot-->>Moderator: Abort ban
    end
Loading

Class diagram for updated ban command parameter

classDiagram
    class BanCommand {
        +ban(ctx: commands.Context[Tux], user: discord.User, flags: BanFlags)
    }
    class discord.User
    class discord.Member
    BanCommand ..> discord.User : now accepts
    BanCommand ..x discord.Member : no longer accepts
Loading

File-Level Changes

Change Details Files
Accept discord.User instead of discord.Member in ban command
  • Changed ban method signature parameter from Member to User
  • Updated permission check to pass User object
  • Modified execute_mod_action and guild.ban call to use User
tux/cogs/moderation/ban.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

github-actions bot commented Jul 26, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @cherryl1k - I've reviewed your changes - here's some feedback:

  • Update the method docstring and internal comments to reflect that it now accepts a discord.User instead of a member.
  • Verify that check_conditions is fully compatible with discord.User inputs (not only discord.Member).
  • Consider renaming the user parameter to something more descriptive (e.g. target or user_to_ban) to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Update the method docstring and internal comments to reflect that it now accepts a discord.User instead of a member.
- Verify that check_conditions is fully compatible with discord.User inputs (not only discord.Member).
- Consider renaming the `user` parameter to something more descriptive (e.g. `target` or `user_to_ban`) to avoid confusion.

## Individual Comments

### Comment 1
<location> `tux/cogs/moderation/ban.py:63` </location>
<code_context>
             silent=flags.silent,
             dm_action="banned",
             actions=[
-                (ctx.guild.ban(member, 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)),
             ],
         )
</code_context>

<issue_to_address>
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.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
            actions=[
                (ctx.guild.ban(user, 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)),
            ],
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 60 to -63
dm_action="banned",
actions=[
(ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
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)),
],

Copy link

cloudflare-workers-and-pages bot commented Jul 26, 2025

Deploying tux with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8b08331
Status: ✅  Deploy successful!
Preview URL: https://0d5c2f79.tux-afh.pages.dev
Branch Preview URL: https://ban-fix.tux-afh.pages.dev

View logs

@cherryl1k cherryl1k changed the title fix: enable the banning nonserver memeber fix: enable the banning nonserver users Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant