Sticker
class
StickerTypes (IntEnum)
¶
Types of sticker.
Source code in naff/models/discord/sticker.py
class StickerTypes(IntEnum):
"""Types of sticker."""
STANDARD = 1
"""An official sticker in a pack, part of Nitro or in a removed purchasable pack."""
GUILD = 2
"""A sticker uploaded to a Boosted guild for the guild's members."""
class
StickerFormatTypes (IntEnum)
¶
File formats for stickers.
Source code in naff/models/discord/sticker.py
class StickerFormatTypes(IntEnum):
"""File formats for stickers."""
PNG = 1
APNG = 2
LOTTIE = 3
attrs
class
StickerItem (DiscordObject)
¶
Attr attributes:
Name | Type | Description |
---|---|---|
id |
int |
Discord unique snowflake ID |
name |
str |
Name of the sticker. |
format_type |
StickerFormatTypes |
Type of sticker image format. |
Source code in naff/models/discord/sticker.py
@define(kw_only=False)
class StickerItem(DiscordObject):
name: str = field(repr=True)
"""Name of the sticker."""
format_type: StickerFormatTypes = field(repr=True, converter=StickerFormatTypes)
"""Type of sticker image format."""
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/sticker.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
property
readonly
created_at: models.Timestamp
¶
Returns a timestamp representing the date-time this discord object was created.
:Returns:
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/sticker.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
attrs
class
Sticker (StickerItem)
¶
Represents a sticker that can be sent in messages.
Attr attributes:
Name | Type | Description |
---|---|---|
id |
int |
Discord unique snowflake ID |
pack_id |
Optional[Snowflake_Type] |
For standard stickers, id of the pack the sticker is from. |
description |
Optional[str] |
Description of the sticker. |
tags |
str |
autocomplete/suggestion tags for the sticker (max 200 characters) |
type |
Union[naff.models.discord.sticker.StickerTypes, int] |
Type of sticker. |
available |
Optional[bool] |
Whether this guild sticker can be used, may be false due to loss of Server Boosts. |
sort_value |
Optional[int] |
The standard sticker's sort order within its pack. |
Source code in naff/models/discord/sticker.py
@define()
class Sticker(StickerItem):
"""Represents a sticker that can be sent in messages."""
pack_id: Optional["Snowflake_Type"] = field(default=None, converter=optional(to_snowflake))
"""For standard stickers, id of the pack the sticker is from."""
description: Optional[str] = field(default=None)
"""Description of the sticker."""
tags: str = field()
"""autocomplete/suggestion tags for the sticker (max 200 characters)"""
type: Union[StickerTypes, int] = field(converter=StickerTypes)
"""Type of sticker."""
available: Optional[bool] = field(default=True)
"""Whether this guild sticker can be used, may be false due to loss of Server Boosts."""
sort_value: Optional[int] = field(default=None)
"""The standard sticker's sort order within its pack."""
_user_id: Optional["Snowflake_Type"] = field(default=None, converter=optional(to_snowflake))
_guild_id: Optional["Snowflake_Type"] = field(default=None, converter=optional(to_snowflake))
async def fetch_creator(self) -> "User":
"""
Fetch the user who created this emoji.
Returns:
User object
"""
return await self._client.cache.fetch_user(self._user_id)
def get_creator(self) -> "User":
"""
Get the user who created this emoji.
Returns:
User object
"""
return self._client.cache.get_user(self._user_id)
async def fetch_guild(self) -> "Guild":
"""
Fetch the guild associated with this emoji.
Returns:
Guild object
"""
return await self._client.cache.fetch_guild(self._guild_id)
def get_guild(self) -> "Guild":
"""
Get the guild associated with this emoji.
Returns:
Guild object
"""
return self._client.cache.get_guild(self._guild_id)
async def edit(
self,
name: Absent[Optional[str]] = MISSING,
description: Absent[Optional[str]] = MISSING,
tags: Absent[Optional[str]] = MISSING,
reason: Absent[Optional[str]] = MISSING,
) -> "Sticker":
"""
Edit a sticker.
Args:
name: New name of the sticker
description: New description of the sticker
tags: New tags of the sticker
reason: Reason for the edit
Returns:
The updated sticker instance
"""
if not self._guild_id:
raise ValueError("You can only edit guild stickers.")
payload = dict_filter_none({"name": name, "description": description, "tags": tags})
sticker_data = await self._client.http.modify_guild_sticker(payload, self._guild_id, self.id, reason)
return self.update_from_dict(sticker_data)
async def delete(self, reason: Optional[str] = MISSING) -> None:
"""
Delete a sticker.
Args:
reason: Reason for the deletion
Raises:
ValueError: If you attempt to delete a non-guild sticker
"""
if not self._guild_id:
raise ValueError("You can only delete guild stickers.")
await self._client.http.delete_guild_sticker(self._guild_id, self.id, reason)
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/sticker.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
async
method
fetch_creator(self)
¶
Fetch the user who created this emoji.
Returns:
Type | Description |
---|---|
User |
User object |
Source code in naff/models/discord/sticker.py
async def fetch_creator(self) -> "User":
"""
Fetch the user who created this emoji.
Returns:
User object
"""
return await self._client.cache.fetch_user(self._user_id)
inherited
property
readonly
created_at: models.Timestamp
¶
Returns a timestamp representing the date-time this discord object was created.
:Returns:
method
get_creator(self)
¶
Get the user who created this emoji.
Returns:
Type | Description |
---|---|
User |
User object |
Source code in naff/models/discord/sticker.py
def get_creator(self) -> "User":
"""
Get the user who created this emoji.
Returns:
User object
"""
return self._client.cache.get_user(self._user_id)
async
method
fetch_guild(self)
¶
Fetch the guild associated with this emoji.
Returns:
Type | Description |
---|---|
Guild |
Guild object |
Source code in naff/models/discord/sticker.py
async def fetch_guild(self) -> "Guild":
"""
Fetch the guild associated with this emoji.
Returns:
Guild object
"""
return await self._client.cache.fetch_guild(self._guild_id)
method
get_guild(self)
¶
Get the guild associated with this emoji.
Returns:
Type | Description |
---|---|
Guild |
Guild object |
Source code in naff/models/discord/sticker.py
def get_guild(self) -> "Guild":
"""
Get the guild associated with this emoji.
Returns:
Guild object
"""
return self._client.cache.get_guild(self._guild_id)
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/sticker.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)
async
method
edit(self, name, description, tags, reason)
¶
Edit a sticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Union[str, NoneType, naff.client.const.Missing] |
New name of the sticker |
Missing |
description |
Union[str, NoneType, naff.client.const.Missing] |
New description of the sticker |
Missing |
tags |
Union[str, NoneType, naff.client.const.Missing] |
New tags of the sticker |
Missing |
reason |
Union[str, NoneType, naff.client.const.Missing] |
Reason for the edit |
Missing |
Returns:
Type | Description |
---|---|
Sticker |
The updated sticker instance |
Source code in naff/models/discord/sticker.py
async def edit(
self,
name: Absent[Optional[str]] = MISSING,
description: Absent[Optional[str]] = MISSING,
tags: Absent[Optional[str]] = MISSING,
reason: Absent[Optional[str]] = MISSING,
) -> "Sticker":
"""
Edit a sticker.
Args:
name: New name of the sticker
description: New description of the sticker
tags: New tags of the sticker
reason: Reason for the edit
Returns:
The updated sticker instance
"""
if not self._guild_id:
raise ValueError("You can only edit guild stickers.")
payload = dict_filter_none({"name": name, "description": description, "tags": tags})
sticker_data = await self._client.http.modify_guild_sticker(payload, self._guild_id, self.id, reason)
return self.update_from_dict(sticker_data)
async
method
delete(self, reason)
¶
Delete a sticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reason |
Optional[str] |
Reason for the deletion |
Missing |
Exceptions:
Type | Description |
---|---|
ValueError |
If you attempt to delete a non-guild sticker |
Source code in naff/models/discord/sticker.py
async def delete(self, reason: Optional[str] = MISSING) -> None:
"""
Delete a sticker.
Args:
reason: Reason for the deletion
Raises:
ValueError: If you attempt to delete a non-guild sticker
"""
if not self._guild_id:
raise ValueError("You can only delete guild stickers.")
await self._client.http.delete_guild_sticker(self._guild_id, self.id, reason)
attrs
class
StickerPack (DiscordObject)
¶
Represents a pack of standard stickers.
Attr attributes:
Name | Type | Description |
---|---|---|
id |
int |
Discord unique snowflake ID |
stickers |
List[Sticker] |
The stickers in the pack. |
name |
str |
Name of the sticker pack. |
sku_id |
Snowflake_Type |
id of the pack's SKU. |
cover_sticker_id |
Optional[Snowflake_Type] |
id of a sticker in the pack which is shown as the pack's icon. |
description |
str |
Description of the sticker pack. |
banner_asset_id |
Snowflake_Type |
id of the sticker pack's banner image. |
Source code in naff/models/discord/sticker.py
@define()
class StickerPack(DiscordObject):
"""Represents a pack of standard stickers."""
stickers: List["Sticker"] = field(factory=list)
"""The stickers in the pack."""
name: str = field(repr=True)
"""Name of the sticker pack."""
sku_id: "Snowflake_Type" = field(repr=True)
"""id of the pack's SKU."""
cover_sticker_id: Optional["Snowflake_Type"] = field(default=None)
"""id of a sticker in the pack which is shown as the pack's icon."""
description: str = field()
"""Description of the sticker pack."""
banner_asset_id: "Snowflake_Type" = field() # TODO CDN Asset
"""id of the sticker pack's banner image."""
inherited
method
update_from_dict(self, data)
¶
Updates object attribute(s) with new json data received from discord api.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
The json data received from discord api. |
required |
Returns:
Type | Description |
---|---|
~T |
The updated object class instance. |
Source code in naff/models/discord/sticker.py
def update_from_dict(self, data) -> T:
data = self._process_dict(data, self._client)
for key, value in self._filter_kwargs(data, self._get_keys()).items():
# todo improve
setattr(self, key, value)
return self
inherited
property
readonly
created_at: models.Timestamp
¶
Returns a timestamp representing the date-time this discord object was created.
:Returns:
inherited
method
to_dict(self)
¶
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
Type | Description |
---|---|
Dict[str, Any] |
The exported dictionary. |
Source code in naff/models/discord/sticker.py
def to_dict(self) -> Dict[str, Any]:
"""
Exports object into dictionary representation, ready to be sent to discord api.
Returns:
The exported dictionary.
"""
self._check_object()
return serializer.to_dict(self)