Red-DiscordBot
Red-DiscordBot copied to clipboard
[Core] Use the `discord.User` converter for the dm command to avoid accepting only the id of a user.
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
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.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.
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 call super().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