[Core] Use the discord.User converter for the dm command to avoid accepting only the id of a user. #5781

Closed
AAA3A-AAA3A wants to merge 6 commits from patch-4 into V3/develop
AAA3A-AAA3A commented 2022-06-22 20:51:44 +02:00 (Migrated from github.com)

Description of the changes

Hello,
Here is a PR to allow the dm command to use the discord.User converter 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

### Description of the changes Hello, Here is a PR to allow the dm command to use the `discord.User` converter 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? <!-- Choose one (remove the line that doesn't apply): --> Yes <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
yamikaitou (Migrated from github.com) reviewed 2022-06-22 21:21:15 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
yamikaitou (Migrated from github.com) commented 2022-06-22 21:17:44 +02:00

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.

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.
AAA3A-AAA3A (Migrated from github.com) reviewed 2022-06-22 21:44:29 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
AAA3A-AAA3A (Migrated from github.com) commented 2022-06-22 21:44:29 +02:00

I agree with the verification if it is a bot or not. On the other hand, discord.User is a converter for users who have access to the bot, which means, under normal conditions, that there is no need to check.

I agree with the verification if it is a bot or not. On the other hand, `discord.User` is a converter for users who have access to the bot, which means, under normal conditions, that there is no need to check.
AAA3A-AAA3A (Migrated from github.com) reviewed 2022-06-22 21:45:59 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
AAA3A-AAA3A (Migrated from github.com) commented 2022-06-22 21:45:59 +02:00

Both discord.User and bot.get_user do not use the api. The converter will never give None as the user.

Both `discord.User` and `bot.get_user` do not use the api. The converter will never give `None` as the user.
yamikaitou (Migrated from github.com) reviewed 2022-06-22 21:51:33 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
yamikaitou (Migrated from github.com) commented 2022-06-22 21:51:33 +02:00

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

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
Flame442 (Migrated from github.com) reviewed 2022-06-22 21:52:18 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
Flame442 (Migrated from github.com) commented 2022-06-22 21:52:17 +02:00

bot.get_user does not, but iirc the discord.User converter does resort to a bot.fetch_user call if its get does not find the user. The fetch_user endpoint is also pretty restrictive, but this is a bot owner command, so I don't know how huge of a deal that is.

`bot.get_user` does not, but iirc the `discord.User` converter *does* resort to a `bot.fetch_user` call if its `get` does not find the user. The `fetch_user` endpoint is also pretty restrictive, but this *is* a bot owner command, so I don't know how huge of a deal that is.
AAA3A-AAA3A (Migrated from github.com) reviewed 2022-06-22 21:55:15 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
AAA3A-AAA3A (Migrated from github.com) commented 2022-06-22 21:55:15 +02:00

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.

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.
AAA3A-AAA3A (Migrated from github.com) reviewed 2022-06-22 22:12:52 +02:00
@ -4087,3 +4094,3 @@
)
else:
await ctx.send(_("Message delivered to {}").format(destination))
await ctx.send(_("Message delivered to {}.").format(user))
AAA3A-AAA3A (Migrated from github.com) commented 2022-06-22 22:12:51 +02:00

This is corrected. And I tested.

This is corrected. And I tested.
aikaterna commented 2022-06-22 23:27:16 +02:00 (Migrated from github.com)

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.

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.
AAA3A-AAA3A commented 2022-06-23 07:23:20 +02:00 (Migrated from github.com)

Change the converter of discord.User to not support untagged names if multiple users are found.

Change the converter of `discord.User` to not support untagged names if multiple users are found.
aikaterna commented 2022-06-23 17:10:10 +02:00 (Migrated from github.com)

Change the converter of discord.User to 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.

> Change the converter of `discord.User` to 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.
AAA3A-AAA3A commented 2022-06-23 17:55:02 +02:00 (Migrated from github.com)

Make a subclass of discord.ext.commands.converters.UserConverter. It could return a raise under certain conditions and then call super().convert().

Make a subclass of `discord.ext.commands.converters.UserConverter`. It could return a raise under certain conditions and then call `super().convert()`.
AAA3A-AAA3A commented 2022-07-10 16:57:05 +02:00 (Migrated from github.com)

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

image

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 ![image](https://user-images.githubusercontent.com/89632044/178150122-f30de64d-18b6-4ce3-b892-69bdf6485a50.png)
Jackenmen commented 2026-05-19 03:15:46 +02:00 (Migrated from github.com)

I don't think we really want this, sorry.

I don't think we really want this, sorry.

Pull request closed

Sign in to join this conversation.
No reviewers
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
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!5781
No description provided.