Browse Source

Add fetch custom emoji, all custom emojis; Add user property to Emoji

pull/2049/head
NCPlayz 6 years ago
committed by Rapptz
parent
commit
1d701f32b6
  1. 8
      discord/emoji.py
  2. 44
      discord/guild.py
  3. 6
      discord/http.py

8
discord/emoji.py

@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE.
from .asset import Asset
from . import utils
from .user import User
class PartialEmoji:
"""Represents a "partial" emoji.
@ -164,8 +165,11 @@ class Emoji:
If this emoji is managed by a Twitch integration.
guild_id: :class:`int`
The guild ID the emoji belongs to.
user: Optional[:class:`User`]
The user that created the emoji. This can only be retrieved using :meth:`Guild.fetch_emoji`.
"""
__slots__ = ('require_colons', 'animated', 'managed', 'id', 'name', '_roles', 'guild_id', '_state')
__slots__ = ('require_colons', 'animated', 'managed', 'id', 'name', '_roles', 'guild_id',
'_state', 'user')
def __init__(self, *, guild, state, data):
self.guild_id = guild.id
@ -179,6 +183,8 @@ class Emoji:
self.name = emoji['name']
self.animated = emoji.get('animated', False)
self._roles = utils.SnowflakeList(map(int, emoji.get('roles', [])))
user = emoji.get('user')
self.user = User(state=self._state, data=user) if user else None
def _iterator(self):
for attr in self.__slots__:

44
discord/guild.py

@ -31,6 +31,7 @@ from . import utils
from .role import Role
from .member import Member, VoiceState
from .activity import create_activity
from .emoji import Emoji
from .permissions import PermissionOverwrite
from .colour import Colour
from .errors import InvalidArgument, ClientException
@ -1143,6 +1144,49 @@ class Guild(Hashable):
return result
async def fetch_emojis(self):
"""|coro|
Retrieves all custom :class:`Emoji`s from the guild.
Raises
---------
HTTPException
An error occurred fetching the emojis.
Returns
--------
List[:class:`Emoji`]
The retrieved emojis.
"""
data = await self._state.http.get_all_custom_emojis(self.id)
return [Emoji(guild=self, state=self._state, data=d) for d in data]
async def fetch_emoji(self, emoji_id):
"""|coro|
Retrieves a custom :class:`Emoji` from the guild.
Parameters
-------------
emoji_id: :class:`int`
The emoji's ID.
Raises
---------
NotFound
The emoji requested could not be found.
HTTPException
An error occurred fetching the emoji.
Returns
--------
:class:`Emoji`
The retrieved emoji.
"""
data = await self._state.http.get_custom_emoji(self.id, emoji_id)
return Emoji(guild=self, state=self._state, data=data)
async def create_custom_emoji(self, *, name, image, roles=None, reason=None):
r"""|coro|

6
discord/http.py

@ -627,6 +627,12 @@ class HTTPClient:
}
return self.request(Route('GET', '/guilds/{guild_id}/prune', guild_id=guild_id), params=params)
def get_all_custom_emojis(self, guild_id):
return self.request(Route('GET', '/guilds/{guild_id}/emojis', guild_id=guild_id))
def get_custom_emoji(self, guild_id, emoji_id):
return self.request(Route('GET', '/guilds/{guild_id}/emojis/{emoji_id}', guild_id=guild_id, emoji_id=emoji_id))
def create_custom_emoji(self, guild_id, name, image, *, roles=None, reason=None):
payload = {
'name': name,

Loading…
Cancel
Save