aboutsummaryrefslogtreecommitdiff
path: root/discord/template.py
diff options
context:
space:
mode:
authorNadir Chowdhury <[email protected]>2021-04-10 07:55:10 +0100
committerGitHub <[email protected]>2021-04-10 02:55:10 -0400
commit1efdef3ac34ebed98d643a6a1c273f3b176e8837 (patch)
treee835ade2564fe61dead5dee5ad67d67cca569c18 /discord/template.py
parentAdd typings for audit logs, integrations, and webhooks (diff)
downloaddiscord.py-1efdef3ac34ebed98d643a6a1c273f3b176e8837.tar.xz
discord.py-1efdef3ac34ebed98d643a6a1c273f3b176e8837.zip
Add typings for invites, templates, and bans
Diffstat (limited to 'discord/template.py')
-rw-r--r--discord/template.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/discord/template.py b/discord/template.py
index af2d0dc4..5b9ad871 100644
--- a/discord/template.py
+++ b/discord/template.py
@@ -22,6 +22,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
+from typing import Any, Optional, TYPE_CHECKING, overload
from .utils import parse_time, _get_as_snowflake, _bytes_to_base64_data
from .enums import VoiceRegion
from .guild import Guild
@@ -30,6 +31,9 @@ __all__ = (
'Template',
)
+if TYPE_CHECKING:
+ from .types.template import Template as TemplatePayload
+
class _FriendlyHttpAttributeErrorHelper:
__slots__ = ()
@@ -101,11 +105,11 @@ class Template:
The source guild.
"""
- def __init__(self, *, state, data):
+ def __init__(self, *, state, data: TemplatePayload):
self._state = state
self._store(data)
- def _store(self, data):
+ def _store(self, data: TemplatePayload):
self.code = data['code']
self.uses = data['usage_count']
self.name = data['name']
@@ -120,7 +124,7 @@ class Template:
guild = self._state._get_guild(id)
- if guild is None:
+ if guild is None and id:
source_serialised = data['serialized_source_guild']
source_serialised['id'] = id
state = _PartialTemplateState(state=self._state)
@@ -128,13 +132,13 @@ class Template:
self.source_guild = guild
- def __repr__(self):
+ def __repr__(self) -> str:
return (
f'<Template code={self.code!r} uses={self.uses} name={self.name!r}'
f' creator={self.creator!r} source_guild={self.source_guild!r}>'
)
- async def create_guild(self, name, region=None, icon=None):
+ async def create_guild(self, name: str, region: Optional[VoiceRegion] = None, icon: Any = None):
"""|coro|
Creates a :class:`.Guild` using the template.
@@ -174,7 +178,7 @@ class Template:
data = await self._state.http.create_from_template(self.code, name, region_value, icon)
return Guild(data=data, state=self._state)
- async def sync(self):
+ async def sync(self) -> None:
"""|coro|
Sync the template to the guild's current state.
@@ -197,7 +201,20 @@ class Template:
data = await self._state.http.sync_template(self.source_guild.id, self.code)
self._store(data)
- async def edit(self, **kwargs):
+ @overload
+ async def edit(
+ self,
+ *,
+ name: Optional[str] = ...,
+ description: Optional[str] = ...,
+ ) -> None:
+ ...
+
+ @overload
+ async def edit(self) -> None:
+ ...
+
+ async def edit(self, **kwargs) -> None:
"""|coro|
Edit the template metadata.
@@ -226,7 +243,7 @@ class Template:
data = await self._state.http.edit_template(self.source_guild.id, self.code, kwargs)
self._store(data)
- async def delete(self):
+ async def delete(self) -> None:
"""|coro|
Delete the template.