aboutsummaryrefslogtreecommitdiff
path: root/discord/ext
diff options
context:
space:
mode:
authorRapptz <[email protected]>2018-09-24 21:05:41 -0400
committerRapptz <[email protected]>2018-09-24 21:08:48 -0400
commit3d03dbc45179f645b59838729047e896cc387049 (patch)
tree63592f4d631c33ee0b22b7f6bb57818ad48b2671 /discord/ext
parentTake the default role property into account when comparing roles. (diff)
downloaddiscord.py-3d03dbc45179f645b59838729047e896cc387049.tar.xz
discord.py-3d03dbc45179f645b59838729047e896cc387049.zip
Change internal role storage in Guild to a dict instead of a list.
This adds the following APIs: * Guild.get_role This removes the following APIs: * Guild.role_hierarchy To compensate for the removed APIs, Guild.roles is now a sorted list based on hierarchy. The first element will always be the @everyone role. This speeds up access at the cost of some memory, theoretically.
Diffstat (limited to 'discord/ext')
-rw-r--r--discord/ext/commands/converter.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py
index 461abee7..c9e91211 100644
--- a/discord/ext/commands/converter.py
+++ b/discord/ext/commands/converter.py
@@ -320,8 +320,11 @@ class RoleConverter(IDConverter):
raise NoPrivateMessage()
match = self._get_id_match(argument) or re.match(r'<@&([0-9]+)>$', argument)
- params = dict(id=int(match.group(1))) if match else dict(name=argument)
- result = discord.utils.get(guild.roles, **params)
+ if match:
+ result = guild.get_role(int(match.group(1)))
+ else:
+ result = discord.utils.get(guild._roles.values(), name=argument)
+
if result is None:
raise BadArgument('Role "{}" not found.'.format(argument))
return result
@@ -454,8 +457,8 @@ class clean_content(Converter):
)
if ctx.guild:
- def resolve_role(id, *, _find=discord.utils.find, _roles=ctx.guild.roles):
- r = _find(lambda x: x.id == id, _roles)
+ def resolve_role(_id, *, _find=ctx.guild.get_role):
+ r = _find(_id, _roles)
return '@' + r.name if r else '@deleted-role'
transformations.update(