|
2 | 2 | from typing import TYPE_CHECKING, List, Optional, Union |
3 | 3 |
|
4 | 4 | from ...utils.attrs_utils import ClientSerializerMixin, convert_list, define, field |
| 5 | +from ...utils.missing import MISSING |
5 | 6 | from ..error import LibraryException |
6 | 7 | from .misc import Snowflake |
| 8 | +from .role import Role |
7 | 9 | from .user import User |
8 | 10 |
|
9 | 11 | if TYPE_CHECKING: |
@@ -109,6 +111,46 @@ async def get_all_of_guild( |
109 | 111 | res = await client.get_all_emoji(guild_id=_guild_id) |
110 | 112 | return [cls(**emoji, _client=client) for emoji in res] |
111 | 113 |
|
| 114 | + async def modify( |
| 115 | + self, |
| 116 | + guild_id: Union[int, Snowflake, "Guild"], |
| 117 | + name: Optional[str] = MISSING, |
| 118 | + roles: Optional[Union[List[Role], List[int]]] = MISSING, |
| 119 | + reason: Optional[str] = None, |
| 120 | + ) -> "Emoji": |
| 121 | + """ |
| 122 | + .. versionadded:: 4.4.0 |
| 123 | +
|
| 124 | + Edits the Emoji in a guild. |
| 125 | +
|
| 126 | + :param int guild_id: The id of the guild to edit the emoji on |
| 127 | + :param Optional[str] name: The name of the emoji. If not specified, the filename will be used |
| 128 | + :param Optional[Union[List[Role], List[int]]] roles: Roles allowed to use this emoji |
| 129 | + :param Optional[str] reason: The reason of the modification |
| 130 | + :return: The modified emoji object |
| 131 | + :rtype: Emoji |
| 132 | + """ |
| 133 | + if not self._client: |
| 134 | + raise LibraryException(code=13) |
| 135 | + |
| 136 | + payload: dict = {} |
| 137 | + |
| 138 | + if name is not MISSING: |
| 139 | + payload["name"] = name |
| 140 | + |
| 141 | + if roles is not MISSING: |
| 142 | + payload["roles"] = [int(role.id if isinstance(role, Role) else role) for role in roles] |
| 143 | + |
| 144 | + _guild_id = int(guild_id) if isinstance(guild_id, (int, Snowflake)) else int(guild_id.id) |
| 145 | + |
| 146 | + res = await self._client.modify_guild_emoji( |
| 147 | + guild_id=_guild_id, emoji_id=int(self.id), payload=payload, reason=reason |
| 148 | + ) |
| 149 | + |
| 150 | + self.update(res) |
| 151 | + |
| 152 | + return self |
| 153 | + |
112 | 154 | async def delete( |
113 | 155 | self, |
114 | 156 | guild_id: Union[int, Snowflake, "Guild"], |
|
0 commit comments