Skip to content

Commit aa4b497

Browse files
example-gitsilasaryLordOfPollspre-commit-ci[bot]
authored
feat: allow editing for guild role icons (#1558)
* chore: Version bump Signed-off-by: LordOfPolls <dev@lordofpolls.com> * Implemented role icon edit * added role icon editing to the edit method * Update misc_utils.py * ci: correct from checks. * fixed formatting, added return formatting indicator * Noticed that interactions.client.utils.serializer already had the functions I added to misc_utils. Undid those changes and tidied up the code in role.py to reflect the already existing converter. Added an error raise if both icon and unicode emojis are used in one edit (the api requires only one is provided.) * Cleaned up the docstring and moved the icon serialization cleaned up the docstring to better align with requirements, moved the icon serialization so the payload's code is a bit easier to follow at a glance. * Added UPLOADABLE_TYPE per comment --------- Signed-off-by: LordOfPolls <dev@lordofpolls.com> Co-authored-by: Katelyn Gigante <clockwork.singularity@gmail.com> Co-authored-by: LordOfPolls <dev@lordofpolls.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2d3c2c0 commit aa4b497

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

interactions/client/utils/misc_utils.py

100644100755
File mode changed.

interactions/models/discord/role.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from typing import Any, TYPE_CHECKING
33

44
import attrs
5-
65
from interactions.client.const import MISSING, T, Missing
76
from interactions.client.utils import nulled_boolean_get
87
from interactions.client.utils.attr_converters import optional as optional_c
9-
from interactions.client.utils.serializer import dict_filter
8+
from interactions.client.utils.serializer import dict_filter, to_image_data
109
from interactions.models.discord.asset import Asset
10+
from interactions.models.discord.file import UPLOADABLE_TYPE
1111
from interactions.models.discord.color import COLOR_TYPES, Color, process_color
1212
from interactions.models.discord.emoji import PartialEmoji
1313
from interactions.models.discord.enums import Permissions
@@ -187,6 +187,8 @@ async def edit(
187187
color: Color | COLOR_TYPES | None = None,
188188
hoist: bool | None = None,
189189
mentionable: bool | None = None,
190+
icon: bytes | UPLOADABLE_TYPE | None = None,
191+
unicode_emoji: str | None = None,
190192
) -> "Role":
191193
"""
192194
Edit this role, all arguments are optional.
@@ -197,20 +199,29 @@ async def edit(
197199
color: The color of the role
198200
hoist: whether the role should be displayed separately in the sidebar
199201
mentionable: whether the role should be mentionable
202+
icon: (Guild Level 2+) Bytes-like object representing the icon; supports PNG, JPEG and WebP
203+
unicode_emoji: (Guild Level 2+) Unicode emoji for the role; can't be used with icon
200204
201205
Returns:
202206
Role with updated information
203207
204208
"""
205209
color = process_color(color)
206210

211+
if icon and unicode_emoji:
212+
raise ValueError("Cannot pass both icon and unicode_emoji")
213+
if icon:
214+
icon = to_image_data(icon)
215+
207216
payload = dict_filter(
208217
{
209218
"name": name,
210219
"permissions": permissions,
211220
"color": color,
212221
"hoist": hoist,
213222
"mentionable": mentionable,
223+
"icon": icon,
224+
"unicode_emoji": unicode_emoji,
214225
}
215226
)
216227

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "interactions.py"
3-
version = "5.9.2"
3+
version = "5.10.0"
44
description = "Easy, simple, scalable and modular: a Python API wrapper for interactions."
55
authors = [
66
"LordOfPolls <dev@lordofpolls.com>",

0 commit comments

Comments
 (0)