Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 70 additions & 4 deletions interactions/api/models/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ async def create_channel(
:param topic?: The topic of that channel
:type topic: Optional[str]
:param bitrate?: (voice channel only) The bitrate (in bits) of the voice channel
:type bitrate Optional[int]
:type bitrate: Optional[int]
:param user_limit?: (voice channel only) Maximum amount of users in the channel
:type user_limit: Optional[int]
:param rate_limit_per_use?: Amount of seconds a user has to wait before sending another message (0-21600)
Expand Down Expand Up @@ -779,19 +779,25 @@ async def modify_channel(
permission_overwrites: Optional[List[Overwrite]] = MISSING,
parent_id: Optional[int] = MISSING,
nsfw: Optional[bool] = MISSING,
archived: Optional[bool] = MISSING,
auto_archive_duration: Optional[int] = MISSING,
locked: Optional[bool] = MISSING,
reason: Optional[str] = None,
) -> Channel:
"""
Edits a channel of the guild.

.. note::
The fields `archived`, `auto_archive_duration` and `locked` require the provided channel to be a thread.

:param channel_id: The id of the channel to modify
:type channel_id: int
:param name?: The name of the channel, defaults to the current value of the channel
:type name: str
:param topic?: The topic of that channel, defaults to the current value of the channel
:type topic: Optional[str]
:param bitrate?: (voice channel only) The bitrate (in bits) of the voice channel, defaults to the current value of the channel
:type bitrate Optional[int]
:type bitrate: Optional[int]
:param user_limit?: (voice channel only) Maximum amount of users in the channel, defaults to the current value of the channel
:type user_limit: Optional[int]
:param rate_limit_per_use?: Amount of seconds a user has to wait before sending another message (0-21600), defaults to the current value of the channel
Expand All @@ -804,6 +810,12 @@ async def modify_channel(
:type permission_overwrites: Optional[Overwrite]
:param nsfw?: Whether the channel is nsfw or not, defaults to the current value of the channel
:type nsfw: Optional[bool]
:param archived?: Whether the thread is archived
:type archived: Optional[bool]
:param auto_archive_duration?: The time after the thread is automatically archived. One of 60, 1440, 4320, 10080
:type auto_archive_duration: Optional[int]
:param locked?: Whether the thread is locked
:type locked: Optional[bool]
:param reason: The reason for the edit
:type reason: Optional[str]
:return: The modified channel
Expand Down Expand Up @@ -843,10 +855,24 @@ async def modify_channel(
nsfw=_nsfw,
)

payload = payload._json

if (
archived is not MISSING or auto_archive_duration is not MISSING or locked is not MISSING
) and not ch.thread_metadata:
raise ValueError("The specified channel is not a Thread!")

if archived is not MISSING:
payload["archived"] = archived
if auto_archive_duration is not MISSING:
payload["auto_archive_duration"] = auto_archive_duration
if locked is not MISSING:
payload["locked"] = locked

res = await self._client.modify_channel(
channel_id=channel_id,
reason=reason,
payload=payload._json,
payload=payload,
)
return Channel(**res, _client=self._client)

Expand Down Expand Up @@ -1600,6 +1626,46 @@ async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Mem
)
return [Member(**member, _client=self._client) for member in res]

async def get_all_members(self) -> List[Member]:
"""
Gets all members of a guild.

.. warning:: Calling this method can lead to rate-limits in larger guilds.

:return: Returns a list of all members of the guild
:rtype: List[Member]
"""
if not self._client:
raise AttributeError("HTTPClient not found!")

_all_members: List[dict] = []
_last_member: Member
_members: List[dict] = await self._client.get_list_of_members(
guild_id=int(self.id), limit=100
)
if len(_members) == 100:
while len(_members) >= 100:
_all_members.extend(_members)
_last_member = Member(**_members[-1])
_members = await self._client.get_list_of_members(
guild_id=int(self.id), limit=100, after=int(_last_member.id)
)
_all_members.extend(_members)

return [Member(**_, _client=self._client) for _ in _all_members]

@property
def icon_url(self) -> str:
"""
Returns the URL of the guild's icon.
:return: URL of the guild's icon (None will be returned if none of icon is set)
:rtype: str
"""
if self.icon is not None:
url = f"https://cdn.discordapp.com/icons/{int(self.id)}/{self.icon}"
url += ".gif" if self.icon.startswith("a_") else ".png"
return url


class GuildPreview(DictSerializerMixin):
"""
Expand Down Expand Up @@ -1896,4 +1962,4 @@ def __init__(self, **kwargs):
self.entity_metadata = (
EventMetadata(**self.entity_metadata) if self._json.get("entity_metadata") else None
)
self.creator = User(**self.creator) if self._json.get("creator") else None
self.creator = User(**self.creator) if self._json.get("creator") else None
2 changes: 2 additions & 0 deletions interactions/api/models/guild.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ class Guild(DictSerializerMixin):
query: str,
limit: Optional[int] = 1
) -> List[Member]: ...
@property
def icon_url(self) -> str: ...

class GuildPreview(DictSerializerMixin):
_json: dict
Expand Down