aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-09-26 23:02:28 -0400
committerRapptz <[email protected]>2016-09-26 23:02:28 -0400
commit9322bc78beb6f527746646aaf4dfe24476f3de4f (patch)
treea230b60103092ed5a03e0949d65ff2c45890572c
parentAdd support for "Do Not Disturb" and "Invisible" statuses. (diff)
downloaddiscord.py-9322bc78beb6f527746646aaf4dfe24476f3de4f.tar.xz
discord.py-9322bc78beb6f527746646aaf4dfe24476f3de4f.zip
Add the ability to add, delete, and edit custom emoji.
-rw-r--r--discord/client.py87
-rw-r--r--discord/http.py22
2 files changed, 109 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 87cee11a..a3579922 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -41,6 +41,7 @@ from .enums import ChannelType, ServerRegion, VerificationLevel, Status
from .voice_client import VoiceClient
from .iterators import LogsFromIterator
from .gateway import *
+from .emoji import Emoji
from .http import HTTPClient
import asyncio
@@ -2120,6 +2121,92 @@ class Client:
data = yield from self.http.estimate_pruned_members(server.id, days)
return data['pruned']
+ @asyncio.coroutine
+ def create_custom_emoji(self, server, *, name, image):
+ """|coro|
+
+ Creates a custom :class:`Emoji` for a :class:`Server`.
+
+ This endpoint is only allowed for user bots or white listed
+ bots. If this is done by a user bot then this is a local
+ emoji that can only be used inside that server.
+
+ There is currently a limit of 50 local emotes per server.
+
+ Parameters
+ -----------
+ server: :class:`Server`
+ The server to add the emoji to.
+ name: str
+ The emoji name. Must be at least 2 characters.
+ image: bytes
+ The *bytes-like* object representing the image data to use.
+ Only JPG and PNG images are supported.
+
+ Returns
+ --------
+ :class:`Emoji`
+ The created emoji.
+
+ Raises
+ -------
+ Forbidden
+ You are not allowed to create emojis.
+ HTTPException
+ An error occurred creating an emoji.
+ """
+
+ img = utils._bytes_to_base64_data(image)
+ data = yield from self.http.create_custom_emoji(server.id, name, img)
+ return Emoji(server=server, **data)
+
+ @asyncio.coroutine
+ def delete_custom_emoji(self, emoji):
+ """|coro|
+
+ Deletes a custom :class:`Emoji` from a :class:`Server`.
+
+ This follows the same rules as :meth:`create_custom_emoji`.
+
+ Parameters
+ -----------
+ emoji: :class:`Emoji`
+ The emoji to delete.
+
+ Raises
+ -------
+ Forbidden
+ You are not allowed to delete emojis.
+ HTTPException
+ An error occurred deleting the emoji.
+ """
+
+ yield from self.http.delete_custom_emoji(emoji.server.id, emoji.id)
+
+ @asyncio.coroutine
+ def edit_custom_emoji(self, emoji, *, name):
+ """|coro|
+
+ Edits a :class:`Emoji`.
+
+ Parameters
+ -----------
+ emoji: :class:`Emoji`
+ The emoji to edit.
+ name: str
+ The new emoji name.
+
+ Raises
+ -------
+ Forbidden
+ You are not allowed to edit emojis.
+ HTTPException
+ An error occurred editing the emoji.
+ """
+
+ yield from self.http.edit_custom_emoji(emoji.server.id, emoji.id, name=name)
+
+
# Invite management
def _fill_invite_data(self, data):
diff --git a/discord/http.py b/discord/http.py
index dd7c1f43..ada71f7c 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -425,6 +425,28 @@ class HTTPClient:
}
return self.get(url, params=params, bucket=_func_())
+ def create_custom_emoji(self, guild_id, name, image):
+ payload = {
+ 'name': name,
+ 'image': image
+ }
+
+ bucket = '%s:%s' % (_func_(), guild_id)
+ return self.post('{0.GUILDS}/{1}/emojis'.format(self, guild_id), json=payload, bucket=bucket)
+
+ def delete_custom_emoji(self, guild_id, emoji_id):
+ url = '{0.GUILDS}/{1}/emojis/{2}'.format(self, guild_id, emoji_id)
+ bucket = '%s:%s' % (_func_(), guild_id)
+ return self.delete(url, bucket=bucket)
+
+ def edit_custom_emoji(self, guild_id, emoji_id, *, name):
+ payload = {
+ 'name': name
+ }
+ url = '{0.GUILDS}/{1}/emojis/{2}'.format(self, guild_id, emoji_id)
+ bucket = '%s:%s' % (_func_(), guild_id)
+ return self.patch(url, bucket=bucket, json=payload)
+
# Invite management
def create_invite(self, channel_id, **options):