From 6516932e67a50ad8539e44cc1fd009b80165816e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 16 Feb 2017 16:13:20 -0500 Subject: [PATCH] Fix Guild.bans to return a BanEntry object. --- discord/guild.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 2888b8227..89d5fb631 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -27,6 +27,8 @@ DEALINGS IN THE SOFTWARE. import copy import asyncio +from collections import namedtuple + from . import utils from .role import Role from .member import Member, VoiceState @@ -41,6 +43,8 @@ from .mixins import Hashable from .user import User from .invite import Invite +BanEntry = namedtuple('BanEntry', 'reason user') + class Guild(Hashable): """Represents a Discord guild. @@ -616,7 +620,12 @@ class Guild(Hashable): def bans(self): """|coro| - Retrieves all the :class:`User`\s that are banned from the guild. + Retrieves all the users that are banned from the guild. + + This coroutine returns a list of BanEntry objects. Which is a + namedtuple with a ``user`` field to denote the :class:`User` + that got banned along with a ``reason`` field specifying + why the user was banned that could be set to ``None``. You must have :attr:`Permissions.ban_members` permission to get this information. @@ -630,12 +639,14 @@ class Guild(Hashable): Returns -------- - list - A list of :class:`User` that have been banned. + List[BanEntry] + A list of BanEntry objects. """ data = yield from self._state.http.get_bans(self.id) - return [User(state=self._state, data=user) for user in data] + return [BanEntry(user=User(state=self._state, data=e['user']), + reason=e['reason']) + for e in data] @asyncio.coroutine def prune_members(self, *, days):