aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPikalaxALT <[email protected]>2018-07-19 17:12:24 -0400
committerRapptz <[email protected]>2018-08-22 21:06:09 -0400
commit0e6082c57d9139dbba6e998c147b34cae5018e78 (patch)
treecd22759ec8bc84af7d0df9ed678536327c4b1590
parentAdd python_requires (diff)
downloaddiscord.py-0e6082c57d9139dbba6e998c147b34cae5018e78.tar.xz
discord.py-0e6082c57d9139dbba6e998c147b34cae5018e78.zip
Implement roles kwarg for guild.create_custom_emoji and emoji.edit
-rw-r--r--discord/emoji.py8
-rw-r--r--discord/guild.py8
-rw-r--r--discord/http.py10
3 files changed, 18 insertions, 8 deletions
diff --git a/discord/emoji.py b/discord/emoji.py
index 21c11c71..158000fb 100644
--- a/discord/emoji.py
+++ b/discord/emoji.py
@@ -228,7 +228,7 @@ class Emoji(Hashable):
await self._state.http.delete_custom_emoji(self.guild.id, self.id, reason=reason)
- async def edit(self, *, name, reason=None):
+ async def edit(self, *, name, roles=None, reason=None):
"""|coro|
Edits the custom emoji.
@@ -242,6 +242,8 @@ class Emoji(Hashable):
-----------
name: str
The new emoji name.
+ roles: Optional[list[:class:`Role`]]
+ A :class:`list` of :class:`Role`s that can use this emoji. Leave empty to make it available to everyone.
reason: Optional[str]
The reason for editing this emoji. Shows up on the audit log.
@@ -253,4 +255,6 @@ class Emoji(Hashable):
An error occurred editing the emoji.
"""
- await self._state.http.edit_custom_emoji(self.guild.id, self.id, name=name, reason=reason)
+ if roles:
+ roles = [role.id for role in roles]
+ await self._state.http.edit_custom_emoji(self.guild.id, self.id, name=name, roles=roles, reason=reason)
diff --git a/discord/guild.py b/discord/guild.py
index 8f770b19..46621e83 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -986,7 +986,7 @@ class Guild(Hashable):
return result
- async def create_custom_emoji(self, *, name, image, reason=None):
+ async def create_custom_emoji(self, *, name, image, roles=None, reason=None):
"""|coro|
Creates a custom :class:`Emoji` for the guild.
@@ -1005,6 +1005,8 @@ class Guild(Hashable):
image: bytes
The *bytes-like* object representing the image data to use.
Only JPG and PNG images are supported.
+ roles: Optional[list[:class:`Role`]]
+ A :class:`list` of :class:`Role`s that can use this emoji. Leave empty to make it available to everyone.
reason: Optional[str]
The reason for creating this emoji. Shows up on the audit log.
@@ -1022,7 +1024,9 @@ class Guild(Hashable):
"""
img = utils._bytes_to_base64_data(image)
- data = await self._state.http.create_custom_emoji(self.id, name, img, reason=reason)
+ if roles:
+ roles = [role.id for role in roles]
+ data = await self._state.http.create_custom_emoji(self.id, name, img, roles=roles, reason=reason)
return self._state.store_emoji(self, data)
async def create_role(self, *, reason=None, **fields):
diff --git a/discord/http.py b/discord/http.py
index d5b8423e..a40db343 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -600,10 +600,11 @@ class HTTPClient:
}
return self.request(Route('GET', '/guilds/{guild_id}/prune', guild_id=guild_id), params=params)
- def create_custom_emoji(self, guild_id, name, image, *, reason=None):
+ def create_custom_emoji(self, guild_id, name, image, *, roles=None, reason=None):
payload = {
'name': name,
- 'image': image
+ 'image': image,
+ 'roles': roles or []
}
r = Route('POST', '/guilds/{guild_id}/emojis', guild_id=guild_id)
@@ -613,9 +614,10 @@ class HTTPClient:
r = Route('DELETE', '/guilds/{guild_id}/emojis/{emoji_id}', guild_id=guild_id, emoji_id=emoji_id)
return self.request(r, reason=reason)
- def edit_custom_emoji(self, guild_id, emoji_id, *, name, reason=None):
+ def edit_custom_emoji(self, guild_id, emoji_id, *, name, roles=None, reason=None):
payload = {
- 'name': name
+ 'name': name,
+ 'roles': roles or []
}
r = Route('PATCH', '/guilds/{guild_id}/emojis/{emoji_id}', guild_id=guild_id, emoji_id=emoji_id)
return self.request(r, json=payload, reason=reason)