Red-DiscordBot icon indicating copy to clipboard operation
Red-DiscordBot copied to clipboard

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

Open AAA3A-AAA3A opened this issue 2 years ago • 5 comments

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

AAA3A-AAA3A avatar Jun 22 '22 18:06 AAA3A-AAA3A

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.

aikaterna avatar Jun 22 '22 21:06 aikaterna

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

AAA3A-AAA3A avatar Jun 23 '22 05:06 AAA3A-AAA3A

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.

aikaterna avatar Jun 23 '22 15:06 aikaterna

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

AAA3A-AAA3A avatar Jun 23 '22 15:06 AAA3A-AAA3A

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

AAA3A-AAA3A avatar Jul 10 '22 14:07 AAA3A-AAA3A