From 3521ae985add26c6df40727f12450da5cce7e125 Mon Sep 17 00:00:00 2001 From: iDutchy Date: Wed, 21 Oct 2020 17:44:46 -0500 Subject: [PATCH] added versionadded --- README.rst | 5 +++-- discord/channel.py | 4 +++- discord/client.py | 6 +++++ discord/ext/commands/bot.py | 8 +++++-- discord/flags.py | 4 +++- discord/guild.py | 44 +++++++++++++++++++++++++++++++++++-- docs/index.rst | 1 + 7 files changed, 64 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index d7f8e92b..f6514e9b 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,7 @@ Custom Features - Added ``Intents.from_list`` - Added support for ``int()`` to ``discord.User``, ``discord.Member``, ``discord.Emoji``, ``discord.Role``, ``discord.Guild``, ``discord.Message``, ``discord.TextChannel``, ``discord.VoiceChannel``, ``discord.CategoryChannel``, ``discord.Attachment`` and ``discord.Message``. This will return their id - Added support for ``str()`` to ``discord.Message``. This will return the message content +- Added ``Guild.try_member`` Key Features ------------- @@ -46,10 +47,10 @@ To install the library without full voice support, you can just run the followin .. code:: sh # Linux/macOS - python3 -m pip install -U git+https://github.com/iDutchy/discord.py + python3 -m pip install -U enhanced-dpy # Windows - py -3 -m pip install -U git+https://github.com/iDutchy/discord.py + py -3 -m pip install -U enhanced-dpy To install the development version, do the following: diff --git a/discord/channel.py b/discord/channel.py index 50effab0..7dad83a4 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -144,7 +144,9 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): @property def can_send(self): - """:class:`bool`: Checks if the bot can send messages""" + """:class:`bool`: Checks if the bot can send messages + + .. versionadded:: 1.5.0.1""" return self.guild.me.guild_permissions.send_messages def permissions_for(self, member): diff --git a/discord/client.py b/discord/client.py index 2e865379..537ec6d8 100644 --- a/discord/client.py +++ b/discord/client.py @@ -226,6 +226,8 @@ class Client: remove the need to set the color per embed, but can still be overridden by setting a color while creating an instance of an embed. + .. versionadded:: 1.5.0.1 + Attributes ----------- ws @@ -294,6 +296,8 @@ class Client: This will raise a TypeError if an improper format was passed. + .. versionadded:: 1.5.0.1 + Parameters ----------- color: Union[:class:`.Colour`, :class:`int`] @@ -1410,6 +1414,8 @@ class Client: Retrieves a :class:`~discord.User` based on their ID. This can only be used by bot accounts. + .. versionadded:: 1.5.0.1 + .. note:: This will first attempt to get the user from the cache. diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 26c4a5eb..a261f096 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -128,14 +128,18 @@ class BotBase(GroupMixin): @property def owner(self): - """:class:`discord.User`: The owner, retrieved from owner_id. In case of improper caching, this can return None""" + """:class:`discord.User`: The owner, retrieved from owner_id. In case of improper caching, this can return None + + .. versionadded:: 1.5.0.1""" if not self.owner_id or self.owner_ids: raise AttributeError('No owner_id specified or you used owner_ids. If you used owner_ids, please refer to `Bot.owners`') return self.get_user(self.owner_id) @property def owners(self): - """List[:class:`discord.User`]: The owners, retrieved from owner_ids. In case of improper caching, this list may not contain all owners.""" + """List[:class:`discord.User`]: The owners, retrieved from owner_ids. In case of improper caching, this list may not contain all owners. + + .. versionadded:: 1.5.0.1""" if not self.owner_ids or self.owner_id: raise TypeError('No owner_ids specified or you used owner_id. If you used owner_id, please refer to `Bot.owner`') owners = [] diff --git a/discord/flags.py b/discord/flags.py index fe89d305..94c2d7d7 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -405,7 +405,9 @@ class Intents(BaseFlags): @classmethod def from_list(cls, intents_list): """A factory method that creates a :class:`Intents` with everything enabled - that has been passed in the list.""" + that has been passed in the list. + + .. versionadded:: 1.5.0.1""" for item in intents_list: if item not in cls.VALID_FLAGS.keys(): intents_list.remove(item) diff --git a/discord/guild.py b/discord/guild.py index af45c45e..5bbd4431 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -520,12 +520,16 @@ class Guild(Hashable): @property def bots(self): - """List[:class:`Member`]: A list of bots that belong to this guild.""" + """List[:class:`Member`]: A list of bots that belong to this guild. + + .. versionadded:: 1.5.0.1""" return list(m for m in self._members.values() if m.bot) @property def humans(self): - """List[:class:`Member`]: A list of humans that belong to this guild.""" + """List[:class:`Member`]: A list of humans that belong to this guild. + + .. versionadded:: 1.5.0.1""" return list(m for m in self._members.values() if not m.bot) def get_member(self, user_id): @@ -1293,6 +1297,42 @@ class Guild(Hashable): """ return MemberIterator(self, limit=limit, after=after) + async def try_member(self, member_id): + """|coro| + + Retreives a :class:`Member` from a guild ID, and a member ID. + + .. versionadded:: 1.5.1.2 + + .. note:: + + This will first attempt to get the member from the cache. + If that fails, it will make an API call. + This method is an API call. For general usage, consider :meth:`get_member` instead. + + Parameters + ----------- + member_id: :class:`int` + The member's ID to fetch from. + + Raises + ------- + Forbidden + You do not have access to the guild. + HTTPException + Fetching the member failed. + + Returns + -------- + :class:`Member` + The member from the member ID. + """ + + member = self.get_member(member_id) + if member is None: + member = await self.fetch_member(member_id) + return member + async def fetch_member(self, member_id): """|coro| diff --git a/docs/index.rst b/docs/index.rst index 21d0c421..95a34c09 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,6 +32,7 @@ Custom Features - Added ``Intents.from_list`` - Added support for ``int()`` to ``discord.User``, ``discord.Member``, ``discord.Emoji``, ``discord.Role``, ``discord.Guild``, ``discord.Message``, ``discord.TextChannel``, ``discord.VoiceChannel``, ``discord.CategoryChannel``, ``discord.Attachment`` and ``discord.Message``. This will return their id - Added support for ``str()`` to ``discord.Message``. This will return the message content +- Added ``Guild.try_member`` Features --------