Browse Source

Merge branch 'Rapptz:master' into new-pins-endpoint

pull/10205/head
Soheab 4 weeks ago
committed by GitHub
parent
commit
2126e8848e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      MANIFEST.in
  2. 69
      discord/app_commands/models.py
  3. 16
      discord/guild.py
  4. 4
      discord/threads.py
  5. 14
      discord/types/interactions.py

2
MANIFEST.in

@ -1,5 +1,5 @@
include README.rst
include LICENSE
include requirements.txt
include discord/bin/*.dll
include discord/bin/*
include discord/py.typed

69
discord/app_commands/models.py

@ -26,7 +26,7 @@ from __future__ import annotations
from datetime import datetime
from .errors import MissingApplicationID
from ..flags import AppCommandContext, AppInstallationType
from ..flags import AppCommandContext, AppInstallationType, ChannelFlags
from .translator import TranslationContextLocation, TranslationContext, locale_str, Translator
from ..permissions import Permissions
from ..enums import (
@ -575,6 +575,35 @@ class AppCommandChannel(Hashable):
the application command in that channel.
guild_id: :class:`int`
The guild ID this channel belongs to.
category_id: Optional[:class:`int`]
The category channel ID this channel belongs to, if applicable.
.. versionadded:: 2.6
topic: Optional[:class:`str`]
The channel's topic. ``None`` if it doesn't exist.
.. versionadded:: 2.6
position: :class:`int`
The position in the channel list. This is a number that starts at 0. e.g. the
top channel is position 0.
.. versionadded:: 2.6
last_message_id: Optional[:class:`int`]
The last message ID of the message sent to this channel. It may
*not* point to an existing or valid message.
.. versionadded:: 2.6
slowmode_delay: :class:`int`
The number of seconds a member must wait between sending messages
in this channel. A value of ``0`` denotes that it is disabled.
Bots and users with :attr:`~discord.Permissions.manage_channels` or
:attr:`~discord.Permissions.manage_messages` bypass slowmode.
.. versionadded:: 2.6
nsfw: :class:`bool`
If the channel is marked as "not safe for work" or "age restricted".
.. versionadded:: 2.6
"""
__slots__ = (
@ -583,6 +612,14 @@ class AppCommandChannel(Hashable):
'name',
'permissions',
'guild_id',
'topic',
'nsfw',
'position',
'category_id',
'slowmode_delay',
'last_message_id',
'_last_pin',
'_flags',
'_state',
)
@ -599,6 +636,14 @@ class AppCommandChannel(Hashable):
self.type: ChannelType = try_enum(ChannelType, data['type'])
self.name: str = data['name']
self.permissions: Permissions = Permissions(int(data['permissions']))
self.topic: Optional[str] = data.get('topic')
self.position: int = data.get('position') or 0
self.nsfw: bool = data.get('nsfw') or False
self.category_id: Optional[int] = _get_as_snowflake(data, 'parent_id')
self.slowmode_delay: int = data.get('rate_limit_per_user') or 0
self.last_message_id: Optional[int] = _get_as_snowflake(data, 'last_message_id')
self._last_pin: Optional[datetime] = parse_time(data.get('last_pin_timestamp'))
self._flags: int = data.get('flags', 0)
def __str__(self) -> str:
return self.name
@ -611,6 +656,28 @@ class AppCommandChannel(Hashable):
"""Optional[:class:`~discord.Guild`]: The channel's guild, from cache, if found."""
return self._state._get_guild(self.guild_id)
@property
def flags(self) -> ChannelFlags:
""":class:`~discord.ChannelFlags`: The flags associated with this channel object.
.. versionadded:: 2.6
"""
return ChannelFlags._from_value(self._flags)
def is_nsfw(self) -> bool:
""":class:`bool`: Checks if the channel is NSFW.
.. versionadded:: 2.6
"""
return self.nsfw
def is_news(self) -> bool:
""":class:`bool`: Checks if the channel is a news channel.
.. versionadded:: 2.6
"""
return self.type == ChannelType.news
def resolve(self) -> Optional[GuildChannel]:
"""Resolves the application command channel to the appropriate channel
from cache if found.

16
discord/guild.py

@ -1560,6 +1560,7 @@ class Guild(Hashable):
rtc_region: Optional[str] = MISSING,
video_quality_mode: VideoQualityMode = MISSING,
overwrites: Mapping[Union[Role, Member, Object], PermissionOverwrite] = MISSING,
nsfw: bool = MISSING,
) -> VoiceChannel:
"""|coro|
@ -1597,6 +1598,10 @@ class Guild(Hashable):
The camera video quality for the voice channel's participants.
.. versionadded:: 2.0
nsfw: :class:`bool`
To mark the channel as NSFW or not.
.. versionadded:: 2.6
reason: Optional[:class:`str`]
The reason for creating this channel. Shows up on the audit log.
@ -1632,6 +1637,9 @@ class Guild(Hashable):
raise TypeError('video_quality_mode must be of type VideoQualityMode')
options['video_quality_mode'] = video_quality_mode.value
if nsfw is not MISSING:
options['nsfw'] = nsfw
data = await self._create_channel(
name, overwrites=overwrites, channel_type=ChannelType.voice, category=category, reason=reason, **options
)
@ -1653,6 +1661,7 @@ class Guild(Hashable):
rtc_region: Optional[str] = MISSING,
video_quality_mode: VideoQualityMode = MISSING,
overwrites: Mapping[Union[Role, Member, Object], PermissionOverwrite] = MISSING,
nsfw: bool = MISSING,
) -> StageChannel:
"""|coro|
@ -1696,6 +1705,10 @@ class Guild(Hashable):
The camera video quality for the voice channel's participants.
.. versionadded:: 2.2
nsfw: :class:`bool`
To mark the channel as NSFW or not.
.. versionadded:: 2.6
reason: Optional[:class:`str`]
The reason for creating this channel. Shows up on the audit log.
@ -1732,6 +1745,9 @@ class Guild(Hashable):
raise TypeError('video_quality_mode must be of type VideoQualityMode')
options['video_quality_mode'] = video_quality_mode.value
if nsfw is not MISSING:
options['nsfw'] = nsfw
data = await self._create_channel(
name, overwrites=overwrites, channel_type=ChannelType.stage_voice, category=category, reason=reason, **options
)

4
discord/threads.py

@ -272,12 +272,12 @@ class Thread(Messageable, Hashable):
.. versionadded:: 2.1
"""
tags = []
if self.parent is None or self.parent.type != ChannelType.forum:
if self.parent is None or self.parent.type not in (ChannelType.forum, ChannelType.media):
return tags
parent = self.parent
for tag_id in self._applied_tags:
tag = parent.get_tag(tag_id)
tag = parent.get_tag(tag_id) # type: ignore # parent here will be ForumChannel instance
if tag is not None:
tags.append(tag)

14
discord/types/interactions.py

@ -24,12 +24,12 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union
from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union, Optional
from typing_extensions import NotRequired
from .channel import ChannelTypeWithoutThread, ThreadMetadata, GuildChannel, InteractionDMChannel, GroupDMChannel
from .channel import ChannelTypeWithoutThread, GuildChannel, InteractionDMChannel, GroupDMChannel
from .sku import Entitlement
from .threads import ThreadType
from .threads import ThreadType, ThreadMetadata
from .member import Member
from .message import Attachment
from .role import Role
@ -64,6 +64,14 @@ class _BasePartialChannel(TypedDict):
class PartialChannel(_BasePartialChannel):
type: ChannelTypeWithoutThread
topic: NotRequired[str]
position: int
nsfw: bool
flags: int
rate_limit_per_user: int
parent_id: Optional[Snowflake]
last_message_id: Optional[Snowflake]
last_pin_timestamp: NotRequired[str]
class PartialThread(_BasePartialChannel):

Loading…
Cancel
Save