aboutsummaryrefslogtreecommitdiff
path: root/discord/template.py
diff options
context:
space:
mode:
authorNadir Chowdhury <[email protected]>2021-02-23 08:58:03 +0000
committerGitHub <[email protected]>2021-02-23 03:58:03 -0500
commitfb773dc1dd46f7921d5ac41d503cecb685ea39a6 (patch)
treee70bac4c9d9ad2ebfeb87d1507dcef71c646e454 /discord/template.py
parentAdd remaining v6 message types (diff)
downloaddiscord.py-fb773dc1dd46f7921d5ac41d503cecb685ea39a6.tar.xz
discord.py-fb773dc1dd46f7921d5ac41d503cecb685ea39a6.zip
Add remaining template endpoints
Diffstat (limited to 'discord/template.py')
-rw-r--r--discord/template.py94
1 files changed, 87 insertions, 7 deletions
diff --git a/discord/template.py b/discord/template.py
index 1c333380..f528120c 100644
--- a/discord/template.py
+++ b/discord/template.py
@@ -105,7 +105,9 @@ class Template:
def __init__(self, *, state, data):
self._state = state
-
+ self._store(data)
+
+ def _store(self, data):
self.code = data['code']
self.uses = data['usage_count']
self.name = data['name']
@@ -117,11 +119,16 @@ class Template:
self.updated_at = parse_time(data.get('updated_at'))
id = _get_as_snowflake(data, 'source_guild_id')
- source_serialised = data['serialized_source_guild']
- source_serialised['id'] = id
- state = _PartialTemplateState(state=self._state)
- self.source_guild = Guild(data=source_serialised, state=state)
+ guild = self._state._get_guild(id)
+
+ if guild is None:
+ source_serialised = data['serialized_source_guild']
+ source_serialised['id'] = id
+ state = _PartialTemplateState(state=self._state)
+ guild = Guild(data=source_serialised, state=state)
+
+ self.source_guild = guild
def __repr__(self):
return '<Template code={0.code!r} uses={0.uses} name={0.name!r}' \
@@ -147,9 +154,9 @@ class Template:
Raises
------
- :exc:`.HTTPException`
+ HTTPException
Guild creation failed.
- :exc:`.InvalidArgument`
+ InvalidArgument
Invalid icon image format given. Must be PNG or JPG.
Returns
@@ -168,3 +175,76 @@ class Template:
data = await self._state.http.create_from_template(self.code, name, region, icon)
return Guild(data=data, state=self._state)
+
+ async def sync(self):
+ """|coro|
+
+ Sync the template to the guild's current state.
+
+ You must have the :attr:`~Permissions.manage_guild` permission in the
+ source guild to do this.
+
+ .. versionadded:: 1.7
+
+ Raises
+ -------
+ HTTPException
+ Editing the template failed.
+ Forbidden
+ You don't have permissions to edit the template.
+ NotFound
+ This template does not exist.
+ """
+
+ data = await self._state.http.sync_template(self.source_guild.id, self.code)
+ self._store(data)
+
+ async def edit(self, **kwargs):
+ """|coro|
+
+ Edit the template metadata.
+
+ You must have the :attr:`~Permissions.manage_guild` permission in the
+ source guild to do this.
+
+ .. versionadded:: 1.7
+
+ Parameters
+ ------------
+ name: Optional[:class:`str`]
+ The template's new name.
+ description: Optional[:class:`str`]
+ The template's description.
+
+ Raises
+ -------
+ HTTPException
+ Editing the template failed.
+ Forbidden
+ You don't have permissions to edit the template.
+ NotFound
+ This template does not exist.
+ """
+ data = await self._state.http.edit_template(self.source_guild.id, self.code, kwargs)
+ self._store(data)
+
+ async def delete(self):
+ """|coro|
+
+ Delete the template.
+
+ You must have the :attr:`~Permissions.manage_guild` permission in the
+ source guild to do this.
+
+ .. versionadded:: 1.7
+
+ Raises
+ -------
+ HTTPException
+ Editing the template failed.
+ Forbidden
+ You don't have permissions to edit the template.
+ NotFound
+ This template does not exist.
+ """
+ await self._state.http.delete_template(self.source_guild.id, self.code)