Skip to content

Conversation

Copy link

Copilot AI commented Jul 23, 2025

Summary

Adds proper error handling for discord.ext.commands.NoPrivateMessage exceptions to provide users with clear, helpful messages when they attempt to use guild-only commands in direct messages.

Problem

Currently, when users try to use commands decorated with @commands.guild_only() in DMs, they receive confusing technical error messages or unhandled exceptions. This creates a poor user experience and can lead to unnecessary support requests.

Solution

Changes Made

  1. Error Handler Configuration (tux/handlers/error.py):

    • Added commands.NoPrivateMessage to ERROR_CONFIG_MAP
    • Configured with user-friendly message: "This command can only be used in a server, not in direct messages."
    • Set send_to_sentry=False to prevent noise in error monitoring (appropriate for expected user behavior)
    • Uses default log_level="INFO" (appropriate for user errors, not system errors)
  2. Developer Testing Support (tux/cogs/admin/mock.py):

    • Added NoPrivateMessage test case to the mock error system
    • Allows developers to test this error handling scenario using /mock error

Impact

  • 38+ guild-only commands now provide clear error messages instead of confusing technical errors
  • Improved user experience - users understand why the command failed and what they need to do
  • Reduced monitoring noise - no Sentry events for expected user behavior
  • Consistent patterns - follows the same configuration style as other user-behavior errors like CheckFailure

Before/After

Before:

[Technical error message or unhandled exception]

After:

❌ This command can only be used in a server, not in direct messages.

Testing

  • Added comprehensive verification scripts to ensure proper configuration
  • Verified integration with existing guild-only commands across the codebase
  • Confirmed error handling follows established patterns for similar user-behavior errors
  • Added mock test case for developer testing

Commands Affected

This improvement affects all commands using @commands.guild_only(), including moderation commands like:

  • /ban, /unban, /tempban
  • /kick, /timeout
  • Server management commands
  • And many others

Users will now receive helpful guidance instead of confusing errors when trying to use these commands in DMs.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 23, 2025

🧙 Sourcery is reviewing your pull request!


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

@github-actions
Copy link
Contributor

Dependency Review

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

Scanned Files

None

Copilot AI changed the title [WIP] add error handling for discord.ext.commands.NoPrivateMessage(message=None) Add error handling for discord.ext.commands.NoPrivateMessage Jul 23, 2025
Copilot AI requested a review from electron271 July 23, 2025 23:13
@kzndotsh kzndotsh deleted the copilot/fix-8b435b86-ec4f-4fd1-afd9-d1cd07f59b16 branch December 3, 2025 10:33
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.

2 participants