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

Allow discord.ClientUser or discord.BaseUser for Config.user

Open madebylydia opened this issue 3 years ago • 2 comments

What component of Red (cog, command, API) would you like to see improvements on?

API: Config

Describe the enhancement you're suggesting.

Currently, the method Config.user's typehint only allow discord.User, but it may be common for certain developers to use Red's user instance when calling Config.user, it is my case, but doing self.bot.user (Where self.bot is a redbot.bot.Red instance) will return a discord.ClientUser, which does not inherit from discord.User.

Here is my proposal:

  1. Change the user's typehint of Config.user to: discord.BaseUser (Which is both implemented by discord.User and discord.ClientUser, and that contains the user's ID)
  2. Change the user's typehint of Config.user to: typing.Union[discord.User, discord.ClientUser]

Both solution shouldn't introduce any breaking changes. I can drop a PR ASAP if you are okay with such modification.

Anything else?

Here is a live action of the issue: image

Alternative: Adding # type: ignore at the end of the affected line

madebylydia avatar Jul 02 '22 07:07 madebylydia

The type hint is discord.abc.User so it accepts all user types. The docstring uses discord.User so that could be fixed.

The screenshotted error is about you trying to pass a variable that might be None, not because of you trying to pass ClientUser.

Jackenmen avatar Jul 02 '22 13:07 Jackenmen

My bad on that one, I just paid too much attention to the docstring and VSC... Damn me. image I'll correct the docstring at least... Sorry for the wrong infos 😰

madebylydia avatar Jul 02 '22 15:07 madebylydia