diff --git a/discord/emoji.py b/discord/emoji.py index 21c11c717..158000fba 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 8f770b19a..46621e835 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 d5b8423e7..a40db3438 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)