[Core] Use the discord.User converter for the dm command to avoid accepting only the id of a user. #5781
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!5781
Loading…
Reference in a new issue
No description provided.
Delete branch "patch-4"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description of the changes
Hello,
Here is a PR to allow the dm command to use the
discord.Userconverter to support usernames and mentions as valid command arguments.We had talked about this quickly on the main Red server and you were not against the idea.
I know that the changes for dpy2 are more important. I didn't open a discussion because the change doesn't really require much thought and is just a minor change to a basic command.
Thanks in advance for your help,
AAA3A
Have the changes in this PR been tested?
Yes
@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))You should retain the check to see if the user is a Bot. It'd also be nice to retain the check to see if the user shares a server with the bot.
@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))I agree with the verification if it is a bot or not. On the other hand,
discord.Useris a converter for users who have access to the bot, which means, under normal conditions, that there is no need to check.@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))Both
discord.Userandbot.get_userdo not use the api. The converter will never giveNoneas the user.@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))As of d.py 1.6, the converter does indeed perform an API call if the user does not exist in the cache. In my testing as well, I was able to successfully get the user data of someone not shared with the bot
@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))bot.get_userdoes not, but iirc thediscord.Userconverter does resort to abot.fetch_usercall if itsgetdoes not find the user. Thefetch_userendpoint is also pretty restrictive, but this is a bot owner command, so I don't know how huge of a deal that is.@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))So the user may not share a server with the bot? That's a bit silly. Dpy should have a converter that only works on shared users.
@ -4087,3 +4094,3 @@)else:await ctx.send(_("Message delivered to {}").format(destination))await ctx.send(_("Message delivered to {}.").format(user))This is corrected. And I tested.
What happens when your bot can see five users named "John" that are not in your server, and you try to target "John" and it blindly resolves to a different one than you wanted? While this sort of PR may be convenient for you in what you are thinking for your use cases, IDs provide a way of contacting a user that is 100% not going to be misconstrued and I feel like it's less nebulous than trying to provide a name where the bot chooses with no feedback.
Change the converter of
discord.Userto not support untagged names if multiple users are found.To me, this sentence reads like you're suggesting that we should go and make a PR to discord.py over this, which is not exactly ideal and most likely won't be happening.
Make a subclass of
discord.ext.commands.converters.UserConverter. It could return a raise under certain conditions and then callsuper().convert().Hello,
I have subclassed the user converter so that it blocks an argument without a specified tag. This code necessarily works because it first checks whether it is an id or not, normally, before spotting the #, exactly as in dpy.
(Tested under normal conditions under the latest development version of Red 3.5 but also of dpy2, using a patch file.)
I don't know if this is really good for Core or if the method used is good (maybe add an equivalent to Red or dpy?).
Thanks in advance,
AAA3A
I don't think we really want this, sorry.
Pull request closed