Skip to content

Channel

BaseChannel

Bases: DiscordObject

Source code in interactions/models/discord/channel.py
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class BaseChannel(DiscordObject):
    name: Optional[str] = attrs.field(repr=True, default=None)
    """The name of the channel (1-100 characters)"""
    type: Union[ChannelType, int] = attrs.field(repr=True, converter=ChannelType)
    """The channel topic (0-1024 characters)"""
    permissions: Optional[Permissions] = attrs.field(repr=False, default=None, converter=optional_c(Permissions))
    """Calculated permissions for the bot in this channel, only given when using channels as an option with slash commands"""

    @classmethod
    def from_dict_factory(cls, data: dict, client: "Client") -> "TYPE_ALL_CHANNEL":
        """
        Creates a channel object of the appropriate type.

        Args:
            data: The channel data.
            client: The bot.

        Returns:
            The new channel object.

        """
        channel_type = data.get("type")
        channel_class = TYPE_CHANNEL_MAPPING.get(channel_type, None)
        if not channel_class:
            client.logger.error(f"Unsupported channel type for {data} ({channel_type}).")
            channel_class = BaseChannel

        if channel_class == GuildPublicThread:
            # attempt to determine if this thread is a forum post (thanks discord)
            parent_channel = client.cache.get_channel(data["parent_id"])
            if parent_channel and parent_channel.type == ChannelType.GUILD_FORUM:
                channel_class = GuildForumPost

        return channel_class.from_dict(data, client)

    @property
    def mention(self) -> str:
        """Returns a string that would mention the channel."""
        return f"<#{self.id}>"

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        icon: Absent[UPLOADABLE_TYPE] = MISSING,
        type: Absent[ChannelType] = MISSING,
        position: Absent[int] = MISSING,
        topic: Absent[str] = MISSING,
        nsfw: Absent[bool] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        bitrate: Absent[int] = MISSING,
        user_limit: Absent[int] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        parent_id: Absent[Snowflake_Type] = MISSING,
        rtc_region: Absent[Union["models.VoiceRegion", str]] = MISSING,
        video_quality_mode: Absent[VideoQualityMode] = MISSING,
        default_auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
        flags: Absent[Union[int, ChannelFlags]] = MISSING,
        archived: Absent[bool] = MISSING,
        auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
        locked: Absent[bool] = MISSING,
        invitable: Absent[bool] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "TYPE_ALL_CHANNEL":
        """
        Edits the channel.

        Args:
            name: 1-100 character channel name
            icon: DM Group icon
            type: The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature
            position: The position of the channel in the left-hand listing
            topic: 0-1024 character channel topic
            nsfw: Whether the channel is nsfw
            rate_limit_per_user: Amount of seconds a user has to wait before sending another message (0-21600)
            bitrate: The bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers)
            user_limit: The user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit
            permission_overwrites: Channel or category-specific permissions
            parent_id: The id of the new parent category for a channel
            rtc_region: Channel voice region id, automatic when set to None.
            video_quality_mode: The camera video quality mode of the voice channel
            default_auto_archive_duration: The default duration that the clients use (not the API) for newly created threads in the channel, in minutes, to automatically archive the thread after recent activity
            flags: Channel flags combined as a bitfield. Only REQUIRE_TAG is supported for now.
            archived: Whether the thread is archived
            auto_archive_duration: Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
            locked: Whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
            invitable: Whether non-moderators can add other non-moderators to a thread; only available on private threads
            reason: The reason for editing the channel

        Returns:
            The edited channel. May be a new object if the channel type changes.

        """
        payload = {
            "name": name,
            "icon": to_image_data(icon),
            "type": type,
            "position": position,
            "topic": topic,
            "nsfw": nsfw,
            "rate_limit_per_user": rate_limit_per_user,
            "bitrate": bitrate,
            "user_limit": user_limit,
            "permission_overwrites": process_permission_overwrites(permission_overwrites),
            "parent_id": to_optional_snowflake(parent_id),
            "rtc_region": rtc_region.id if isinstance(rtc_region, models.VoiceRegion) else rtc_region,
            "video_quality_mode": video_quality_mode,
            "default_auto_archive_duration": default_auto_archive_duration,
            "flags": flags,
            "archived": archived,
            "auto_archive_duration": auto_archive_duration,
            "locked": locked,
            "invitable": invitable,
            **kwargs,
        }
        channel_data = await self._client.http.modify_channel(self.id, payload, reason)
        if not channel_data:
            raise TooManyChanges(
                "You have changed this channel too frequently, you need to wait a while before trying again."
            ) from None

        return self._client.cache.place_channel_data(channel_data)

    async def delete(self, reason: Absent[Optional[str]] = MISSING) -> None:
        """
        Delete this channel.

        Args:
            reason: The reason for deleting this channel

        """
        await self._client.http.delete_channel(self.id, reason)

mention: str property

Returns a string that would mention the channel.

name: Optional[str] = attrs.field(repr=True, default=None) class-attribute

The name of the channel (1-100 characters)

permissions: Optional[Permissions] = attrs.field(repr=False, default=None, converter=optional_c(Permissions)) class-attribute

Calculated permissions for the bot in this channel, only given when using channels as an option with slash commands

type: Union[ChannelType, int] = attrs.field(repr=True, converter=ChannelType) class-attribute

The channel topic (0-1024 characters)

delete(reason=MISSING) async

Delete this channel.

Parameters:

Name Type Description Default
reason Absent[Optional[str]]

The reason for deleting this channel

MISSING
Source code in interactions/models/discord/channel.py
903
904
905
906
907
908
909
910
911
async def delete(self, reason: Absent[Optional[str]] = MISSING) -> None:
    """
    Delete this channel.

    Args:
        reason: The reason for deleting this channel

    """
    await self._client.http.delete_channel(self.id, reason)

edit(*, name=MISSING, icon=MISSING, type=MISSING, position=MISSING, topic=MISSING, nsfw=MISSING, rate_limit_per_user=MISSING, bitrate=MISSING, user_limit=MISSING, permission_overwrites=MISSING, parent_id=MISSING, rtc_region=MISSING, video_quality_mode=MISSING, default_auto_archive_duration=MISSING, flags=MISSING, archived=MISSING, auto_archive_duration=MISSING, locked=MISSING, invitable=MISSING, reason=MISSING, **kwargs) async

Edits the channel.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
icon Absent[UPLOADABLE_TYPE]

DM Group icon

MISSING
type Absent[ChannelType]

The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature

MISSING
position Absent[int]

The position of the channel in the left-hand listing

MISSING
topic Absent[str]

0-1024 character channel topic

MISSING
nsfw Absent[bool]

Whether the channel is nsfw

MISSING
rate_limit_per_user Absent[int]

Amount of seconds a user has to wait before sending another message (0-21600)

MISSING
bitrate Absent[int]

The bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers)

MISSING
user_limit Absent[int]

The user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

Channel or category-specific permissions

MISSING
parent_id Absent[Snowflake_Type]

The id of the new parent category for a channel

MISSING
rtc_region Absent[Union[VoiceRegion, str]]

Channel voice region id, automatic when set to None.

MISSING
video_quality_mode Absent[VideoQualityMode]

The camera video quality mode of the voice channel

MISSING
default_auto_archive_duration Absent[AutoArchiveDuration]

The default duration that the clients use (not the API) for newly created threads in the channel, in minutes, to automatically archive the thread after recent activity

MISSING
flags Absent[Union[int, ChannelFlags]]

Channel flags combined as a bitfield. Only REQUIRE_TAG is supported for now.

MISSING
archived Absent[bool]

Whether the thread is archived

MISSING
auto_archive_duration Absent[AutoArchiveDuration]

Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080

MISSING
locked Absent[bool]

Whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it

MISSING
invitable Absent[bool]

Whether non-moderators can add other non-moderators to a thread; only available on private threads

MISSING
reason Absent[str]

The reason for editing the channel

MISSING

Returns:

Type Description
TYPE_ALL_CHANNEL

The edited channel. May be a new object if the channel type changes.

Source code in interactions/models/discord/channel.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    icon: Absent[UPLOADABLE_TYPE] = MISSING,
    type: Absent[ChannelType] = MISSING,
    position: Absent[int] = MISSING,
    topic: Absent[str] = MISSING,
    nsfw: Absent[bool] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    bitrate: Absent[int] = MISSING,
    user_limit: Absent[int] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    parent_id: Absent[Snowflake_Type] = MISSING,
    rtc_region: Absent[Union["models.VoiceRegion", str]] = MISSING,
    video_quality_mode: Absent[VideoQualityMode] = MISSING,
    default_auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
    flags: Absent[Union[int, ChannelFlags]] = MISSING,
    archived: Absent[bool] = MISSING,
    auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
    locked: Absent[bool] = MISSING,
    invitable: Absent[bool] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "TYPE_ALL_CHANNEL":
    """
    Edits the channel.

    Args:
        name: 1-100 character channel name
        icon: DM Group icon
        type: The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature
        position: The position of the channel in the left-hand listing
        topic: 0-1024 character channel topic
        nsfw: Whether the channel is nsfw
        rate_limit_per_user: Amount of seconds a user has to wait before sending another message (0-21600)
        bitrate: The bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers)
        user_limit: The user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit
        permission_overwrites: Channel or category-specific permissions
        parent_id: The id of the new parent category for a channel
        rtc_region: Channel voice region id, automatic when set to None.
        video_quality_mode: The camera video quality mode of the voice channel
        default_auto_archive_duration: The default duration that the clients use (not the API) for newly created threads in the channel, in minutes, to automatically archive the thread after recent activity
        flags: Channel flags combined as a bitfield. Only REQUIRE_TAG is supported for now.
        archived: Whether the thread is archived
        auto_archive_duration: Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
        locked: Whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
        invitable: Whether non-moderators can add other non-moderators to a thread; only available on private threads
        reason: The reason for editing the channel

    Returns:
        The edited channel. May be a new object if the channel type changes.

    """
    payload = {
        "name": name,
        "icon": to_image_data(icon),
        "type": type,
        "position": position,
        "topic": topic,
        "nsfw": nsfw,
        "rate_limit_per_user": rate_limit_per_user,
        "bitrate": bitrate,
        "user_limit": user_limit,
        "permission_overwrites": process_permission_overwrites(permission_overwrites),
        "parent_id": to_optional_snowflake(parent_id),
        "rtc_region": rtc_region.id if isinstance(rtc_region, models.VoiceRegion) else rtc_region,
        "video_quality_mode": video_quality_mode,
        "default_auto_archive_duration": default_auto_archive_duration,
        "flags": flags,
        "archived": archived,
        "auto_archive_duration": auto_archive_duration,
        "locked": locked,
        "invitable": invitable,
        **kwargs,
    }
    channel_data = await self._client.http.modify_channel(self.id, payload, reason)
    if not channel_data:
        raise TooManyChanges(
            "You have changed this channel too frequently, you need to wait a while before trying again."
        ) from None

    return self._client.cache.place_channel_data(channel_data)

from_dict_factory(data, client) classmethod

Creates a channel object of the appropriate type.

Parameters:

Name Type Description Default
data dict

The channel data.

required
client Client

The bot.

required

Returns:

Type Description
TYPE_ALL_CHANNEL

The new channel object.

Source code in interactions/models/discord/channel.py
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
@classmethod
def from_dict_factory(cls, data: dict, client: "Client") -> "TYPE_ALL_CHANNEL":
    """
    Creates a channel object of the appropriate type.

    Args:
        data: The channel data.
        client: The bot.

    Returns:
        The new channel object.

    """
    channel_type = data.get("type")
    channel_class = TYPE_CHANNEL_MAPPING.get(channel_type, None)
    if not channel_class:
        client.logger.error(f"Unsupported channel type for {data} ({channel_type}).")
        channel_class = BaseChannel

    if channel_class == GuildPublicThread:
        # attempt to determine if this thread is a forum post (thanks discord)
        parent_channel = client.cache.get_channel(data["parent_id"])
        if parent_channel and parent_channel.type == ChannelType.GUILD_FORUM:
            channel_class = GuildForumPost

    return channel_class.from_dict(data, client)

ChannelHistory

Bases: AsyncIterator

An async iterator for searching through a channel's history.

Attributes:

Name Type Description
channel BaseChannel

The channel to search through

limit BaseChannel

The maximum number of messages to return (set to 0 for no limit)

before Snowflake_Type

get messages before this message ID

after Snowflake_Type

get messages after this message ID

around Snowflake_Type

get messages "around" this message ID

Source code in interactions/models/discord/channel.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class ChannelHistory(AsyncIterator):
    """
    An async iterator for searching through a channel's history.

    Attributes:
        channel: The channel to search through
        limit: The maximum number of messages to return (set to 0 for no limit)
        before: get messages before this message ID
        after: get messages after this message ID
        around: get messages "around" this message ID

    """

    def __init__(self, channel: "BaseChannel", limit=50, before=None, after=None, around=None) -> None:
        self.channel: "BaseChannel" = channel
        self.before: Snowflake_Type = before
        self.after: Snowflake_Type = after
        self.around: Snowflake_Type = around
        super().__init__(limit)

    async def fetch(self) -> List["models.Message"]:
        """
        Fetch additional objects.

        Your implementation of this method *must* return a list of objects.
        If no more objects are available, raise QueueEmpty

        Returns:
            List of objects

        Raises:
              QueueEmpty: when no more objects are available.

        """
        if self.after:
            if not self.last:
                self.last = namedtuple("temp", "id")
                self.last.id = self.after
            messages = await self.channel.fetch_messages(limit=self.get_limit, after=self.last.id)
            messages.sort(key=lambda x: x.id)

        elif self.around:
            messages = await self.channel.fetch_messages(limit=self.get_limit, around=self.around)
            # todo: decide how getting *more* messages from `around` would work
            self._limit = 1  # stops history from getting more messages

        else:
            if self.before and not self.last:
                self.last = namedtuple("temp", "id")
                self.last.id = self.before

            messages = await self.channel.fetch_messages(limit=self.get_limit, before=self.last.id)
            messages.sort(key=lambda x: x.id, reverse=True)
        return messages

fetch() async

Fetch additional objects.

Your implementation of this method must return a list of objects. If no more objects are available, raise QueueEmpty

Returns:

Type Description
List[Message]

List of objects

Raises:

Type Description
QueueEmpty

when no more objects are available.

Source code in interactions/models/discord/channel.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
async def fetch(self) -> List["models.Message"]:
    """
    Fetch additional objects.

    Your implementation of this method *must* return a list of objects.
    If no more objects are available, raise QueueEmpty

    Returns:
        List of objects

    Raises:
          QueueEmpty: when no more objects are available.

    """
    if self.after:
        if not self.last:
            self.last = namedtuple("temp", "id")
            self.last.id = self.after
        messages = await self.channel.fetch_messages(limit=self.get_limit, after=self.last.id)
        messages.sort(key=lambda x: x.id)

    elif self.around:
        messages = await self.channel.fetch_messages(limit=self.get_limit, around=self.around)
        # todo: decide how getting *more* messages from `around` would work
        self._limit = 1  # stops history from getting more messages

    else:
        if self.before and not self.last:
            self.last = namedtuple("temp", "id")
            self.last.id = self.before

        messages = await self.channel.fetch_messages(limit=self.get_limit, before=self.last.id)
        messages.sort(key=lambda x: x.id, reverse=True)
    return messages

DM

Bases: DMChannel

Source code in interactions/models/discord/channel.py
939
940
941
942
943
944
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class DM(DMChannel):
    @property
    def recipient(self) -> "models.User":
        """Returns the user that is in this DM channel."""
        return self.recipients[0]

recipient: models.User property

Returns the user that is in this DM channel.

DMChannel

Bases: BaseChannel, MessageableMixin

Source code in interactions/models/discord/channel.py
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class DMChannel(BaseChannel, MessageableMixin):
    recipients: List["models.User"] = attrs.field(repr=False, factory=list)
    """The users of the DM that will receive messages sent"""

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data = super()._process_dict(data, client)
        if recipients := data.get("recipients", None):
            data["recipients"] = [
                client.cache.place_user_data(recipient) if isinstance(recipient, dict) else recipient
                for recipient in recipients
            ]
        return data

    @property
    def members(self) -> List["models.User"]:
        """Returns a list of users that are in this DM channel."""
        return self.recipients

members: List[models.User] property

Returns a list of users that are in this DM channel.

recipients: List[models.User] = attrs.field(repr=False, factory=list) class-attribute

The users of the DM that will receive messages sent

DMGroup

Bases: DMChannel

Source code in interactions/models/discord/channel.py
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class DMGroup(DMChannel):
    owner_id: Snowflake_Type = attrs.field(repr=True)
    """id of the creator of the group DM"""
    application_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None)
    """Application id of the group DM creator if it is bot-created"""

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        icon: Absent[UPLOADABLE_TYPE] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "DMGroup":
        """
        Edit this DM Channel.

        Args:
            name: 1-100 character channel name
            icon: An icon to use
            reason: The reason for this change

        """
        return await super().edit(name=name, icon=icon, reason=reason, **kwargs)

    async def fetch_owner(self, *, force: bool = False) -> "models.User":
        """
        Fetch the owner of this DM group

        Args:
            force: Whether to force a fetch from the API

        """
        return await self._client.cache.fetch_user(self.owner_id, force=force)

    def get_owner(self) -> "models.User":
        """Get the owner of this DM group"""
        return self._client.cache.get_user(self.owner_id)

    async def add_recipient(
        self,
        user: Union["models.User", Snowflake_Type],
        access_token: str,
        nickname: Absent[Optional[str]] = MISSING,
    ) -> None:
        """
        Add a recipient to this DM Group.

        Args:
            user: The user to add
            access_token: access token of a user that has granted your app the gdm.join scope
            nickname: nickname to apply to the user being added

        """
        user = await self._client.cache.fetch_user(user)
        await self._client.http.group_dm_add_recipient(self.id, user.id, access_token, nickname)
        self.recipients.append(user)

    async def remove_recipient(self, user: Union["models.User", Snowflake_Type]) -> None:
        """
        Remove a recipient from this DM Group.

        Args:
            user: The user to remove

        """
        user = await self._client.cache.fetch_user(user)
        await self._client.http.group_dm_remove_recipient(self.id, user.id)
        self.recipients.remove(user)

application_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None) class-attribute

Application id of the group DM creator if it is bot-created

owner_id: Snowflake_Type = attrs.field(repr=True) class-attribute

id of the creator of the group DM

add_recipient(user, access_token, nickname=MISSING) async

Add a recipient to this DM Group.

Parameters:

Name Type Description Default
user Union[User, Snowflake_Type]

The user to add

required
access_token str

access token of a user that has granted your app the gdm.join scope

required
nickname Absent[Optional[str]]

nickname to apply to the user being added

MISSING
Source code in interactions/models/discord/channel.py
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
async def add_recipient(
    self,
    user: Union["models.User", Snowflake_Type],
    access_token: str,
    nickname: Absent[Optional[str]] = MISSING,
) -> None:
    """
    Add a recipient to this DM Group.

    Args:
        user: The user to add
        access_token: access token of a user that has granted your app the gdm.join scope
        nickname: nickname to apply to the user being added

    """
    user = await self._client.cache.fetch_user(user)
    await self._client.http.group_dm_add_recipient(self.id, user.id, access_token, nickname)
    self.recipients.append(user)

edit(*, name=MISSING, icon=MISSING, reason=MISSING, **kwargs) async

Edit this DM Channel.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
icon Absent[UPLOADABLE_TYPE]

An icon to use

MISSING
reason Absent[str]

The reason for this change

MISSING
Source code in interactions/models/discord/channel.py
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    icon: Absent[UPLOADABLE_TYPE] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "DMGroup":
    """
    Edit this DM Channel.

    Args:
        name: 1-100 character channel name
        icon: An icon to use
        reason: The reason for this change

    """
    return await super().edit(name=name, icon=icon, reason=reason, **kwargs)

fetch_owner(*, force=False) async

Fetch the owner of this DM group

Parameters:

Name Type Description Default
force bool

Whether to force a fetch from the API

False
Source code in interactions/models/discord/channel.py
973
974
975
976
977
978
979
980
981
async def fetch_owner(self, *, force: bool = False) -> "models.User":
    """
    Fetch the owner of this DM group

    Args:
        force: Whether to force a fetch from the API

    """
    return await self._client.cache.fetch_user(self.owner_id, force=force)

get_owner()

Get the owner of this DM group

Source code in interactions/models/discord/channel.py
983
984
985
def get_owner(self) -> "models.User":
    """Get the owner of this DM group"""
    return self._client.cache.get_user(self.owner_id)

remove_recipient(user) async

Remove a recipient from this DM Group.

Parameters:

Name Type Description Default
user Union[User, Snowflake_Type]

The user to remove

required
Source code in interactions/models/discord/channel.py
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
async def remove_recipient(self, user: Union["models.User", Snowflake_Type]) -> None:
    """
    Remove a recipient from this DM Group.

    Args:
        user: The user to remove

    """
    user = await self._client.cache.fetch_user(user)
    await self._client.http.group_dm_remove_recipient(self.id, user.id)
    self.recipients.remove(user)

GuildCategory

Bases: GuildChannel

Source code in interactions/models/discord/channel.py
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildCategory(GuildChannel):
    @property
    def channels(self) -> List["TYPE_GUILD_CHANNEL"]:
        """Get all channels within the category"""
        return [channel for channel in self.guild.channels if channel.parent_id == self.id]

    @property
    def voice_channels(self) -> List["GuildVoice"]:
        """Get all voice channels within the category"""
        return [
            channel
            for channel in self.channels
            if isinstance(channel, GuildVoice) and not isinstance(channel, GuildStageVoice)
        ]

    @property
    def stage_channels(self) -> List["GuildStageVoice"]:
        """Get all stage channels within the category"""
        return [channel for channel in self.channels if isinstance(channel, GuildStageVoice)]

    @property
    def text_channels(self) -> List["GuildText"]:
        """Get all text channels within the category"""
        return [channel for channel in self.channels if isinstance(channel, GuildText)]

    @property
    def news_channels(self) -> List["GuildNews"]:
        """Get all news channels within the category"""
        return [channel for channel in self.channels if isinstance(channel, GuildNews)]

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        position: Absent[int] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "GuildCategory":
        """
        Edit this channel.

        Args:
            name: 1-100 character channel name
            position: the position of the channel in the left-hand listing
            permission_overwrites: channel or category-specific permissions
            reason: the reason for this change

        Returns:
            The updated channel object.

        """
        return await super().edit(
            name=name,
            position=position,
            permission_overwrites=permission_overwrites,
            reason=reason,
            **kwargs,
        )

    async def create_channel(
        self,
        channel_type: Union[ChannelType, int],
        name: str,
        topic: Absent[Optional[str]] = MISSING,
        position: Absent[Optional[int]] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        nsfw: bool = False,
        bitrate: int = 64000,
        user_limit: int = 0,
        rate_limit_per_user: int = 0,
        reason: Absent[Optional[str]] = MISSING,
    ) -> "TYPE_GUILD_CHANNEL":
        """
        Create a guild channel within this category, allows for explicit channel type setting.

        Args:
            channel_type: The type of channel to create
            name: The name of the channel
            topic: The topic of the channel
            position: The position of the channel in the channel list
            permission_overwrites: Permission overwrites to apply to the channel
            nsfw: Should this channel be marked nsfw
            bitrate: The bitrate of this channel, only for voice
            user_limit: The max users that can be in this channel, only for voice
            rate_limit_per_user: The time users must wait between sending messages
            reason: The reason for creating this channel

        Returns:
            The newly created channel.

        """
        return await self.guild.create_channel(
            channel_type=channel_type,
            name=name,
            topic=topic,
            position=position,
            permission_overwrites=permission_overwrites,
            category=self.id,
            nsfw=nsfw,
            bitrate=bitrate,
            user_limit=user_limit,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
        )

    async def create_text_channel(
        self,
        name: str,
        topic: Absent[Optional[str]] = MISSING,
        position: Absent[Optional[int]] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        nsfw: bool = False,
        rate_limit_per_user: int = 0,
        reason: Absent[Optional[str]] = MISSING,
    ) -> "GuildText":
        """
        Create a text channel in this guild within this category.

        Args:
            name: The name of the channel
            topic: The topic of the channel
            position: The position of the channel in the channel list
            permission_overwrites: Permission overwrites to apply to the channel
            nsfw: Should this channel be marked nsfw
            rate_limit_per_user: The time users must wait between sending messages
            reason: The reason for creating this channel

        Returns:
           The newly created text channel.

        """
        return await self.create_channel(
            channel_type=ChannelType.GUILD_TEXT,
            name=name,
            topic=topic,
            position=position,
            permission_overwrites=permission_overwrites,
            nsfw=nsfw,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
        )

    async def create_news_channel(
        self,
        name: str,
        topic: Absent[Optional[str]] = MISSING,
        position: Absent[Optional[int]] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        nsfw: bool = False,
        reason: Absent[Optional[str]] = MISSING,
    ) -> "GuildNews":
        """
        Create a news channel in this guild within this category.

        Args:
            name: The name of the channel
            topic: The topic of the channel
            position: The position of the channel in the channel list
            permission_overwrites: Permission overwrites to apply to the channel
            nsfw: Should this channel be marked nsfw
            reason: The reason for creating this channel

        Returns:
           The newly created news channel.

        """
        return await self.create_channel(
            channel_type=ChannelType.GUILD_NEWS,
            name=name,
            topic=topic,
            position=position,
            permission_overwrites=permission_overwrites,
            nsfw=nsfw,
            reason=reason,
        )

    async def create_voice_channel(
        self,
        name: str,
        topic: Absent[Optional[str]] = MISSING,
        position: Absent[Optional[int]] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        nsfw: bool = False,
        bitrate: int = 64000,
        user_limit: int = 0,
        reason: Absent[Optional[str]] = MISSING,
    ) -> "GuildVoice":
        """
        Create a guild voice channel within this category.

        Args:
            name: The name of the channel
            topic: The topic of the channel
            position: The position of the channel in the channel list
            permission_overwrites: Permission overwrites to apply to the channel
            nsfw: Should this channel be marked nsfw
            bitrate: The bitrate of this channel, only for voice
            user_limit: The max users that can be in this channel, only for voice
            reason: The reason for creating this channel

        Returns:
           The newly created voice channel.

        """
        return await self.create_channel(
            channel_type=ChannelType.GUILD_VOICE,
            name=name,
            topic=topic,
            position=position,
            permission_overwrites=permission_overwrites,
            nsfw=nsfw,
            bitrate=bitrate,
            user_limit=user_limit,
            reason=reason,
        )

    async def create_stage_channel(
        self,
        name: str,
        topic: Absent[Optional[str]] = MISSING,
        position: Absent[Optional[int]] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        bitrate: int = 64000,
        user_limit: int = 0,
        reason: Absent[Optional[str]] = MISSING,
    ) -> "GuildStageVoice":
        """
        Create a guild stage channel within this category.

        Args:
            name: The name of the channel
            topic: The topic of the channel
            position: The position of the channel in the channel list
            permission_overwrites: Permission overwrites to apply to the channel
            bitrate: The bitrate of this channel, only for voice
            user_limit: The max users that can be in this channel, only for voice
            reason: The reason for creating this channel

        Returns:
            The newly created stage channel.

        """
        return await self.create_channel(
            channel_type=ChannelType.GUILD_STAGE_VOICE,
            name=name,
            topic=topic,
            position=position,
            permission_overwrites=permission_overwrites,
            bitrate=bitrate,
            user_limit=user_limit,
            reason=reason,
        )

channels: List[TYPE_GUILD_CHANNEL] property

Get all channels within the category

news_channels: List[GuildNews] property

Get all news channels within the category

stage_channels: List[GuildStageVoice] property

Get all stage channels within the category

text_channels: List[GuildText] property

Get all text channels within the category

voice_channels: List[GuildVoice] property

Get all voice channels within the category

create_channel(channel_type, name, topic=MISSING, position=MISSING, permission_overwrites=MISSING, nsfw=False, bitrate=64000, user_limit=0, rate_limit_per_user=0, reason=MISSING) async

Create a guild channel within this category, allows for explicit channel type setting.

Parameters:

Name Type Description Default
channel_type Union[ChannelType, int]

The type of channel to create

required
name str

The name of the channel

required
topic Absent[Optional[str]]

The topic of the channel

MISSING
position Absent[Optional[int]]

The position of the channel in the channel list

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

Permission overwrites to apply to the channel

MISSING
nsfw bool

Should this channel be marked nsfw

False
bitrate int

The bitrate of this channel, only for voice

64000
user_limit int

The max users that can be in this channel, only for voice

0
rate_limit_per_user int

The time users must wait between sending messages

0
reason Absent[Optional[str]]

The reason for creating this channel

MISSING

Returns:

Type Description
TYPE_GUILD_CHANNEL

The newly created channel.

Source code in interactions/models/discord/channel.py
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
async def create_channel(
    self,
    channel_type: Union[ChannelType, int],
    name: str,
    topic: Absent[Optional[str]] = MISSING,
    position: Absent[Optional[int]] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    nsfw: bool = False,
    bitrate: int = 64000,
    user_limit: int = 0,
    rate_limit_per_user: int = 0,
    reason: Absent[Optional[str]] = MISSING,
) -> "TYPE_GUILD_CHANNEL":
    """
    Create a guild channel within this category, allows for explicit channel type setting.

    Args:
        channel_type: The type of channel to create
        name: The name of the channel
        topic: The topic of the channel
        position: The position of the channel in the channel list
        permission_overwrites: Permission overwrites to apply to the channel
        nsfw: Should this channel be marked nsfw
        bitrate: The bitrate of this channel, only for voice
        user_limit: The max users that can be in this channel, only for voice
        rate_limit_per_user: The time users must wait between sending messages
        reason: The reason for creating this channel

    Returns:
        The newly created channel.

    """
    return await self.guild.create_channel(
        channel_type=channel_type,
        name=name,
        topic=topic,
        position=position,
        permission_overwrites=permission_overwrites,
        category=self.id,
        nsfw=nsfw,
        bitrate=bitrate,
        user_limit=user_limit,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
    )

create_news_channel(name, topic=MISSING, position=MISSING, permission_overwrites=MISSING, nsfw=False, reason=MISSING) async

Create a news channel in this guild within this category.

Parameters:

Name Type Description Default
name str

The name of the channel

required
topic Absent[Optional[str]]

The topic of the channel

MISSING
position Absent[Optional[int]]

The position of the channel in the channel list

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

Permission overwrites to apply to the channel

MISSING
nsfw bool

Should this channel be marked nsfw

False
reason Absent[Optional[str]]

The reason for creating this channel

MISSING

Returns:

Type Description
GuildNews

The newly created news channel.

Source code in interactions/models/discord/channel.py
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
async def create_news_channel(
    self,
    name: str,
    topic: Absent[Optional[str]] = MISSING,
    position: Absent[Optional[int]] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    nsfw: bool = False,
    reason: Absent[Optional[str]] = MISSING,
) -> "GuildNews":
    """
    Create a news channel in this guild within this category.

    Args:
        name: The name of the channel
        topic: The topic of the channel
        position: The position of the channel in the channel list
        permission_overwrites: Permission overwrites to apply to the channel
        nsfw: Should this channel be marked nsfw
        reason: The reason for creating this channel

    Returns:
       The newly created news channel.

    """
    return await self.create_channel(
        channel_type=ChannelType.GUILD_NEWS,
        name=name,
        topic=topic,
        position=position,
        permission_overwrites=permission_overwrites,
        nsfw=nsfw,
        reason=reason,
    )

create_stage_channel(name, topic=MISSING, position=MISSING, permission_overwrites=MISSING, bitrate=64000, user_limit=0, reason=MISSING) async

Create a guild stage channel within this category.

Parameters:

Name Type Description Default
name str

The name of the channel

required
topic Absent[Optional[str]]

The topic of the channel

MISSING
position Absent[Optional[int]]

The position of the channel in the channel list

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

Permission overwrites to apply to the channel

MISSING
bitrate int

The bitrate of this channel, only for voice

64000
user_limit int

The max users that can be in this channel, only for voice

0
reason Absent[Optional[str]]

The reason for creating this channel

MISSING

Returns:

Type Description
GuildStageVoice

The newly created stage channel.

Source code in interactions/models/discord/channel.py
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
async def create_stage_channel(
    self,
    name: str,
    topic: Absent[Optional[str]] = MISSING,
    position: Absent[Optional[int]] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    bitrate: int = 64000,
    user_limit: int = 0,
    reason: Absent[Optional[str]] = MISSING,
) -> "GuildStageVoice":
    """
    Create a guild stage channel within this category.

    Args:
        name: The name of the channel
        topic: The topic of the channel
        position: The position of the channel in the channel list
        permission_overwrites: Permission overwrites to apply to the channel
        bitrate: The bitrate of this channel, only for voice
        user_limit: The max users that can be in this channel, only for voice
        reason: The reason for creating this channel

    Returns:
        The newly created stage channel.

    """
    return await self.create_channel(
        channel_type=ChannelType.GUILD_STAGE_VOICE,
        name=name,
        topic=topic,
        position=position,
        permission_overwrites=permission_overwrites,
        bitrate=bitrate,
        user_limit=user_limit,
        reason=reason,
    )

create_text_channel(name, topic=MISSING, position=MISSING, permission_overwrites=MISSING, nsfw=False, rate_limit_per_user=0, reason=MISSING) async

Create a text channel in this guild within this category.

Parameters:

Name Type Description Default
name str

The name of the channel

required
topic Absent[Optional[str]]

The topic of the channel

MISSING
position Absent[Optional[int]]

The position of the channel in the channel list

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

Permission overwrites to apply to the channel

MISSING
nsfw bool

Should this channel be marked nsfw

False
rate_limit_per_user int

The time users must wait between sending messages

0
reason Absent[Optional[str]]

The reason for creating this channel

MISSING

Returns:

Type Description
GuildText

The newly created text channel.

Source code in interactions/models/discord/channel.py
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
async def create_text_channel(
    self,
    name: str,
    topic: Absent[Optional[str]] = MISSING,
    position: Absent[Optional[int]] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    nsfw: bool = False,
    rate_limit_per_user: int = 0,
    reason: Absent[Optional[str]] = MISSING,
) -> "GuildText":
    """
    Create a text channel in this guild within this category.

    Args:
        name: The name of the channel
        topic: The topic of the channel
        position: The position of the channel in the channel list
        permission_overwrites: Permission overwrites to apply to the channel
        nsfw: Should this channel be marked nsfw
        rate_limit_per_user: The time users must wait between sending messages
        reason: The reason for creating this channel

    Returns:
       The newly created text channel.

    """
    return await self.create_channel(
        channel_type=ChannelType.GUILD_TEXT,
        name=name,
        topic=topic,
        position=position,
        permission_overwrites=permission_overwrites,
        nsfw=nsfw,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
    )

create_voice_channel(name, topic=MISSING, position=MISSING, permission_overwrites=MISSING, nsfw=False, bitrate=64000, user_limit=0, reason=MISSING) async

Create a guild voice channel within this category.

Parameters:

Name Type Description Default
name str

The name of the channel

required
topic Absent[Optional[str]]

The topic of the channel

MISSING
position Absent[Optional[int]]

The position of the channel in the channel list

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

Permission overwrites to apply to the channel

MISSING
nsfw bool

Should this channel be marked nsfw

False
bitrate int

The bitrate of this channel, only for voice

64000
user_limit int

The max users that can be in this channel, only for voice

0
reason Absent[Optional[str]]

The reason for creating this channel

MISSING

Returns:

Type Description
GuildVoice

The newly created voice channel.

Source code in interactions/models/discord/channel.py
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
async def create_voice_channel(
    self,
    name: str,
    topic: Absent[Optional[str]] = MISSING,
    position: Absent[Optional[int]] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    nsfw: bool = False,
    bitrate: int = 64000,
    user_limit: int = 0,
    reason: Absent[Optional[str]] = MISSING,
) -> "GuildVoice":
    """
    Create a guild voice channel within this category.

    Args:
        name: The name of the channel
        topic: The topic of the channel
        position: The position of the channel in the channel list
        permission_overwrites: Permission overwrites to apply to the channel
        nsfw: Should this channel be marked nsfw
        bitrate: The bitrate of this channel, only for voice
        user_limit: The max users that can be in this channel, only for voice
        reason: The reason for creating this channel

    Returns:
       The newly created voice channel.

    """
    return await self.create_channel(
        channel_type=ChannelType.GUILD_VOICE,
        name=name,
        topic=topic,
        position=position,
        permission_overwrites=permission_overwrites,
        nsfw=nsfw,
        bitrate=bitrate,
        user_limit=user_limit,
        reason=reason,
    )

edit(*, name=MISSING, position=MISSING, permission_overwrites=MISSING, reason=MISSING, **kwargs) async

Edit this channel.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
position Absent[int]

the position of the channel in the left-hand listing

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

channel or category-specific permissions

MISSING
reason Absent[str]

the reason for this change

MISSING

Returns:

Type Description
GuildCategory

The updated channel object.

Source code in interactions/models/discord/channel.py
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    position: Absent[int] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "GuildCategory":
    """
    Edit this channel.

    Args:
        name: 1-100 character channel name
        position: the position of the channel in the left-hand listing
        permission_overwrites: channel or category-specific permissions
        reason: the reason for this change

    Returns:
        The updated channel object.

    """
    return await super().edit(
        name=name,
        position=position,
        permission_overwrites=permission_overwrites,
        reason=reason,
        **kwargs,
    )

GuildChannel

Bases: BaseChannel

Source code in interactions/models/discord/channel.py
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class GuildChannel(BaseChannel):
    position: Optional[int] = attrs.field(repr=False, default=0)
    """Sorting position of the channel"""
    nsfw: bool = attrs.field(repr=False, default=False)
    """Whether the channel is nsfw"""
    parent_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake))
    """id of the parent category for a channel (each parent category can contain up to 50 channels)"""
    permission_overwrites: list[PermissionOverwrite] = attrs.field(repr=False, factory=list)
    """A list of the overwritten permissions for the members and roles"""

    _guild_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake))

    @property
    def guild(self) -> "models.Guild":
        """The guild this channel belongs to."""
        return self._client.cache.get_guild(self._guild_id)

    @property
    def category(self) -> Optional["GuildCategory"]:
        """The parent category of this channel."""
        return self._client.cache.get_channel(self.parent_id)

    @property
    def gui_position(self) -> int:
        """The position of this channel in the Discord interface."""
        return self.guild.get_channel_gui_position(self.id)

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data = super()._process_dict(data, client)
        if overwrites := data.get("permission_overwrites"):
            data["permission_overwrites"] = PermissionOverwrite.from_list(overwrites)
        return data

    def permissions_for(self, instance: Snowflake_Type) -> Permissions:
        """
        Calculates permissions for an instance

        Args:
            instance: Member or Role instance (or its ID)

        Returns:
            Permissions data

        Raises:
            ValueError: If could not find any member or role by given ID
            RuntimeError: If given instance is from another guild

        """
        if (is_member := isinstance(instance, models.Member)) or isinstance(instance, models.Role):
            if instance._guild_id != self._guild_id:
                raise RuntimeError("Unable to calculate permissions for the instance from different guild")

            if is_member:
                return instance.channel_permissions(self)

            permissions = instance.permissions

            for overwrite in self.permission_overwrites:
                if overwrite.id == instance.id:
                    permissions &= ~overwrite.deny
                    permissions |= overwrite.allow
                    break

            return permissions

        instance = to_snowflake(instance)
        guild = self.guild
        if instance := guild.get_member(instance) or guild.get_role(instance):
            return self.permissions_for(instance)
        raise ValueError("Unable to find any member or role by given instance ID")

    async def add_permission(
        self,
        target: Union["PermissionOverwrite", "models.Role", "models.User", "models.Member", "Snowflake_Type"],
        type: Optional["OverwriteType"] = None,
        allow: Optional[List["Permissions"] | int] = None,
        deny: Optional[List["Permissions"] | int] = None,
        reason: Optional[str] = None,
    ) -> None:
        """
        Add a permission to this channel.

        Args:
            target: The updated PermissionOverwrite object, or the Role or User object/id to update
            type: The type of permission overwrite. Only applicable if target is an id
            allow: List of permissions to allow. Only applicable if target is not an PermissionOverwrite object
            deny: List of permissions to deny. Only applicable if target is not an PermissionOverwrite object
            reason: The reason for this change

        Raises:
            ValueError: Invalid target for permission

        """
        allow = allow or []
        deny = deny or []
        if not isinstance(target, PermissionOverwrite):
            if isinstance(target, (models.User, models.Member)):
                target = target.id
                type = OverwriteType.MEMBER
            elif isinstance(target, models.Role):
                target = target.id
                type = OverwriteType.ROLE
            elif type and isinstance(target, Snowflake_Type):
                target = to_snowflake(target)
            else:
                raise ValueError("Invalid target and/or type for permission")
            overwrite = PermissionOverwrite(id=target, type=type, allow=Permissions.NONE, deny=Permissions.NONE)
            if isinstance(allow, int):
                overwrite.allow |= allow
            else:
                for perm in allow:
                    overwrite.allow |= perm
            if isinstance(deny, int):
                overwrite.deny |= deny
            else:
                for perm in deny:
                    overwrite.deny |= perm
        else:
            overwrite = target

        if exists := get(self.permission_overwrites, id=overwrite.id, type=overwrite.type):
            exists.deny = (exists.deny | overwrite.deny) & ~overwrite.allow
            exists.allow = (exists.allow | overwrite.allow) & ~overwrite.deny
            await self.edit_permission(exists, reason)
        else:
            permission_overwrites = self.permission_overwrites
            permission_overwrites.append(overwrite)
            await self.edit(permission_overwrites=permission_overwrites)

    async def edit_permission(self, overwrite: PermissionOverwrite, reason: Optional[str] = None) -> None:
        """
        Edit the permissions for this channel.

        Args:
            overwrite: The permission overwrite to apply
            reason: The reason for this change

        """
        await self._client.http.edit_channel_permission(
            self.id,
            overwrite_id=overwrite.id,
            allow=overwrite.allow,
            deny=overwrite.deny,
            perm_type=overwrite.type,
            reason=reason,
        )

    async def delete_permission(
        self,
        target: Union["PermissionOverwrite", "models.Role", "models.User"],
        reason: Absent[Optional[str]] = MISSING,
    ) -> None:
        """
        Delete a permission overwrite for this channel.

        Args:
            target: The permission overwrite to delete
            reason: The reason for this change

        """
        target = to_snowflake(target)
        await self._client.http.delete_channel_permission(self.id, target, reason)

    async def set_permission(
        self,
        target: Union["models.Role", "models.Member", "models.User"],
        *,
        add_reactions: bool | None = None,
        administrator: bool | None = None,
        attach_files: bool | None = None,
        ban_members: bool | None = None,
        change_nickname: bool | None = None,
        connect: bool | None = None,
        create_instant_invite: bool | None = None,
        deafen_members: bool | None = None,
        embed_links: bool | None = None,
        kick_members: bool | None = None,
        manage_channels: bool | None = None,
        manage_emojis_and_stickers: bool | None = None,
        manage_events: bool | None = None,
        manage_guild: bool | None = None,
        manage_messages: bool | None = None,
        manage_nicknames: bool | None = None,
        manage_roles: bool | None = None,
        manage_threads: bool | None = None,
        manage_webhooks: bool | None = None,
        mention_everyone: bool | None = None,
        moderate_members: bool | None = None,
        move_members: bool | None = None,
        mute_members: bool | None = None,
        priority_speaker: bool | None = None,
        read_message_history: bool | None = None,
        request_to_speak: bool | None = None,
        send_messages: bool | None = None,
        send_messages_in_threads: bool | None = None,
        send_tts_messages: bool | None = None,
        speak: bool | None = None,
        start_embedded_activities: bool | None = None,
        stream: bool | None = None,
        use_application_commands: bool | None = None,
        use_external_emojis: bool | None = None,
        use_external_stickers: bool | None = None,
        use_private_threads: bool | None = None,
        use_public_threads: bool | None = None,
        use_vad: bool | None = None,
        view_audit_log: bool | None = None,
        view_channel: bool | None = None,
        view_guild_insights: bool | None = None,
        reason: str | None = None,
    ) -> None:
        """
        Set the Permission Overwrites for a given target.

        Args:
            target: The target to set permission overwrites for
            add_reactions: Allows for the addition of reactions to messages
            administrator: Allows all permissions and bypasses channel permission overwrites
            attach_files: Allows for uploading images and files
            ban_members: Allows banning members
            change_nickname: Allows for modification of own nickname
            connect: Allows for joining of a voice channel
            create_instant_invite: Allows creation of instant invites
            deafen_members: Allows for deafening of members in a voice channel
            embed_links: Links sent by users with this permission will be auto-embedded
            kick_members: Allows kicking members
            manage_channels: Allows management and editing of channels
            manage_emojis_and_stickers: Allows management and editing of emojis and stickers
            manage_events: Allows for creating, editing, and deleting scheduled events
            manage_guild: Allows management and editing of the guild
            manage_messages: Allows for deletion of other users messages
            manage_nicknames: Allows for modification of other users nicknames
            manage_roles: Allows management and editing of roles
            manage_threads: Allows for deleting and archiving threads, and viewing all private threads
            manage_webhooks: Allows management and editing of webhooks
            mention_everyone: Allows for using the `@everyone` tag to notify all users in a channel, and the `@here` tag to notify all online users in a channel
            moderate_members: Allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels
            move_members: Allows for moving of members between voice channels
            mute_members: Allows for muting members in a voice channel
            priority_speaker: Allows for using priority speaker in a voice channel
            read_message_history: Allows for reading of message history
            request_to_speak: Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.)
            send_messages:  Allows for sending messages in a channel (does not allow sending messages in threads)
            send_messages_in_threads: Allows for sending messages in threads
            send_tts_messages:  Allows for sending of `/tts` messages
            speak: Allows for speaking in a voice channel
            start_embedded_activities: Allows for using Activities (applications with the `EMBEDDED` flag) in a voice channel
            stream: Allows the user to go live
            use_application_commands: Allows members to use application commands, including slash commands and context menu commands
            use_external_emojis: Allows the usage of custom emojis from other servers
            use_external_stickers: Allows the usage of custom stickers from other servers
            use_private_threads: Allows for creating private threads
            use_public_threads:  Allows for creating public and announcement threads
            use_vad: Allows for using voice-activity-detection in a voice channel
            view_audit_log: Allows for viewing of audit logs
            view_channel: Allows guild members to view a channel, which includes reading messages in text channels and joining voice channels
            view_guild_insights: Allows for viewing guild insights
            reason: The reason for creating this overwrite

        """
        overwrite = PermissionOverwrite.for_target(target)

        allow: Permissions = Permissions.NONE
        deny: Permissions = Permissions.NONE

        for name, val in locals().items():
            if isinstance(val, bool):
                if val:
                    allow |= getattr(Permissions, name.upper())
                else:
                    deny |= getattr(Permissions, name.upper())

        overwrite.add_allows(allow)
        overwrite.add_denies(deny)

        await self.edit_permission(overwrite, reason)

    @property
    def members(self) -> List["models.Member"]:
        """Returns a list of members that can see this channel."""
        return [m for m in self.guild.members if Permissions.VIEW_CHANNEL in m.channel_permissions(self)]  # type: ignore

    @property
    def bots(self) -> List["models.Member"]:
        """Returns a list of bots that can see this channel."""
        return [m for m in self.guild.members if m.bot and Permissions.VIEW_CHANNEL in m.channel_permissions(self)]  # type: ignore

    @property
    def humans(self) -> List["models.Member"]:
        """Returns a list of humans that can see this channel."""
        return [m for m in self.guild.members if not m.bot and Permissions.VIEW_CHANNEL in m.channel_permissions(self)]  # type: ignore

    async def clone(self, name: Optional[str] = None, reason: Absent[Optional[str]] = MISSING) -> "TYPE_GUILD_CHANNEL":
        """
        Clone this channel and create a new one.

        Args:
            name: The name of the new channel. Defaults to the current name
            reason: The reason for creating this channel

        Returns:
            The newly created channel.

        """
        return await self.guild.create_channel(
            channel_type=self.type,
            name=name or self.name,
            topic=getattr(self, "topic", MISSING),
            position=self.position,
            permission_overwrites=self.permission_overwrites,
            category=self.category,
            nsfw=self.nsfw,
            bitrate=getattr(self, "bitrate", 64000),
            user_limit=getattr(self, "user_limit", 0),
            rate_limit_per_user=getattr(self, "rate_limit_per_user", 0),
            reason=reason,
        )

bots: List[models.Member] property

Returns a list of bots that can see this channel.

category: Optional[GuildCategory] property

The parent category of this channel.

gui_position: int property

The position of this channel in the Discord interface.

guild: models.Guild property

The guild this channel belongs to.

humans: List[models.Member] property

Returns a list of humans that can see this channel.

members: List[models.Member] property

Returns a list of members that can see this channel.

nsfw: bool = attrs.field(repr=False, default=False) class-attribute

Whether the channel is nsfw

parent_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake)) class-attribute

id of the parent category for a channel (each parent category can contain up to 50 channels)

permission_overwrites: list[PermissionOverwrite] = attrs.field(repr=False, factory=list) class-attribute

A list of the overwritten permissions for the members and roles

position: Optional[int] = attrs.field(repr=False, default=0) class-attribute

Sorting position of the channel

add_permission(target, type=None, allow=None, deny=None, reason=None) async

Add a permission to this channel.

Parameters:

Name Type Description Default
target Union[PermissionOverwrite, Role, User, Member, Snowflake_Type]

The updated PermissionOverwrite object, or the Role or User object/id to update

required
type Optional[OverwriteType]

The type of permission overwrite. Only applicable if target is an id

None
allow Optional[List[Permissions] | int]

List of permissions to allow. Only applicable if target is not an PermissionOverwrite object

None
deny Optional[List[Permissions] | int]

List of permissions to deny. Only applicable if target is not an PermissionOverwrite object

None
reason Optional[str]

The reason for this change

None

Raises:

Type Description
ValueError

Invalid target for permission

Source code in interactions/models/discord/channel.py
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
async def add_permission(
    self,
    target: Union["PermissionOverwrite", "models.Role", "models.User", "models.Member", "Snowflake_Type"],
    type: Optional["OverwriteType"] = None,
    allow: Optional[List["Permissions"] | int] = None,
    deny: Optional[List["Permissions"] | int] = None,
    reason: Optional[str] = None,
) -> None:
    """
    Add a permission to this channel.

    Args:
        target: The updated PermissionOverwrite object, or the Role or User object/id to update
        type: The type of permission overwrite. Only applicable if target is an id
        allow: List of permissions to allow. Only applicable if target is not an PermissionOverwrite object
        deny: List of permissions to deny. Only applicable if target is not an PermissionOverwrite object
        reason: The reason for this change

    Raises:
        ValueError: Invalid target for permission

    """
    allow = allow or []
    deny = deny or []
    if not isinstance(target, PermissionOverwrite):
        if isinstance(target, (models.User, models.Member)):
            target = target.id
            type = OverwriteType.MEMBER
        elif isinstance(target, models.Role):
            target = target.id
            type = OverwriteType.ROLE
        elif type and isinstance(target, Snowflake_Type):
            target = to_snowflake(target)
        else:
            raise ValueError("Invalid target and/or type for permission")
        overwrite = PermissionOverwrite(id=target, type=type, allow=Permissions.NONE, deny=Permissions.NONE)
        if isinstance(allow, int):
            overwrite.allow |= allow
        else:
            for perm in allow:
                overwrite.allow |= perm
        if isinstance(deny, int):
            overwrite.deny |= deny
        else:
            for perm in deny:
                overwrite.deny |= perm
    else:
        overwrite = target

    if exists := get(self.permission_overwrites, id=overwrite.id, type=overwrite.type):
        exists.deny = (exists.deny | overwrite.deny) & ~overwrite.allow
        exists.allow = (exists.allow | overwrite.allow) & ~overwrite.deny
        await self.edit_permission(exists, reason)
    else:
        permission_overwrites = self.permission_overwrites
        permission_overwrites.append(overwrite)
        await self.edit(permission_overwrites=permission_overwrites)

clone(name=None, reason=MISSING) async

Clone this channel and create a new one.

Parameters:

Name Type Description Default
name Optional[str]

The name of the new channel. Defaults to the current name

None
reason Absent[Optional[str]]

The reason for creating this channel

MISSING

Returns:

Type Description
TYPE_GUILD_CHANNEL

The newly created channel.

Source code in interactions/models/discord/channel.py
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
async def clone(self, name: Optional[str] = None, reason: Absent[Optional[str]] = MISSING) -> "TYPE_GUILD_CHANNEL":
    """
    Clone this channel and create a new one.

    Args:
        name: The name of the new channel. Defaults to the current name
        reason: The reason for creating this channel

    Returns:
        The newly created channel.

    """
    return await self.guild.create_channel(
        channel_type=self.type,
        name=name or self.name,
        topic=getattr(self, "topic", MISSING),
        position=self.position,
        permission_overwrites=self.permission_overwrites,
        category=self.category,
        nsfw=self.nsfw,
        bitrate=getattr(self, "bitrate", 64000),
        user_limit=getattr(self, "user_limit", 0),
        rate_limit_per_user=getattr(self, "rate_limit_per_user", 0),
        reason=reason,
    )

delete_permission(target, reason=MISSING) async

Delete a permission overwrite for this channel.

Parameters:

Name Type Description Default
target Union[PermissionOverwrite, Role, User]

The permission overwrite to delete

required
reason Absent[Optional[str]]

The reason for this change

MISSING
Source code in interactions/models/discord/channel.py
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
async def delete_permission(
    self,
    target: Union["PermissionOverwrite", "models.Role", "models.User"],
    reason: Absent[Optional[str]] = MISSING,
) -> None:
    """
    Delete a permission overwrite for this channel.

    Args:
        target: The permission overwrite to delete
        reason: The reason for this change

    """
    target = to_snowflake(target)
    await self._client.http.delete_channel_permission(self.id, target, reason)

edit_permission(overwrite, reason=None) async

Edit the permissions for this channel.

Parameters:

Name Type Description Default
overwrite PermissionOverwrite

The permission overwrite to apply

required
reason Optional[str]

The reason for this change

None
Source code in interactions/models/discord/channel.py
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
async def edit_permission(self, overwrite: PermissionOverwrite, reason: Optional[str] = None) -> None:
    """
    Edit the permissions for this channel.

    Args:
        overwrite: The permission overwrite to apply
        reason: The reason for this change

    """
    await self._client.http.edit_channel_permission(
        self.id,
        overwrite_id=overwrite.id,
        allow=overwrite.allow,
        deny=overwrite.deny,
        perm_type=overwrite.type,
        reason=reason,
    )

permissions_for(instance)

Calculates permissions for an instance

Parameters:

Name Type Description Default
instance Snowflake_Type

Member or Role instance (or its ID)

required

Returns:

Type Description
Permissions

Permissions data

Raises:

Type Description
ValueError

If could not find any member or role by given ID

RuntimeError

If given instance is from another guild

Source code in interactions/models/discord/channel.py
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
def permissions_for(self, instance: Snowflake_Type) -> Permissions:
    """
    Calculates permissions for an instance

    Args:
        instance: Member or Role instance (or its ID)

    Returns:
        Permissions data

    Raises:
        ValueError: If could not find any member or role by given ID
        RuntimeError: If given instance is from another guild

    """
    if (is_member := isinstance(instance, models.Member)) or isinstance(instance, models.Role):
        if instance._guild_id != self._guild_id:
            raise RuntimeError("Unable to calculate permissions for the instance from different guild")

        if is_member:
            return instance.channel_permissions(self)

        permissions = instance.permissions

        for overwrite in self.permission_overwrites:
            if overwrite.id == instance.id:
                permissions &= ~overwrite.deny
                permissions |= overwrite.allow
                break

        return permissions

    instance = to_snowflake(instance)
    guild = self.guild
    if instance := guild.get_member(instance) or guild.get_role(instance):
        return self.permissions_for(instance)
    raise ValueError("Unable to find any member or role by given instance ID")

set_permission(target, *, add_reactions=None, administrator=None, attach_files=None, ban_members=None, change_nickname=None, connect=None, create_instant_invite=None, deafen_members=None, embed_links=None, kick_members=None, manage_channels=None, manage_emojis_and_stickers=None, manage_events=None, manage_guild=None, manage_messages=None, manage_nicknames=None, manage_roles=None, manage_threads=None, manage_webhooks=None, mention_everyone=None, moderate_members=None, move_members=None, mute_members=None, priority_speaker=None, read_message_history=None, request_to_speak=None, send_messages=None, send_messages_in_threads=None, send_tts_messages=None, speak=None, start_embedded_activities=None, stream=None, use_application_commands=None, use_external_emojis=None, use_external_stickers=None, use_private_threads=None, use_public_threads=None, use_vad=None, view_audit_log=None, view_channel=None, view_guild_insights=None, reason=None) async

Set the Permission Overwrites for a given target.

Parameters:

Name Type Description Default
target Union[Role, Member, User]

The target to set permission overwrites for

required
add_reactions bool | None

Allows for the addition of reactions to messages

None
administrator bool | None

Allows all permissions and bypasses channel permission overwrites

None
attach_files bool | None

Allows for uploading images and files

None
ban_members bool | None

Allows banning members

None
change_nickname bool | None

Allows for modification of own nickname

None
connect bool | None

Allows for joining of a voice channel

None
create_instant_invite bool | None

Allows creation of instant invites

None
deafen_members bool | None

Allows for deafening of members in a voice channel

None
embed_links bool | None

Links sent by users with this permission will be auto-embedded

None
kick_members bool | None

Allows kicking members

None
manage_channels bool | None

Allows management and editing of channels

None
manage_emojis_and_stickers bool | None

Allows management and editing of emojis and stickers

None
manage_events bool | None

Allows for creating, editing, and deleting scheduled events

None
manage_guild bool | None

Allows management and editing of the guild

None
manage_messages bool | None

Allows for deletion of other users messages

None
manage_nicknames bool | None

Allows for modification of other users nicknames

None
manage_roles bool | None

Allows management and editing of roles

None
manage_threads bool | None

Allows for deleting and archiving threads, and viewing all private threads

None
manage_webhooks bool | None

Allows management and editing of webhooks

None
mention_everyone bool | None

Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel

None
moderate_members bool | None

Allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels

None
move_members bool | None

Allows for moving of members between voice channels

None
mute_members bool | None

Allows for muting members in a voice channel

None
priority_speaker bool | None

Allows for using priority speaker in a voice channel

None
read_message_history bool | None

Allows for reading of message history

None
request_to_speak bool | None

Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.)

None
send_messages bool | None

Allows for sending messages in a channel (does not allow sending messages in threads)

None
send_messages_in_threads bool | None

Allows for sending messages in threads

None
send_tts_messages bool | None

Allows for sending of /tts messages

None
speak bool | None

Allows for speaking in a voice channel

None
start_embedded_activities bool | None

Allows for using Activities (applications with the EMBEDDED flag) in a voice channel

None
stream bool | None

Allows the user to go live

None
use_application_commands bool | None

Allows members to use application commands, including slash commands and context menu commands

None
use_external_emojis bool | None

Allows the usage of custom emojis from other servers

None
use_external_stickers bool | None

Allows the usage of custom stickers from other servers

None
use_private_threads bool | None

Allows for creating private threads

None
use_public_threads bool | None

Allows for creating public and announcement threads

None
use_vad bool | None

Allows for using voice-activity-detection in a voice channel

None
view_audit_log bool | None

Allows for viewing of audit logs

None
view_channel bool | None

Allows guild members to view a channel, which includes reading messages in text channels and joining voice channels

None
view_guild_insights bool | None

Allows for viewing guild insights

None
reason str | None

The reason for creating this overwrite

None
Source code in interactions/models/discord/channel.py
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
async def set_permission(
    self,
    target: Union["models.Role", "models.Member", "models.User"],
    *,
    add_reactions: bool | None = None,
    administrator: bool | None = None,
    attach_files: bool | None = None,
    ban_members: bool | None = None,
    change_nickname: bool | None = None,
    connect: bool | None = None,
    create_instant_invite: bool | None = None,
    deafen_members: bool | None = None,
    embed_links: bool | None = None,
    kick_members: bool | None = None,
    manage_channels: bool | None = None,
    manage_emojis_and_stickers: bool | None = None,
    manage_events: bool | None = None,
    manage_guild: bool | None = None,
    manage_messages: bool | None = None,
    manage_nicknames: bool | None = None,
    manage_roles: bool | None = None,
    manage_threads: bool | None = None,
    manage_webhooks: bool | None = None,
    mention_everyone: bool | None = None,
    moderate_members: bool | None = None,
    move_members: bool | None = None,
    mute_members: bool | None = None,
    priority_speaker: bool | None = None,
    read_message_history: bool | None = None,
    request_to_speak: bool | None = None,
    send_messages: bool | None = None,
    send_messages_in_threads: bool | None = None,
    send_tts_messages: bool | None = None,
    speak: bool | None = None,
    start_embedded_activities: bool | None = None,
    stream: bool | None = None,
    use_application_commands: bool | None = None,
    use_external_emojis: bool | None = None,
    use_external_stickers: bool | None = None,
    use_private_threads: bool | None = None,
    use_public_threads: bool | None = None,
    use_vad: bool | None = None,
    view_audit_log: bool | None = None,
    view_channel: bool | None = None,
    view_guild_insights: bool | None = None,
    reason: str | None = None,
) -> None:
    """
    Set the Permission Overwrites for a given target.

    Args:
        target: The target to set permission overwrites for
        add_reactions: Allows for the addition of reactions to messages
        administrator: Allows all permissions and bypasses channel permission overwrites
        attach_files: Allows for uploading images and files
        ban_members: Allows banning members
        change_nickname: Allows for modification of own nickname
        connect: Allows for joining of a voice channel
        create_instant_invite: Allows creation of instant invites
        deafen_members: Allows for deafening of members in a voice channel
        embed_links: Links sent by users with this permission will be auto-embedded
        kick_members: Allows kicking members
        manage_channels: Allows management and editing of channels
        manage_emojis_and_stickers: Allows management and editing of emojis and stickers
        manage_events: Allows for creating, editing, and deleting scheduled events
        manage_guild: Allows management and editing of the guild
        manage_messages: Allows for deletion of other users messages
        manage_nicknames: Allows for modification of other users nicknames
        manage_roles: Allows management and editing of roles
        manage_threads: Allows for deleting and archiving threads, and viewing all private threads
        manage_webhooks: Allows management and editing of webhooks
        mention_everyone: Allows for using the `@everyone` tag to notify all users in a channel, and the `@here` tag to notify all online users in a channel
        moderate_members: Allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels
        move_members: Allows for moving of members between voice channels
        mute_members: Allows for muting members in a voice channel
        priority_speaker: Allows for using priority speaker in a voice channel
        read_message_history: Allows for reading of message history
        request_to_speak: Allows for requesting to speak in stage channels. (This permission is under active development and may be changed or removed.)
        send_messages:  Allows for sending messages in a channel (does not allow sending messages in threads)
        send_messages_in_threads: Allows for sending messages in threads
        send_tts_messages:  Allows for sending of `/tts` messages
        speak: Allows for speaking in a voice channel
        start_embedded_activities: Allows for using Activities (applications with the `EMBEDDED` flag) in a voice channel
        stream: Allows the user to go live
        use_application_commands: Allows members to use application commands, including slash commands and context menu commands
        use_external_emojis: Allows the usage of custom emojis from other servers
        use_external_stickers: Allows the usage of custom stickers from other servers
        use_private_threads: Allows for creating private threads
        use_public_threads:  Allows for creating public and announcement threads
        use_vad: Allows for using voice-activity-detection in a voice channel
        view_audit_log: Allows for viewing of audit logs
        view_channel: Allows guild members to view a channel, which includes reading messages in text channels and joining voice channels
        view_guild_insights: Allows for viewing guild insights
        reason: The reason for creating this overwrite

    """
    overwrite = PermissionOverwrite.for_target(target)

    allow: Permissions = Permissions.NONE
    deny: Permissions = Permissions.NONE

    for name, val in locals().items():
        if isinstance(val, bool):
            if val:
                allow |= getattr(Permissions, name.upper())
            else:
                deny |= getattr(Permissions, name.upper())

    overwrite.add_allows(allow)
    overwrite.add_denies(deny)

    await self.edit_permission(overwrite, reason)

GuildForum

Bases: GuildChannel, InvitableMixin

Source code in interactions/models/discord/channel.py
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildForum(GuildChannel, InvitableMixin):
    available_tags: List[ThreadTag] = attrs.field(repr=False, factory=list)
    """A list of tags available to assign to threads"""
    default_reaction_emoji: Optional[DefaultReaction] = attrs.field(repr=False, default=None)
    """The default emoji to react with for posts"""
    last_message_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None)
    # TODO: Implement "template" once the API supports them
    rate_limit_per_user: int = attrs.field(repr=False, default=0)
    """Amount of seconds a user has to wait before sending another message (0-21600)"""
    default_sort_order: Optional[ForumSortOrder] = attrs.field(
        repr=False, default=None, converter=ForumSortOrder.converter
    )
    """the default sort order type used to order posts in GUILD_FORUM channels. Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin"""
    default_forum_layout: ForumLayoutType = attrs.field(
        repr=False, default=ForumLayoutType.NOT_SET, converter=ForumLayoutType
    )
    """The default forum layout view used to display posts in GUILD_FORUM channels. Defaults to 0, which indicates a layout view has not been set by a channel admin"""

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data = super()._process_dict(data, client)
        data["available_tags"] = [
            ThreadTag.from_dict(tag_data | {"parent_channel_id": data["id"]}, client)
            for tag_data in data.get("available_tags", [])
        ]
        return data

    async def create_post(
        self,
        name: str,
        content: str | None,
        applied_tags: Absent[List[Union["Snowflake_Type", "ThreadTag", str]]] = MISSING,
        *,
        auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
        rate_limit_per_user: Absent[int] = MISSING,
        embeds: Optional[Union[List[Union["Embed", dict]], Union["Embed", dict]]] = None,
        embed: Optional[Union["Embed", dict]] = None,
        components: Optional[
            Union[
                List[List[Union["BaseComponent", dict]]],
                List[Union["BaseComponent", dict]],
                "BaseComponent",
                dict,
            ]
        ] = None,
        stickers: Optional[Union[List[Union["Sticker", "Snowflake_Type"]], "Sticker", "Snowflake_Type"]] = None,
        allowed_mentions: Optional[Union["AllowedMentions", dict]] = None,
        files: Optional[Union["UPLOADABLE_TYPE", List["UPLOADABLE_TYPE"]]] = None,
        file: Optional["UPLOADABLE_TYPE"] = None,
        tts: bool = False,
        reason: Absent[str] = MISSING,
    ) -> "GuildForumPost":
        """
        Create a post within this channel.

        Args:
            name: The name of the post
            content: The text content of this post
            applied_tags: A list of tag ids or tag objects to apply to this post
            auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
            rate_limit_per_user: The time users must wait between sending messages
            embeds: Embedded rich content (up to 6000 characters).
            embed: Embedded rich content (up to 6000 characters).
            components: The components to include with the message.
            stickers: IDs of up to 3 stickers in the server to send in the message.
            allowed_mentions: Allowed mentions for the message.
            files: Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.
            file: Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.
            tts: Should this message use Text To Speech.
            reason: The reason for creating this post

        Returns:
            A GuildForumPost object representing the created post.

        """
        if applied_tags is not MISSING:
            processed = []
            for tag in applied_tags:
                if isinstance(tag, ThreadTag):
                    tag = tag.id
                elif isinstance(tag, (str, int)):
                    tag = self.get_tag(tag, case_insensitive=True)
                    if not tag:
                        continue
                    tag = tag.id
                elif isinstance(tag, dict):
                    tag = tag["id"]
                processed.append(tag)

            applied_tags = processed

        message_payload = models.discord.message.process_message_payload(
            content=content,
            embeds=embeds or embed,
            components=components,
            stickers=stickers,
            allowed_mentions=allowed_mentions,
            tts=tts,
        )

        data = await self._client.http.create_forum_thread(
            self.id,
            name,
            auto_archive_duration,
            message_payload,
            applied_tags,
            rate_limit_per_user,
            files=files or file,
            reason=reason,
        )
        return self._client.cache.place_channel_data(data)

    async def fetch_posts(self) -> List["GuildForumPost"]:
        """
        Requests all active posts within this channel.

        Returns:
            A list of GuildForumPost objects representing the posts.

        """
        # I can guarantee this endpoint will need to be converted to an async iterator eventually
        data = await self._client.http.list_active_threads(self._guild_id)
        threads = [self._client.cache.place_channel_data(post_data) for post_data in data["threads"]]

        return [thread for thread in threads if thread.parent_id == self.id]

    def get_posts(self, *, exclude_archived: bool = True) -> List["GuildForumPost"]:
        """
        List all, cached, active posts within this channel.

        Args:
            exclude_archived: Whether to exclude archived posts from the response

        Returns:
            A list of GuildForumPost objects representing the posts.

        """
        out = [thread for thread in self.guild.threads if thread.parent_id == self.id]
        if exclude_archived:
            return [thread for thread in out if not thread.archived]
        return out

    def archived_posts(self, limit: int = 0, before: Snowflake_Type | None = None) -> ArchivedForumPosts:
        """An async iterator for all archived posts in this channel."""
        return ArchivedForumPosts(self, limit, before)

    async def fetch_post(self, id: "Snowflake_Type", *, force: bool = False) -> "GuildForumPost":
        """
        Fetch a post within this channel.

        Args:
            id: The id of the post to fetch
            force: Whether to force a fetch from the API

        Returns:
            A GuildForumPost object representing the post.

        """
        return await self._client.fetch_channel(id, force=force)

    def get_post(self, id: "Snowflake_Type") -> "GuildForumPost":
        """
        Get a post within this channel.

        Args:
            id: The id of the post to get

        Returns:
            A GuildForumPost object representing the post.

        """
        return self._client.cache.get_channel(id)

    def get_tag(self, value: str | Snowflake_Type, *, case_insensitive: bool = False) -> Optional["ThreadTag"]:
        """
        Get a tag within this channel.

        Args:
            value: The name or ID of the tag to get
            case_insensitive: Whether to ignore case when searching for the tag

        Returns:
            A ThreadTag object representing the tag.

        """
        value = str(value)

        def maybe_insensitive(string: str) -> str:
            return string.lower() if case_insensitive else string

        def predicate(tag: ThreadTag) -> Optional["ThreadTag"]:
            if str(tag.id) == value:
                return tag
            if maybe_insensitive(tag.name) == maybe_insensitive(value):
                return tag

        return next((tag for tag in self.available_tags if predicate(tag)), None)

    async def create_tag(
        self, name: str, emoji: Union["models.PartialEmoji", dict, str, None] = None, moderated: bool = False
    ) -> "ThreadTag":
        """
        Create a tag for this forum.

        Args:
            name: The name of the tag
            emoji: The emoji to use for the tag
            moderated: whether this tag can only be added to or removed from threads by a member with the MANAGE_THREADS permission

        !!! note
            If the emoji is a custom emoji, it must be from the same guild as the channel.

        Returns:
            The created tag object.

        """
        payload = {"channel_id": self.id, "name": name, "moderated": moderated}

        if emoji:
            if isinstance(emoji, str):
                emoji = PartialEmoji.from_str(emoji)
            elif isinstance(emoji, dict):
                emoji = PartialEmoji.from_dict(emoji)

            if emoji.id:
                payload["emoji_id"] = emoji.id
            else:
                payload["emoji_name"] = emoji.name

        data = await self._client.http.create_tag(**payload)

        channel_data = self._client.cache.place_channel_data(data)
        return next(tag for tag in channel_data.available_tags if tag.name == name)

    async def edit_tag(
        self,
        tag_id: "Snowflake_Type",
        *,
        name: str | None = None,
        emoji: Union["models.PartialEmoji", dict, str, None] = None,
    ) -> "ThreadTag":
        """
        Edit a tag for this forum.

        Args:
            tag_id: The id of the tag to edit
            name: The name for this tag
            emoji: The emoji for this tag

        """
        if isinstance(emoji, str):
            emoji = PartialEmoji.from_str(emoji)
        elif isinstance(emoji, dict):
            emoji = PartialEmoji.from_dict(emoji)

        if emoji.id:
            data = await self._client.http.edit_tag(self.id, tag_id, name, emoji_id=emoji.id)
        else:
            data = await self._client.http.edit_tag(self.id, tag_id, name, emoji_name=emoji.name)

        channel_data = self._client.cache.place_channel_data(data)
        return next(tag for tag in channel_data.available_tags if tag.name == name)

    async def delete_tag(self, tag_id: "Snowflake_Type") -> None:
        """
        Delete a tag for this forum.

        Args:
            tag_id: The ID of the tag to delete

        """
        data = await self._client.http.delete_tag(self.id, tag_id)
        self._client.cache.place_channel_data(data)

available_tags: List[ThreadTag] = attrs.field(repr=False, factory=list) class-attribute

A list of tags available to assign to threads

default_forum_layout: ForumLayoutType = attrs.field(repr=False, default=ForumLayoutType.NOT_SET, converter=ForumLayoutType) class-attribute

The default forum layout view used to display posts in GUILD_FORUM channels. Defaults to 0, which indicates a layout view has not been set by a channel admin

default_reaction_emoji: Optional[DefaultReaction] = attrs.field(repr=False, default=None) class-attribute

The default emoji to react with for posts

default_sort_order: Optional[ForumSortOrder] = attrs.field(repr=False, default=None, converter=ForumSortOrder.converter) class-attribute

the default sort order type used to order posts in GUILD_FORUM channels. Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin

rate_limit_per_user: int = attrs.field(repr=False, default=0) class-attribute

Amount of seconds a user has to wait before sending another message (0-21600)

archived_posts(limit=0, before=None)

An async iterator for all archived posts in this channel.

Source code in interactions/models/discord/channel.py
2544
2545
2546
def archived_posts(self, limit: int = 0, before: Snowflake_Type | None = None) -> ArchivedForumPosts:
    """An async iterator for all archived posts in this channel."""
    return ArchivedForumPosts(self, limit, before)

create_post(name, content, applied_tags=MISSING, *, auto_archive_duration=AutoArchiveDuration.ONE_DAY, rate_limit_per_user=MISSING, embeds=None, embed=None, components=None, stickers=None, allowed_mentions=None, files=None, file=None, tts=False, reason=MISSING) async

Create a post within this channel.

Parameters:

Name Type Description Default
name str

The name of the post

required
content str | None

The text content of this post

required
applied_tags Absent[List[Union[Snowflake_Type, ThreadTag, str]]]

A list of tag ids or tag objects to apply to this post

MISSING
auto_archive_duration AutoArchiveDuration

Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.

AutoArchiveDuration.ONE_DAY
rate_limit_per_user Absent[int]

The time users must wait between sending messages

MISSING
embeds Optional[Union[List[Union[Embed, dict]], Union[Embed, dict]]]

Embedded rich content (up to 6000 characters).

None
embed Optional[Union[Embed, dict]]

Embedded rich content (up to 6000 characters).

None
components Optional[Union[List[List[Union[BaseComponent, dict]]], List[Union[BaseComponent, dict]], BaseComponent, dict]]

The components to include with the message.

None
stickers Optional[Union[List[Union[Sticker, Snowflake_Type]], Sticker, Snowflake_Type]]

IDs of up to 3 stickers in the server to send in the message.

None
allowed_mentions Optional[Union[AllowedMentions, dict]]

Allowed mentions for the message.

None
files Optional[Union[UPLOADABLE_TYPE, List[UPLOADABLE_TYPE]]]

Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.

None
file Optional[UPLOADABLE_TYPE]

Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.

None
tts bool

Should this message use Text To Speech.

False
reason Absent[str]

The reason for creating this post

MISSING

Returns:

Type Description
GuildForumPost

A GuildForumPost object representing the created post.

Source code in interactions/models/discord/channel.py
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
async def create_post(
    self,
    name: str,
    content: str | None,
    applied_tags: Absent[List[Union["Snowflake_Type", "ThreadTag", str]]] = MISSING,
    *,
    auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
    rate_limit_per_user: Absent[int] = MISSING,
    embeds: Optional[Union[List[Union["Embed", dict]], Union["Embed", dict]]] = None,
    embed: Optional[Union["Embed", dict]] = None,
    components: Optional[
        Union[
            List[List[Union["BaseComponent", dict]]],
            List[Union["BaseComponent", dict]],
            "BaseComponent",
            dict,
        ]
    ] = None,
    stickers: Optional[Union[List[Union["Sticker", "Snowflake_Type"]], "Sticker", "Snowflake_Type"]] = None,
    allowed_mentions: Optional[Union["AllowedMentions", dict]] = None,
    files: Optional[Union["UPLOADABLE_TYPE", List["UPLOADABLE_TYPE"]]] = None,
    file: Optional["UPLOADABLE_TYPE"] = None,
    tts: bool = False,
    reason: Absent[str] = MISSING,
) -> "GuildForumPost":
    """
    Create a post within this channel.

    Args:
        name: The name of the post
        content: The text content of this post
        applied_tags: A list of tag ids or tag objects to apply to this post
        auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
        rate_limit_per_user: The time users must wait between sending messages
        embeds: Embedded rich content (up to 6000 characters).
        embed: Embedded rich content (up to 6000 characters).
        components: The components to include with the message.
        stickers: IDs of up to 3 stickers in the server to send in the message.
        allowed_mentions: Allowed mentions for the message.
        files: Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.
        file: Files to send, the path, bytes or File() instance, defaults to None. You may have up to 10 files.
        tts: Should this message use Text To Speech.
        reason: The reason for creating this post

    Returns:
        A GuildForumPost object representing the created post.

    """
    if applied_tags is not MISSING:
        processed = []
        for tag in applied_tags:
            if isinstance(tag, ThreadTag):
                tag = tag.id
            elif isinstance(tag, (str, int)):
                tag = self.get_tag(tag, case_insensitive=True)
                if not tag:
                    continue
                tag = tag.id
            elif isinstance(tag, dict):
                tag = tag["id"]
            processed.append(tag)

        applied_tags = processed

    message_payload = models.discord.message.process_message_payload(
        content=content,
        embeds=embeds or embed,
        components=components,
        stickers=stickers,
        allowed_mentions=allowed_mentions,
        tts=tts,
    )

    data = await self._client.http.create_forum_thread(
        self.id,
        name,
        auto_archive_duration,
        message_payload,
        applied_tags,
        rate_limit_per_user,
        files=files or file,
        reason=reason,
    )
    return self._client.cache.place_channel_data(data)

create_tag(name, emoji=None, moderated=False) async

Create a tag for this forum.

Parameters:

Name Type Description Default
name str

The name of the tag

required
emoji Union[PartialEmoji, dict, str, None]

The emoji to use for the tag

None
moderated bool

whether this tag can only be added to or removed from threads by a member with the MANAGE_THREADS permission

False

Note

If the emoji is a custom emoji, it must be from the same guild as the channel.

Returns:

Type Description
ThreadTag

The created tag object.

Source code in interactions/models/discord/channel.py
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
async def create_tag(
    self, name: str, emoji: Union["models.PartialEmoji", dict, str, None] = None, moderated: bool = False
) -> "ThreadTag":
    """
    Create a tag for this forum.

    Args:
        name: The name of the tag
        emoji: The emoji to use for the tag
        moderated: whether this tag can only be added to or removed from threads by a member with the MANAGE_THREADS permission

    !!! note
        If the emoji is a custom emoji, it must be from the same guild as the channel.

    Returns:
        The created tag object.

    """
    payload = {"channel_id": self.id, "name": name, "moderated": moderated}

    if emoji:
        if isinstance(emoji, str):
            emoji = PartialEmoji.from_str(emoji)
        elif isinstance(emoji, dict):
            emoji = PartialEmoji.from_dict(emoji)

        if emoji.id:
            payload["emoji_id"] = emoji.id
        else:
            payload["emoji_name"] = emoji.name

    data = await self._client.http.create_tag(**payload)

    channel_data = self._client.cache.place_channel_data(data)
    return next(tag for tag in channel_data.available_tags if tag.name == name)

delete_tag(tag_id) async

Delete a tag for this forum.

Parameters:

Name Type Description Default
tag_id Snowflake_Type

The ID of the tag to delete

required
Source code in interactions/models/discord/channel.py
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
async def delete_tag(self, tag_id: "Snowflake_Type") -> None:
    """
    Delete a tag for this forum.

    Args:
        tag_id: The ID of the tag to delete

    """
    data = await self._client.http.delete_tag(self.id, tag_id)
    self._client.cache.place_channel_data(data)

edit_tag(tag_id, *, name=None, emoji=None) async

Edit a tag for this forum.

Parameters:

Name Type Description Default
tag_id Snowflake_Type

The id of the tag to edit

required
name str | None

The name for this tag

None
emoji Union[PartialEmoji, dict, str, None]

The emoji for this tag

None
Source code in interactions/models/discord/channel.py
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
async def edit_tag(
    self,
    tag_id: "Snowflake_Type",
    *,
    name: str | None = None,
    emoji: Union["models.PartialEmoji", dict, str, None] = None,
) -> "ThreadTag":
    """
    Edit a tag for this forum.

    Args:
        tag_id: The id of the tag to edit
        name: The name for this tag
        emoji: The emoji for this tag

    """
    if isinstance(emoji, str):
        emoji = PartialEmoji.from_str(emoji)
    elif isinstance(emoji, dict):
        emoji = PartialEmoji.from_dict(emoji)

    if emoji.id:
        data = await self._client.http.edit_tag(self.id, tag_id, name, emoji_id=emoji.id)
    else:
        data = await self._client.http.edit_tag(self.id, tag_id, name, emoji_name=emoji.name)

    channel_data = self._client.cache.place_channel_data(data)
    return next(tag for tag in channel_data.available_tags if tag.name == name)

fetch_post(id, *, force=False) async

Fetch a post within this channel.

Parameters:

Name Type Description Default
id Snowflake_Type

The id of the post to fetch

required
force bool

Whether to force a fetch from the API

False

Returns:

Type Description
GuildForumPost

A GuildForumPost object representing the post.

Source code in interactions/models/discord/channel.py
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
async def fetch_post(self, id: "Snowflake_Type", *, force: bool = False) -> "GuildForumPost":
    """
    Fetch a post within this channel.

    Args:
        id: The id of the post to fetch
        force: Whether to force a fetch from the API

    Returns:
        A GuildForumPost object representing the post.

    """
    return await self._client.fetch_channel(id, force=force)

fetch_posts() async

Requests all active posts within this channel.

Returns:

Type Description
List[GuildForumPost]

A list of GuildForumPost objects representing the posts.

Source code in interactions/models/discord/channel.py
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
async def fetch_posts(self) -> List["GuildForumPost"]:
    """
    Requests all active posts within this channel.

    Returns:
        A list of GuildForumPost objects representing the posts.

    """
    # I can guarantee this endpoint will need to be converted to an async iterator eventually
    data = await self._client.http.list_active_threads(self._guild_id)
    threads = [self._client.cache.place_channel_data(post_data) for post_data in data["threads"]]

    return [thread for thread in threads if thread.parent_id == self.id]

get_post(id)

Get a post within this channel.

Parameters:

Name Type Description Default
id Snowflake_Type

The id of the post to get

required

Returns:

Type Description
GuildForumPost

A GuildForumPost object representing the post.

Source code in interactions/models/discord/channel.py
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
def get_post(self, id: "Snowflake_Type") -> "GuildForumPost":
    """
    Get a post within this channel.

    Args:
        id: The id of the post to get

    Returns:
        A GuildForumPost object representing the post.

    """
    return self._client.cache.get_channel(id)

get_posts(*, exclude_archived=True)

List all, cached, active posts within this channel.

Parameters:

Name Type Description Default
exclude_archived bool

Whether to exclude archived posts from the response

True

Returns:

Type Description
List[GuildForumPost]

A list of GuildForumPost objects representing the posts.

Source code in interactions/models/discord/channel.py
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
def get_posts(self, *, exclude_archived: bool = True) -> List["GuildForumPost"]:
    """
    List all, cached, active posts within this channel.

    Args:
        exclude_archived: Whether to exclude archived posts from the response

    Returns:
        A list of GuildForumPost objects representing the posts.

    """
    out = [thread for thread in self.guild.threads if thread.parent_id == self.id]
    if exclude_archived:
        return [thread for thread in out if not thread.archived]
    return out

get_tag(value, *, case_insensitive=False)

Get a tag within this channel.

Parameters:

Name Type Description Default
value str | Snowflake_Type

The name or ID of the tag to get

required
case_insensitive bool

Whether to ignore case when searching for the tag

False

Returns:

Type Description
Optional[ThreadTag]

A ThreadTag object representing the tag.

Source code in interactions/models/discord/channel.py
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
def get_tag(self, value: str | Snowflake_Type, *, case_insensitive: bool = False) -> Optional["ThreadTag"]:
    """
    Get a tag within this channel.

    Args:
        value: The name or ID of the tag to get
        case_insensitive: Whether to ignore case when searching for the tag

    Returns:
        A ThreadTag object representing the tag.

    """
    value = str(value)

    def maybe_insensitive(string: str) -> str:
        return string.lower() if case_insensitive else string

    def predicate(tag: ThreadTag) -> Optional["ThreadTag"]:
        if str(tag.id) == value:
            return tag
        if maybe_insensitive(tag.name) == maybe_insensitive(value):
            return tag

    return next((tag for tag in self.available_tags if predicate(tag)), None)

GuildForumPost

Bases: GuildPublicThread

A forum post

Note

This model is an abstraction of the api - In reality all posts are GuildPublicThread

Source code in interactions/models/discord/channel.py
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildForumPost(GuildPublicThread):
    """
    A forum post

    !!! note
        This model is an abstraction of the api - In reality all posts are GuildPublicThread
    """

    _applied_tags: list[Snowflake_Type] = attrs.field(repr=False, factory=list)

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data = super()._process_dict(data, client)
        data["_applied_tags"] = data.pop("applied_tags") if "applied_tags" in data else []
        return data

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        archived: Absent[bool] = MISSING,
        auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
        applied_tags: Absent[List[Union[Snowflake_Type, ThreadTag]]] = MISSING,
        locked: Absent[bool] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        flags: Absent[Union[int, ChannelFlags]] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "GuildForumPost":
        """
        Edit this thread.

        Args:
            name: 1-100 character channel name
            archived: whether the thread is archived
            applied_tags: list of tags to apply
            auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
            locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
            rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
            flags: channel flags to apply
            reason: The reason for this change

        Returns:
            The edited thread channel object.

        """
        if applied_tags != MISSING:
            applied_tags = [str(tag.id) if isinstance(tag, ThreadTag) else str(tag) for tag in applied_tags]

        return await super().edit(
            name=name,
            archived=archived,
            auto_archive_duration=auto_archive_duration,
            applied_tags=applied_tags,
            locked=locked,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
            flags=flags,
            **kwargs,
        )

    @property
    def applied_tags(self) -> list[ThreadTag]:
        """The tags applied to this thread."""
        if not isinstance(self.parent_channel, GuildForum):
            raise AttributeError("This is only available on forum threads.")
        return [tag for tag in self.parent_channel.available_tags if str(tag.id) in self._applied_tags]

    @property
    def initial_post(self) -> Optional["Message"]:
        """The initial message posted by the OP."""
        if not isinstance(self.parent_channel, GuildForum):
            raise AttributeError("This is only available on forum threads.")
        return self.get_message(self.id)

    @property
    def pinned(self) -> bool:
        """Whether this thread is pinned."""
        return ChannelFlags.PINNED in self.flags

    async def pin(self, reason: Absent[str] = MISSING) -> None:
        """
        Pin this thread.

        Args:
            reason: The reason for this pin

        """
        flags = self.flags | ChannelFlags.PINNED
        await self.edit(flags=flags, reason=reason)

    async def unpin(self, reason: Absent[str] = MISSING) -> None:
        """
        Unpin this thread.

        Args:
            reason: The reason for this unpin

        """
        flags = self.flags & ~ChannelFlags.PINNED
        await self.edit(flags=flags, reason=reason)

applied_tags: list[ThreadTag] property

The tags applied to this thread.

initial_post: Optional[Message] property

The initial message posted by the OP.

pinned: bool property

Whether this thread is pinned.

edit(*, name=MISSING, archived=MISSING, auto_archive_duration=MISSING, applied_tags=MISSING, locked=MISSING, rate_limit_per_user=MISSING, flags=MISSING, reason=MISSING, **kwargs) async

Edit this thread.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
archived Absent[bool]

whether the thread is archived

MISSING
applied_tags Absent[List[Union[Snowflake_Type, ThreadTag]]]

list of tags to apply

MISSING
auto_archive_duration Absent[AutoArchiveDuration]

duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080

MISSING
locked Absent[bool]

whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it

MISSING
rate_limit_per_user Absent[int]

amount of seconds a user has to wait before sending another message (0-21600)

MISSING
flags Absent[Union[int, ChannelFlags]]

channel flags to apply

MISSING
reason Absent[str]

The reason for this change

MISSING

Returns:

Type Description
GuildForumPost

The edited thread channel object.

Source code in interactions/models/discord/channel.py
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    archived: Absent[bool] = MISSING,
    auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
    applied_tags: Absent[List[Union[Snowflake_Type, ThreadTag]]] = MISSING,
    locked: Absent[bool] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    flags: Absent[Union[int, ChannelFlags]] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "GuildForumPost":
    """
    Edit this thread.

    Args:
        name: 1-100 character channel name
        archived: whether the thread is archived
        applied_tags: list of tags to apply
        auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
        locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
        rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
        flags: channel flags to apply
        reason: The reason for this change

    Returns:
        The edited thread channel object.

    """
    if applied_tags != MISSING:
        applied_tags = [str(tag.id) if isinstance(tag, ThreadTag) else str(tag) for tag in applied_tags]

    return await super().edit(
        name=name,
        archived=archived,
        auto_archive_duration=auto_archive_duration,
        applied_tags=applied_tags,
        locked=locked,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
        flags=flags,
        **kwargs,
    )

pin(reason=MISSING) async

Pin this thread.

Parameters:

Name Type Description Default
reason Absent[str]

The reason for this pin

MISSING
Source code in interactions/models/discord/channel.py
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
async def pin(self, reason: Absent[str] = MISSING) -> None:
    """
    Pin this thread.

    Args:
        reason: The reason for this pin

    """
    flags = self.flags | ChannelFlags.PINNED
    await self.edit(flags=flags, reason=reason)

unpin(reason=MISSING) async

Unpin this thread.

Parameters:

Name Type Description Default
reason Absent[str]

The reason for this unpin

MISSING
Source code in interactions/models/discord/channel.py
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
async def unpin(self, reason: Absent[str] = MISSING) -> None:
    """
    Unpin this thread.

    Args:
        reason: The reason for this unpin

    """
    flags = self.flags & ~ChannelFlags.PINNED
    await self.edit(flags=flags, reason=reason)

GuildNews

Bases: GuildChannel, MessageableMixin, InvitableMixin, ThreadableMixin, WebhookMixin

Source code in interactions/models/discord/channel.py
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildNews(GuildChannel, MessageableMixin, InvitableMixin, ThreadableMixin, WebhookMixin):
    topic: Optional[str] = attrs.field(repr=False, default=None)
    """The channel topic (0-1024 characters)"""

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        position: Absent[int] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        parent_id: Absent[Snowflake_Type] = MISSING,
        nsfw: Absent[bool] = MISSING,
        topic: Absent[str] = MISSING,
        channel_type: Absent["ChannelType"] = MISSING,
        default_auto_archive_duration: Absent["AutoArchiveDuration"] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> Union["GuildNews", "GuildText"]:
        """
        Edit the guild text channel.

        Args:
            name: 1-100 character channel name
            position: the position of the channel in the left-hand listing
            permission_overwrites: a list of PermissionOverwrite
            parent_id:  the parent category `Snowflake_Type` for the channel
            nsfw: whether the channel is nsfw
            topic: 0-1024 character channel topic
            channel_type: the type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature
            default_auto_archive_duration: optional AutoArchiveDuration
            reason: An optional reason for the audit log

        Returns:
            The edited channel.

        """
        return await super().edit(
            name=name,
            position=position,
            permission_overwrites=permission_overwrites,
            parent_id=parent_id,
            nsfw=nsfw,
            topic=topic,
            type=channel_type,
            default_auto_archive_duration=default_auto_archive_duration,
            reason=reason,
            **kwargs,
        )

    async def follow(self, webhook_channel_id: Snowflake_Type) -> None:
        """
        Follow this channel.

        Args:
            webhook_channel_id: The ID of the channel to post messages from this channel to

        """
        await self._client.http.follow_news_channel(self.id, webhook_channel_id)

    async def create_thread_from_message(
        self,
        name: str,
        message: Snowflake_Type,
        auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
        reason: Absent[str] | None = None,
    ) -> "GuildNewsThread":
        """
        Creates a new news thread in this channel.

        Args:
            name: 1-100 character thread name.
            message: The message to connect this thread to.
            auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
            reason: The reason for creating this thread.

        Returns:
            The created public thread, if successful

        """
        return await self.create_thread(
            name=name,
            message=message,
            auto_archive_duration=auto_archive_duration,
            reason=reason,
        )

topic: Optional[str] = attrs.field(repr=False, default=None) class-attribute

The channel topic (0-1024 characters)

create_thread_from_message(name, message, auto_archive_duration=AutoArchiveDuration.ONE_DAY, reason=None) async

Creates a new news thread in this channel.

Parameters:

Name Type Description Default
name str

1-100 character thread name.

required
message Snowflake_Type

The message to connect this thread to.

required
auto_archive_duration AutoArchiveDuration

Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.

AutoArchiveDuration.ONE_DAY
reason Absent[str] | None

The reason for creating this thread.

None

Returns:

Type Description
GuildNewsThread

The created public thread, if successful

Source code in interactions/models/discord/channel.py
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
async def create_thread_from_message(
    self,
    name: str,
    message: Snowflake_Type,
    auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
    reason: Absent[str] | None = None,
) -> "GuildNewsThread":
    """
    Creates a new news thread in this channel.

    Args:
        name: 1-100 character thread name.
        message: The message to connect this thread to.
        auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
        reason: The reason for creating this thread.

    Returns:
        The created public thread, if successful

    """
    return await self.create_thread(
        name=name,
        message=message,
        auto_archive_duration=auto_archive_duration,
        reason=reason,
    )

edit(*, name=MISSING, position=MISSING, permission_overwrites=MISSING, parent_id=MISSING, nsfw=MISSING, topic=MISSING, channel_type=MISSING, default_auto_archive_duration=MISSING, reason=MISSING, **kwargs) async

Edit the guild text channel.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
position Absent[int]

the position of the channel in the left-hand listing

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

a list of PermissionOverwrite

MISSING
parent_id Absent[Snowflake_Type]

the parent category Snowflake_Type for the channel

MISSING
nsfw Absent[bool]

whether the channel is nsfw

MISSING
topic Absent[str]

0-1024 character channel topic

MISSING
channel_type Absent[ChannelType]

the type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature

MISSING
default_auto_archive_duration Absent[AutoArchiveDuration]

optional AutoArchiveDuration

MISSING
reason Absent[str]

An optional reason for the audit log

MISSING

Returns:

Type Description
Union[GuildNews, GuildText]

The edited channel.

Source code in interactions/models/discord/channel.py
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    position: Absent[int] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    parent_id: Absent[Snowflake_Type] = MISSING,
    nsfw: Absent[bool] = MISSING,
    topic: Absent[str] = MISSING,
    channel_type: Absent["ChannelType"] = MISSING,
    default_auto_archive_duration: Absent["AutoArchiveDuration"] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> Union["GuildNews", "GuildText"]:
    """
    Edit the guild text channel.

    Args:
        name: 1-100 character channel name
        position: the position of the channel in the left-hand listing
        permission_overwrites: a list of PermissionOverwrite
        parent_id:  the parent category `Snowflake_Type` for the channel
        nsfw: whether the channel is nsfw
        topic: 0-1024 character channel topic
        channel_type: the type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature
        default_auto_archive_duration: optional AutoArchiveDuration
        reason: An optional reason for the audit log

    Returns:
        The edited channel.

    """
    return await super().edit(
        name=name,
        position=position,
        permission_overwrites=permission_overwrites,
        parent_id=parent_id,
        nsfw=nsfw,
        topic=topic,
        type=channel_type,
        default_auto_archive_duration=default_auto_archive_duration,
        reason=reason,
        **kwargs,
    )

follow(webhook_channel_id) async

Follow this channel.

Parameters:

Name Type Description Default
webhook_channel_id Snowflake_Type

The ID of the channel to post messages from this channel to

required
Source code in interactions/models/discord/channel.py
1663
1664
1665
1666
1667
1668
1669
1670
1671
async def follow(self, webhook_channel_id: Snowflake_Type) -> None:
    """
    Follow this channel.

    Args:
        webhook_channel_id: The ID of the channel to post messages from this channel to

    """
    await self._client.http.follow_news_channel(self.id, webhook_channel_id)

GuildNewsThread

Bases: ThreadChannel

Source code in interactions/models/discord/channel.py
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildNewsThread(ThreadChannel):
    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        archived: Absent[bool] = MISSING,
        auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
        locked: Absent[bool] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "GuildNewsThread":
        """
        Edit this thread.

        Args:
            name: 1-100 character channel name
            archived: whether the thread is archived
            auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
            locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
            rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
            reason: The reason for this change

        Returns:
            The edited thread channel object.

        """
        return await super().edit(
            name=name,
            archived=archived,
            auto_archive_duration=auto_archive_duration,
            locked=locked,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
            **kwargs,
        )

edit(*, name=MISSING, archived=MISSING, auto_archive_duration=MISSING, locked=MISSING, rate_limit_per_user=MISSING, reason=MISSING, **kwargs) async

Edit this thread.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
archived Absent[bool]

whether the thread is archived

MISSING
auto_archive_duration Absent[AutoArchiveDuration]

duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080

MISSING
locked Absent[bool]

whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it

MISSING
rate_limit_per_user Absent[int]

amount of seconds a user has to wait before sending another message (0-21600)

MISSING
reason Absent[str]

The reason for this change

MISSING

Returns:

Type Description
GuildNewsThread

The edited thread channel object.

Source code in interactions/models/discord/channel.py
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    archived: Absent[bool] = MISSING,
    auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
    locked: Absent[bool] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "GuildNewsThread":
    """
    Edit this thread.

    Args:
        name: 1-100 character channel name
        archived: whether the thread is archived
        auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
        locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
        rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
        reason: The reason for this change

    Returns:
        The edited thread channel object.

    """
    return await super().edit(
        name=name,
        archived=archived,
        auto_archive_duration=auto_archive_duration,
        locked=locked,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
        **kwargs,
    )

GuildPrivateThread

Bases: ThreadChannel

Source code in interactions/models/discord/channel.py
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildPrivateThread(ThreadChannel):
    invitable: bool = attrs.field(repr=False, default=False)
    """Whether non-moderators can add other non-moderators to a thread"""

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        archived: Absent[bool] = MISSING,
        auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
        locked: Absent[bool] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        invitable: Absent[bool] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "GuildPrivateThread":
        """
        Edit this thread.

        Args:
            name: 1-100 character channel name
            archived: whether the thread is archived
            auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
            locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
            rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
            invitable: whether non-moderators can add other non-moderators to a thread; only available on private threads
            reason: The reason for this change

        Returns:
            The edited thread channel object.

        """
        return await super().edit(
            name=name,
            archived=archived,
            auto_archive_duration=auto_archive_duration,
            locked=locked,
            rate_limit_per_user=rate_limit_per_user,
            invitable=invitable,
            reason=reason,
            **kwargs,
        )

invitable: bool = attrs.field(repr=False, default=False) class-attribute

Whether non-moderators can add other non-moderators to a thread

edit(*, name=MISSING, archived=MISSING, auto_archive_duration=MISSING, locked=MISSING, rate_limit_per_user=MISSING, invitable=MISSING, reason=MISSING, **kwargs) async

Edit this thread.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
archived Absent[bool]

whether the thread is archived

MISSING
auto_archive_duration Absent[AutoArchiveDuration]

duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080

MISSING
locked Absent[bool]

whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it

MISSING
rate_limit_per_user Absent[int]

amount of seconds a user has to wait before sending another message (0-21600)

MISSING
invitable Absent[bool]

whether non-moderators can add other non-moderators to a thread; only available on private threads

MISSING
reason Absent[str]

The reason for this change

MISSING

Returns:

Type Description
GuildPrivateThread

The edited thread channel object.

Source code in interactions/models/discord/channel.py
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    archived: Absent[bool] = MISSING,
    auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
    locked: Absent[bool] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    invitable: Absent[bool] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "GuildPrivateThread":
    """
    Edit this thread.

    Args:
        name: 1-100 character channel name
        archived: whether the thread is archived
        auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
        locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
        rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
        invitable: whether non-moderators can add other non-moderators to a thread; only available on private threads
        reason: The reason for this change

    Returns:
        The edited thread channel object.

    """
    return await super().edit(
        name=name,
        archived=archived,
        auto_archive_duration=auto_archive_duration,
        locked=locked,
        rate_limit_per_user=rate_limit_per_user,
        invitable=invitable,
        reason=reason,
        **kwargs,
    )

GuildPublicThread

Bases: ThreadChannel

Source code in interactions/models/discord/channel.py
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildPublicThread(ThreadChannel):
    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        archived: Absent[bool] = MISSING,
        auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
        locked: Absent[bool] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        flags: Absent[Union[int, ChannelFlags]] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> "GuildPublicThread":
        """
        Edit this thread.

        Args:
            name: 1-100 character channel name
            archived: whether the thread is archived
            auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
            locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
            rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
            flags: channel flags for forum threads
            reason: The reason for this change

        Returns:
            The edited thread channel object.

        """
        return await super().edit(
            name=name,
            archived=archived,
            auto_archive_duration=auto_archive_duration,
            locked=locked,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
            flags=flags,
            **kwargs,
        )

edit(*, name=MISSING, archived=MISSING, auto_archive_duration=MISSING, locked=MISSING, rate_limit_per_user=MISSING, flags=MISSING, reason=MISSING, **kwargs) async

Edit this thread.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
archived Absent[bool]

whether the thread is archived

MISSING
auto_archive_duration Absent[AutoArchiveDuration]

duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080

MISSING
locked Absent[bool]

whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it

MISSING
rate_limit_per_user Absent[int]

amount of seconds a user has to wait before sending another message (0-21600)

MISSING
flags Absent[Union[int, ChannelFlags]]

channel flags for forum threads

MISSING
reason Absent[str]

The reason for this change

MISSING

Returns:

Type Description
GuildPublicThread

The edited thread channel object.

Source code in interactions/models/discord/channel.py
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    archived: Absent[bool] = MISSING,
    auto_archive_duration: Absent[AutoArchiveDuration] = MISSING,
    locked: Absent[bool] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    flags: Absent[Union[int, ChannelFlags]] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> "GuildPublicThread":
    """
    Edit this thread.

    Args:
        name: 1-100 character channel name
        archived: whether the thread is archived
        auto_archive_duration: duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
        locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
        rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
        flags: channel flags for forum threads
        reason: The reason for this change

    Returns:
        The edited thread channel object.

    """
    return await super().edit(
        name=name,
        archived=archived,
        auto_archive_duration=auto_archive_duration,
        locked=locked,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
        flags=flags,
        **kwargs,
    )

GuildStageVoice

Bases: GuildVoice

Source code in interactions/models/discord/channel.py
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildStageVoice(GuildVoice):
    stage_instance: "models.StageInstance" = attrs.field(repr=False, default=MISSING)
    """The stage instance that this voice channel belongs to"""

    # todo: Listeners and speakers properties (needs voice state caching)

    async def fetch_stage_instance(self) -> "models.StageInstance":
        """
        Fetches the stage instance associated with this channel.

        Returns:
            The stage instance associated with this channel. If no stage is live, will return None.

        """
        self.stage_instance = models.StageInstance.from_dict(
            await self._client.http.get_stage_instance(self.id), self._client
        )
        return self.stage_instance

    async def create_stage_instance(
        self,
        topic: str,
        privacy_level: StagePrivacyLevel = StagePrivacyLevel.GUILD_ONLY,
        reason: Absent[Optional[str]] = MISSING,
    ) -> "models.StageInstance":
        """
        Create a stage instance in this channel.

        Args:
            topic: The topic of the stage (1-120 characters)
            privacy_level: The privacy level of the stage
            reason: The reason for creating this instance

        Returns:
            The created stage instance object.

        """
        self.stage_instance = models.StageInstance.from_dict(
            await self._client.http.create_stage_instance(self.id, topic, privacy_level, reason),
            self._client,
        )
        return self.stage_instance

    async def close_stage(self, reason: Absent[Optional[str]] = MISSING) -> None:
        """
        Closes the live stage instance.

        Args:
            reason: The reason for closing the stage

        """
        if not self.stage_instance and not await self.get_stage_instance():
            # we dont know of an active stage instance, so lets check for one
            raise ValueError("No stage instance found")

        await self.stage_instance.delete(reason=reason)

stage_instance: models.StageInstance = attrs.field(repr=False, default=MISSING) class-attribute

The stage instance that this voice channel belongs to

close_stage(reason=MISSING) async

Closes the live stage instance.

Parameters:

Name Type Description Default
reason Absent[Optional[str]]

The reason for closing the stage

MISSING
Source code in interactions/models/discord/channel.py
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
async def close_stage(self, reason: Absent[Optional[str]] = MISSING) -> None:
    """
    Closes the live stage instance.

    Args:
        reason: The reason for closing the stage

    """
    if not self.stage_instance and not await self.get_stage_instance():
        # we dont know of an active stage instance, so lets check for one
        raise ValueError("No stage instance found")

    await self.stage_instance.delete(reason=reason)

create_stage_instance(topic, privacy_level=StagePrivacyLevel.GUILD_ONLY, reason=MISSING) async

Create a stage instance in this channel.

Parameters:

Name Type Description Default
topic str

The topic of the stage (1-120 characters)

required
privacy_level StagePrivacyLevel

The privacy level of the stage

StagePrivacyLevel.GUILD_ONLY
reason Absent[Optional[str]]

The reason for creating this instance

MISSING

Returns:

Type Description
StageInstance

The created stage instance object.

Source code in interactions/models/discord/channel.py
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
async def create_stage_instance(
    self,
    topic: str,
    privacy_level: StagePrivacyLevel = StagePrivacyLevel.GUILD_ONLY,
    reason: Absent[Optional[str]] = MISSING,
) -> "models.StageInstance":
    """
    Create a stage instance in this channel.

    Args:
        topic: The topic of the stage (1-120 characters)
        privacy_level: The privacy level of the stage
        reason: The reason for creating this instance

    Returns:
        The created stage instance object.

    """
    self.stage_instance = models.StageInstance.from_dict(
        await self._client.http.create_stage_instance(self.id, topic, privacy_level, reason),
        self._client,
    )
    return self.stage_instance

fetch_stage_instance() async

Fetches the stage instance associated with this channel.

Returns:

Type Description
StageInstance

The stage instance associated with this channel. If no stage is live, will return None.

Source code in interactions/models/discord/channel.py
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
async def fetch_stage_instance(self) -> "models.StageInstance":
    """
    Fetches the stage instance associated with this channel.

    Returns:
        The stage instance associated with this channel. If no stage is live, will return None.

    """
    self.stage_instance = models.StageInstance.from_dict(
        await self._client.http.get_stage_instance(self.id), self._client
    )
    return self.stage_instance

GuildText

Bases: GuildChannel, MessageableMixin, InvitableMixin, ThreadableMixin, WebhookMixin

Source code in interactions/models/discord/channel.py
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildText(GuildChannel, MessageableMixin, InvitableMixin, ThreadableMixin, WebhookMixin):
    topic: Optional[str] = attrs.field(repr=False, default=None)
    """The channel topic (0-1024 characters)"""

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        position: Absent[int] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        parent_id: Absent[Snowflake_Type] = MISSING,
        nsfw: Absent[bool] = MISSING,
        topic: Absent[str] = MISSING,
        channel_type: Absent["ChannelType"] = MISSING,
        default_auto_archive_duration: Absent["AutoArchiveDuration"] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> Union["GuildText", "GuildNews"]:
        """
        Edit the guild text channel.

        Args:
            name: 1-100 character channel name
            position: the position of the channel in the left-hand listing
            permission_overwrites: a list of PermissionOverwrite
            parent_id:  the parent category `Snowflake_Type` for the channel
            nsfw: whether the channel is nsfw
            topic: 0-1024 character channel topic
            channel_type: the type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature
            default_auto_archive_duration: optional AutoArchiveDuration
            rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
            reason: An optional reason for the audit log

        Returns:
            The edited channel.

        """
        return await super().edit(
            name=name,
            position=position,
            permission_overwrites=permission_overwrites,
            parent_id=parent_id,
            nsfw=nsfw,
            topic=topic,
            type=channel_type,
            default_auto_archive_duration=default_auto_archive_duration,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
            **kwargs,
        )

    async def create_public_thread(
        self,
        name: str,
        auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
        rate_limit_per_user: Absent[int] = MISSING,
        reason: Absent[str] | None = None,
    ) -> "GuildPublicThread":
        """
        Creates a new public thread in this channel.

        Args:
            name: 1-100 character thread name.
            auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
            rate_limit_per_user: The time users must wait between sending messages (0-21600).
            reason: The reason for creating this thread.

        Returns:
            The created public thread, if successful

        """
        return await self.create_thread(
            name=name,
            thread_type=ChannelType.GUILD_PUBLIC_THREAD,
            auto_archive_duration=auto_archive_duration,
            rate_limit_per_user=rate_limit_per_user,
            reason=reason,
        )

    async def create_private_thread(
        self,
        name: str,
        invitable: Absent[bool] = MISSING,
        auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
        rate_limit_per_user: Absent[int] = MISSING,
        reason: Absent[str] | None = None,
    ) -> "GuildPrivateThread":
        """
        Creates a new private thread in this channel.

        Args:
            name: 1-100 character thread name.
            invitable: Whether non-moderators can add other non-moderators to a thread.
            rate_limit_per_user: The time users must wait between sending messages (0-21600).
            auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
            reason: The reason for creating this thread.

        Returns:
            The created thread, if successful

        """
        return await self.create_thread(
            name=name,
            thread_type=ChannelType.GUILD_PRIVATE_THREAD,
            invitable=invitable,
            rate_limit_per_user=rate_limit_per_user,
            auto_archive_duration=auto_archive_duration,
            reason=reason,
        )

    async def create_thread_from_message(
        self,
        name: str,
        message: Snowflake_Type,
        auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
        reason: Absent[str] | None = None,
    ) -> "GuildPublicThread":
        """
        Creates a new public thread in this channel.

        Args:
            name: 1-100 character thread name.
            message: The message to connect this thread to.
            auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
            reason: The reason for creating this thread.

        Returns:
            The created public thread, if successful

        """
        return await self.create_thread(
            name=name,
            message=message,
            auto_archive_duration=auto_archive_duration,
            reason=reason,
        )

topic: Optional[str] = attrs.field(repr=False, default=None) class-attribute

The channel topic (0-1024 characters)

create_private_thread(name, invitable=MISSING, auto_archive_duration=AutoArchiveDuration.ONE_DAY, rate_limit_per_user=MISSING, reason=None) async

Creates a new private thread in this channel.

Parameters:

Name Type Description Default
name str

1-100 character thread name.

required
invitable Absent[bool]

Whether non-moderators can add other non-moderators to a thread.

MISSING
rate_limit_per_user Absent[int]

The time users must wait between sending messages (0-21600).

MISSING
auto_archive_duration AutoArchiveDuration

Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.

AutoArchiveDuration.ONE_DAY
reason Absent[str] | None

The reason for creating this thread.

None

Returns:

Type Description
GuildPrivateThread

The created thread, if successful

Source code in interactions/models/discord/channel.py
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
async def create_private_thread(
    self,
    name: str,
    invitable: Absent[bool] = MISSING,
    auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
    rate_limit_per_user: Absent[int] = MISSING,
    reason: Absent[str] | None = None,
) -> "GuildPrivateThread":
    """
    Creates a new private thread in this channel.

    Args:
        name: 1-100 character thread name.
        invitable: Whether non-moderators can add other non-moderators to a thread.
        rate_limit_per_user: The time users must wait between sending messages (0-21600).
        auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
        reason: The reason for creating this thread.

    Returns:
        The created thread, if successful

    """
    return await self.create_thread(
        name=name,
        thread_type=ChannelType.GUILD_PRIVATE_THREAD,
        invitable=invitable,
        rate_limit_per_user=rate_limit_per_user,
        auto_archive_duration=auto_archive_duration,
        reason=reason,
    )

create_public_thread(name, auto_archive_duration=AutoArchiveDuration.ONE_DAY, rate_limit_per_user=MISSING, reason=None) async

Creates a new public thread in this channel.

Parameters:

Name Type Description Default
name str

1-100 character thread name.

required
auto_archive_duration AutoArchiveDuration

Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.

AutoArchiveDuration.ONE_DAY
rate_limit_per_user Absent[int]

The time users must wait between sending messages (0-21600).

MISSING
reason Absent[str] | None

The reason for creating this thread.

None

Returns:

Type Description
GuildPublicThread

The created public thread, if successful

Source code in interactions/models/discord/channel.py
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
async def create_public_thread(
    self,
    name: str,
    auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
    rate_limit_per_user: Absent[int] = MISSING,
    reason: Absent[str] | None = None,
) -> "GuildPublicThread":
    """
    Creates a new public thread in this channel.

    Args:
        name: 1-100 character thread name.
        auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
        rate_limit_per_user: The time users must wait between sending messages (0-21600).
        reason: The reason for creating this thread.

    Returns:
        The created public thread, if successful

    """
    return await self.create_thread(
        name=name,
        thread_type=ChannelType.GUILD_PUBLIC_THREAD,
        auto_archive_duration=auto_archive_duration,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
    )

create_thread_from_message(name, message, auto_archive_duration=AutoArchiveDuration.ONE_DAY, reason=None) async

Creates a new public thread in this channel.

Parameters:

Name Type Description Default
name str

1-100 character thread name.

required
message Snowflake_Type

The message to connect this thread to.

required
auto_archive_duration AutoArchiveDuration

Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.

AutoArchiveDuration.ONE_DAY
reason Absent[str] | None

The reason for creating this thread.

None

Returns:

Type Description
GuildPublicThread

The created public thread, if successful

Source code in interactions/models/discord/channel.py
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
async def create_thread_from_message(
    self,
    name: str,
    message: Snowflake_Type,
    auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
    reason: Absent[str] | None = None,
) -> "GuildPublicThread":
    """
    Creates a new public thread in this channel.

    Args:
        name: 1-100 character thread name.
        message: The message to connect this thread to.
        auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
        reason: The reason for creating this thread.

    Returns:
        The created public thread, if successful

    """
    return await self.create_thread(
        name=name,
        message=message,
        auto_archive_duration=auto_archive_duration,
        reason=reason,
    )

edit(*, name=MISSING, position=MISSING, permission_overwrites=MISSING, parent_id=MISSING, nsfw=MISSING, topic=MISSING, channel_type=MISSING, default_auto_archive_duration=MISSING, rate_limit_per_user=MISSING, reason=MISSING, **kwargs) async

Edit the guild text channel.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
position Absent[int]

the position of the channel in the left-hand listing

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

a list of PermissionOverwrite

MISSING
parent_id Absent[Snowflake_Type]

the parent category Snowflake_Type for the channel

MISSING
nsfw Absent[bool]

whether the channel is nsfw

MISSING
topic Absent[str]

0-1024 character channel topic

MISSING
channel_type Absent[ChannelType]

the type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature

MISSING
default_auto_archive_duration Absent[AutoArchiveDuration]

optional AutoArchiveDuration

MISSING
rate_limit_per_user Absent[int]

amount of seconds a user has to wait before sending another message (0-21600)

MISSING
reason Absent[str]

An optional reason for the audit log

MISSING

Returns:

Type Description
Union[GuildText, GuildNews]

The edited channel.

Source code in interactions/models/discord/channel.py
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    position: Absent[int] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    parent_id: Absent[Snowflake_Type] = MISSING,
    nsfw: Absent[bool] = MISSING,
    topic: Absent[str] = MISSING,
    channel_type: Absent["ChannelType"] = MISSING,
    default_auto_archive_duration: Absent["AutoArchiveDuration"] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> Union["GuildText", "GuildNews"]:
    """
    Edit the guild text channel.

    Args:
        name: 1-100 character channel name
        position: the position of the channel in the left-hand listing
        permission_overwrites: a list of PermissionOverwrite
        parent_id:  the parent category `Snowflake_Type` for the channel
        nsfw: whether the channel is nsfw
        topic: 0-1024 character channel topic
        channel_type: the type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature
        default_auto_archive_duration: optional AutoArchiveDuration
        rate_limit_per_user: amount of seconds a user has to wait before sending another message (0-21600)
        reason: An optional reason for the audit log

    Returns:
        The edited channel.

    """
    return await super().edit(
        name=name,
        position=position,
        permission_overwrites=permission_overwrites,
        parent_id=parent_id,
        nsfw=nsfw,
        topic=topic,
        type=channel_type,
        default_auto_archive_duration=default_auto_archive_duration,
        rate_limit_per_user=rate_limit_per_user,
        reason=reason,
        **kwargs,
    )

InvitableMixin

Source code in interactions/models/discord/channel.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class InvitableMixin:
    async def create_invite(
        self,
        max_age: int = 86400,
        max_uses: int = 0,
        temporary: bool = False,
        unique: bool = False,
        target_type: Optional[InviteTargetType] = None,
        target_user: Optional[Union[Snowflake_Type, "models.User"]] = None,
        target_application: Optional[Union[Snowflake_Type, "models.Application"]] = None,
        reason: Optional[str] = None,
    ) -> "models.Invite":
        """
        Creates a new channel invite.

        Args:
            max_age: Max age of invite in seconds, default 86400 (24 hours).
            max_uses: Max uses of invite, default 0.
            temporary: Grants temporary membership, default False.
            unique: Invite is unique, default false.
            target_type: Target type for streams and embedded applications.
            target_user: Target User ID for Stream target type.
            target_application: Target Application ID for Embedded App target type.
            reason: The reason for creating this invite.

        Returns:
            Newly created Invite object.

        """
        if target_type:
            if target_type == InviteTargetType.STREAM and not target_user:
                raise ValueError("Stream target must include target user id.")
            if target_type == InviteTargetType.EMBEDDED_APPLICATION and not target_application:
                raise ValueError("Embedded Application target must include target application id.")

        if target_user and target_application:
            raise ValueError("Invite target must be either User or Embedded Application, not both.")
        if target_user:
            target_user = to_snowflake(target_user)
            target_type = InviteTargetType.STREAM
        if target_application:
            target_application = to_snowflake(target_application)
            target_type = InviteTargetType.EMBEDDED_APPLICATION

        invite_data = await self._client.http.create_channel_invite(
            self.id,
            max_age,
            max_uses,
            temporary,
            unique,
            target_user_id=target_user,
            target_application_id=target_application,
            reason=reason,
        )
        return models.Invite.from_dict(invite_data, self._client)

    async def fetch_invites(self) -> List["models.Invite"]:
        """
        Fetches all invites (with invite metadata) for the channel.

        Returns:
            List of Invite objects.

        """
        invites_data = await self._client.http.get_channel_invites(self.id)
        return models.Invite.from_list(invites_data, self._client)

create_invite(max_age=86400, max_uses=0, temporary=False, unique=False, target_type=None, target_user=None, target_application=None, reason=None) async

Creates a new channel invite.

Parameters:

Name Type Description Default
max_age int

Max age of invite in seconds, default 86400 (24 hours).

86400
max_uses int

Max uses of invite, default 0.

0
temporary bool

Grants temporary membership, default False.

False
unique bool

Invite is unique, default false.

False
target_type Optional[InviteTargetType]

Target type for streams and embedded applications.

None
target_user Optional[Union[Snowflake_Type, User]]

Target User ID for Stream target type.

None
target_application Optional[Union[Snowflake_Type, Application]]

Target Application ID for Embedded App target type.

None
reason Optional[str]

The reason for creating this invite.

None

Returns:

Type Description
Invite

Newly created Invite object.

Source code in interactions/models/discord/channel.py
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
async def create_invite(
    self,
    max_age: int = 86400,
    max_uses: int = 0,
    temporary: bool = False,
    unique: bool = False,
    target_type: Optional[InviteTargetType] = None,
    target_user: Optional[Union[Snowflake_Type, "models.User"]] = None,
    target_application: Optional[Union[Snowflake_Type, "models.Application"]] = None,
    reason: Optional[str] = None,
) -> "models.Invite":
    """
    Creates a new channel invite.

    Args:
        max_age: Max age of invite in seconds, default 86400 (24 hours).
        max_uses: Max uses of invite, default 0.
        temporary: Grants temporary membership, default False.
        unique: Invite is unique, default false.
        target_type: Target type for streams and embedded applications.
        target_user: Target User ID for Stream target type.
        target_application: Target Application ID for Embedded App target type.
        reason: The reason for creating this invite.

    Returns:
        Newly created Invite object.

    """
    if target_type:
        if target_type == InviteTargetType.STREAM and not target_user:
            raise ValueError("Stream target must include target user id.")
        if target_type == InviteTargetType.EMBEDDED_APPLICATION and not target_application:
            raise ValueError("Embedded Application target must include target application id.")

    if target_user and target_application:
        raise ValueError("Invite target must be either User or Embedded Application, not both.")
    if target_user:
        target_user = to_snowflake(target_user)
        target_type = InviteTargetType.STREAM
    if target_application:
        target_application = to_snowflake(target_application)
        target_type = InviteTargetType.EMBEDDED_APPLICATION

    invite_data = await self._client.http.create_channel_invite(
        self.id,
        max_age,
        max_uses,
        temporary,
        unique,
        target_user_id=target_user,
        target_application_id=target_application,
        reason=reason,
    )
    return models.Invite.from_dict(invite_data, self._client)

fetch_invites() async

Fetches all invites (with invite metadata) for the channel.

Returns:

Type Description
List[Invite]

List of Invite objects.

Source code in interactions/models/discord/channel.py
546
547
548
549
550
551
552
553
554
555
async def fetch_invites(self) -> List["models.Invite"]:
    """
    Fetches all invites (with invite metadata) for the channel.

    Returns:
        List of Invite objects.

    """
    invites_data = await self._client.http.get_channel_invites(self.id)
    return models.Invite.from_list(invites_data, self._client)

MessageableMixin

Bases: SendMixin

Source code in interactions/models/discord/channel.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class MessageableMixin(SendMixin):
    last_message_id: Optional[Snowflake_Type] = attrs.field(
        repr=False, default=None
    )  # TODO May need to think of dynamically updating this.
    """The id of the last message sent in this channel (may not point to an existing or valid message)"""
    default_auto_archive_duration: int = attrs.field(repr=False, default=AutoArchiveDuration.ONE_DAY)
    """Default duration that the clients (not the API) will use for newly created threads, in minutes, to automatically archive the thread after recent activity"""
    last_pin_timestamp: Optional["models.Timestamp"] = attrs.field(
        repr=False, default=None, converter=optional_c(timestamp_converter)
    )
    """When the last pinned message was pinned. This may be None when a message is not pinned."""
    rate_limit_per_user: int = attrs.field(repr=False, default=0)
    """Amount of seconds a user has to wait before sending another message (0-21600)"""

    async def _send_http_request(
        self, message_payload: Union[dict, "FormData"], files: list["UPLOADABLE_TYPE"] | None = None
    ) -> dict:
        return await self._client.http.create_message(message_payload, self.id, files=files)

    async def fetch_message(self, message_id: Snowflake_Type, *, force: bool = False) -> Optional["models.Message"]:
        """
        Fetch a message from the channel.

        Args:
            message_id: ID of message to retrieve.
            force: Whether to force a fetch from the API.

        Returns:
            The message object fetched. If the message is not found, returns None.

        """
        try:
            return await self._client.cache.fetch_message(self.id, message_id, force=force)
        except NotFound:
            return None

    def get_message(self, message_id: Snowflake_Type) -> "models.Message":
        """
        Get a message from the channel.

        Args:
            message_id: ID of message to retrieve.

        Returns:
            The message object fetched.

        """
        message_id = to_snowflake(message_id)
        message: "models.Message" = self._client.cache.get_message(self.id, message_id)
        return message

    def history(
        self,
        limit: int = 100,
        before: Snowflake_Type = None,
        after: Snowflake_Type = None,
        around: Snowflake_Type = None,
    ) -> ChannelHistory:
        """
        Get an async iterator for the history of this channel.

        Args:
            limit: The maximum number of messages to return (set to 0 for no limit)
            before: get messages before this message ID
            after: get messages after this message ID
            around: get messages "around" this message ID

        ??? Hint "Example Usage:"
            ```python
            async for message in channel.history(limit=0):
                if message.author.id == 174918559539920897:
                    print("Found author's message")
                    # ...
                    break
            ```
            or
            ```python
            history = channel.history(limit=250)
            # Flatten the async iterator into a list
            messages = await history.flatten()
            ```

        Returns:
            ChannelHistory (AsyncIterator)

        """
        return ChannelHistory(self, limit, before, after, around)

    async def fetch_messages(
        self,
        limit: int = 50,
        around: Snowflake_Type = MISSING,
        before: Snowflake_Type = MISSING,
        after: Snowflake_Type = MISSING,
    ) -> List["models.Message"]:
        """
        Fetch multiple messages from the channel.

        Args:
            limit: Max number of messages to return, default `50`, max `100`
            around: Message to get messages around
            before: Message to get messages before
            after: Message to get messages after

        Returns:
            A list of messages fetched.

        """
        if limit > 100:
            raise ValueError("You cannot fetch more than 100 messages at once.")

        if around:
            around = to_snowflake(around)
        elif before:
            before = to_snowflake(before)
        elif after:
            after = to_snowflake(after)

        messages_data = await self._client.http.get_channel_messages(
            self.id, limit, around=around, before=before, after=after
        )
        if isinstance(self, GuildChannel):
            for m in messages_data:
                m["guild_id"] = self._guild_id

        return [self._client.cache.place_message_data(m) for m in messages_data]

    async def fetch_pinned_messages(self) -> List["models.Message"]:
        """
        Fetch pinned messages from the channel.

        Returns:
            A list of messages fetched.

        """
        messages_data = await self._client.http.get_pinned_messages(self.id)
        return [self._client.cache.place_message_data(message_data) for message_data in messages_data]

    async def delete_messages(
        self,
        messages: List[Union[Snowflake_Type, "models.Message"]],
        reason: Absent[Optional[str]] = MISSING,
    ) -> None:
        """
        Bulk delete messages from channel.

        Args:
            messages: List of messages or message IDs to delete.
            reason: The reason for this action. Used for audit logs.

        """
        message_ids = [to_snowflake(message) for message in messages]
        # TODO Add check for min/max and duplicates.

        if len(message_ids) == 1:
            # bulk delete messages will throw a http error if only 1 message is passed
            await self.delete_message(message_ids[0], reason)
        else:
            await self._client.http.bulk_delete_messages(self.id, message_ids, reason)

    async def delete_message(self, message: Union[Snowflake_Type, "models.Message"], reason: str | None = None) -> None:
        """
        Delete a single message from a channel.

        Args:
            message: The message to delete
            reason: The reason for this action

        """
        message = to_snowflake(message)
        await self._client.http.delete_message(self.id, message, reason=reason)

    async def purge(
        self,
        deletion_limit: int = 50,
        search_limit: int = 100,
        predicate: Callable[["models.Message"], bool] = MISSING,
        avoid_loading_msg: bool = True,
        return_messages: bool = False,
        before: Optional[Snowflake_Type] = MISSING,
        after: Optional[Snowflake_Type] = MISSING,
        around: Optional[Snowflake_Type] = MISSING,
        reason: Absent[Optional[str]] = MISSING,
    ) -> int | List["models.Message"]:
        """
        Bulk delete messages within a channel. If a `predicate` is provided, it will be used to determine which messages to delete, otherwise all messages will be deleted within the `deletion_limit`.

        ??? Hint "Example Usage:"
            ```python
            # this will delete the last 20 messages sent by a user with the given ID
            deleted = await channel.purge(deletion_limit=20, predicate=lambda m: m.author.id == 174918559539920897)
            await channel.send(f"{deleted} messages deleted")
            ```

        Args:
            deletion_limit: The target amount of messages to delete
            search_limit: How many messages to search through
            predicate: A function that returns True or False, and takes a message as an argument
            avoid_loading_msg: Should the bot attempt to avoid deleting its own loading messages (recommended enabled)
            return_messages: Should the bot return the messages that were deleted
            before: Search messages before this ID
            after: Search messages after this ID
            around: Search messages around this ID
            reason: The reason for this deletion

        Returns:
            The total amount of messages deleted

        """
        if not predicate:

            def predicate(m) -> bool:
                return True

        to_delete = []

        # 1209600 14 days ago in seconds, 1420070400000 is used to convert to snowflake
        fourteen_days_ago = int((time.time() - 1209600) * 1000.0 - DISCORD_EPOCH) << 22
        async for message in self.history(limit=search_limit, before=before, after=after, around=around):
            if deletion_limit != 0 and len(to_delete) == deletion_limit:
                break

            if not predicate(message):
                # fails predicate
                continue

            if (
                avoid_loading_msg
                and message._author_id == self._client.user.id
                and MessageFlags.LOADING in message.flags
            ):
                continue

            if message.id < fourteen_days_ago:
                # message is too old to be purged
                continue

            to_delete.append(message)

        out = to_delete.copy()
        while len(to_delete):
            iteration = [to_delete.pop().id for i in range(min(100, len(to_delete)))]
            await self.delete_messages(iteration, reason=reason)
        return out if return_messages else len(out)

    async def trigger_typing(self) -> None:
        """Trigger a typing animation in this channel."""
        await self._client.http.trigger_typing_indicator(self.id)

    @property
    def typing(self) -> Typing:
        """A context manager to send a typing state to a given channel as long as long as the wrapped operation takes."""
        return Typing(self)

default_auto_archive_duration: int = attrs.field(repr=False, default=AutoArchiveDuration.ONE_DAY) class-attribute

Default duration that the clients (not the API) will use for newly created threads, in minutes, to automatically archive the thread after recent activity

last_message_id: Optional[Snowflake_Type] = attrs.field(repr=False, default=None) class-attribute

The id of the last message sent in this channel (may not point to an existing or valid message)

last_pin_timestamp: Optional[models.Timestamp] = attrs.field(repr=False, default=None, converter=optional_c(timestamp_converter)) class-attribute

When the last pinned message was pinned. This may be None when a message is not pinned.

rate_limit_per_user: int = attrs.field(repr=False, default=0) class-attribute

Amount of seconds a user has to wait before sending another message (0-21600)

typing: Typing property

A context manager to send a typing state to a given channel as long as long as the wrapped operation takes.

delete_message(message, reason=None) async

Delete a single message from a channel.

Parameters:

Name Type Description Default
message Union[Snowflake_Type, Message]

The message to delete

required
reason str | None

The reason for this action

None
Source code in interactions/models/discord/channel.py
394
395
396
397
398
399
400
401
402
403
404
async def delete_message(self, message: Union[Snowflake_Type, "models.Message"], reason: str | None = None) -> None:
    """
    Delete a single message from a channel.

    Args:
        message: The message to delete
        reason: The reason for this action

    """
    message = to_snowflake(message)
    await self._client.http.delete_message(self.id, message, reason=reason)

delete_messages(messages, reason=MISSING) async

Bulk delete messages from channel.

Parameters:

Name Type Description Default
messages List[Union[Snowflake_Type, Message]]

List of messages or message IDs to delete.

required
reason Absent[Optional[str]]

The reason for this action. Used for audit logs.

MISSING
Source code in interactions/models/discord/channel.py
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
async def delete_messages(
    self,
    messages: List[Union[Snowflake_Type, "models.Message"]],
    reason: Absent[Optional[str]] = MISSING,
) -> None:
    """
    Bulk delete messages from channel.

    Args:
        messages: List of messages or message IDs to delete.
        reason: The reason for this action. Used for audit logs.

    """
    message_ids = [to_snowflake(message) for message in messages]
    # TODO Add check for min/max and duplicates.

    if len(message_ids) == 1:
        # bulk delete messages will throw a http error if only 1 message is passed
        await self.delete_message(message_ids[0], reason)
    else:
        await self._client.http.bulk_delete_messages(self.id, message_ids, reason)

fetch_message(message_id, *, force=False) async

Fetch a message from the channel.

Parameters:

Name Type Description Default
message_id Snowflake_Type

ID of message to retrieve.

required
force bool

Whether to force a fetch from the API.

False

Returns:

Type Description
Optional[Message]

The message object fetched. If the message is not found, returns None.

Source code in interactions/models/discord/channel.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
async def fetch_message(self, message_id: Snowflake_Type, *, force: bool = False) -> Optional["models.Message"]:
    """
    Fetch a message from the channel.

    Args:
        message_id: ID of message to retrieve.
        force: Whether to force a fetch from the API.

    Returns:
        The message object fetched. If the message is not found, returns None.

    """
    try:
        return await self._client.cache.fetch_message(self.id, message_id, force=force)
    except NotFound:
        return None

fetch_messages(limit=50, around=MISSING, before=MISSING, after=MISSING) async

Fetch multiple messages from the channel.

Parameters:

Name Type Description Default
limit int

Max number of messages to return, default 50, max 100

50
around Snowflake_Type

Message to get messages around

MISSING
before Snowflake_Type

Message to get messages before

MISSING
after Snowflake_Type

Message to get messages after

MISSING

Returns:

Type Description
List[Message]

A list of messages fetched.

Source code in interactions/models/discord/channel.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
async def fetch_messages(
    self,
    limit: int = 50,
    around: Snowflake_Type = MISSING,
    before: Snowflake_Type = MISSING,
    after: Snowflake_Type = MISSING,
) -> List["models.Message"]:
    """
    Fetch multiple messages from the channel.

    Args:
        limit: Max number of messages to return, default `50`, max `100`
        around: Message to get messages around
        before: Message to get messages before
        after: Message to get messages after

    Returns:
        A list of messages fetched.

    """
    if limit > 100:
        raise ValueError("You cannot fetch more than 100 messages at once.")

    if around:
        around = to_snowflake(around)
    elif before:
        before = to_snowflake(before)
    elif after:
        after = to_snowflake(after)

    messages_data = await self._client.http.get_channel_messages(
        self.id, limit, around=around, before=before, after=after
    )
    if isinstance(self, GuildChannel):
        for m in messages_data:
            m["guild_id"] = self._guild_id

    return [self._client.cache.place_message_data(m) for m in messages_data]

fetch_pinned_messages() async

Fetch pinned messages from the channel.

Returns:

Type Description
List[Message]

A list of messages fetched.

Source code in interactions/models/discord/channel.py
361
362
363
364
365
366
367
368
369
370
async def fetch_pinned_messages(self) -> List["models.Message"]:
    """
    Fetch pinned messages from the channel.

    Returns:
        A list of messages fetched.

    """
    messages_data = await self._client.http.get_pinned_messages(self.id)
    return [self._client.cache.place_message_data(message_data) for message_data in messages_data]

get_message(message_id)

Get a message from the channel.

Parameters:

Name Type Description Default
message_id Snowflake_Type

ID of message to retrieve.

required

Returns:

Type Description
Message

The message object fetched.

Source code in interactions/models/discord/channel.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def get_message(self, message_id: Snowflake_Type) -> "models.Message":
    """
    Get a message from the channel.

    Args:
        message_id: ID of message to retrieve.

    Returns:
        The message object fetched.

    """
    message_id = to_snowflake(message_id)
    message: "models.Message" = self._client.cache.get_message(self.id, message_id)
    return message

history(limit=100, before=None, after=None, around=None)

Get an async iterator for the history of this channel.

Parameters:

Name Type Description Default
limit int

The maximum number of messages to return (set to 0 for no limit)

100
before Snowflake_Type

get messages before this message ID

None
after Snowflake_Type

get messages after this message ID

None
around Snowflake_Type

get messages "around" this message ID

None
Example Usage:

1
2
3
4
5
async for message in channel.history(limit=0):
    if message.author.id == 174918559539920897:
        print("Found author's message")
        # ...
        break
or
1
2
3
history = channel.history(limit=250)
# Flatten the async iterator into a list
messages = await history.flatten()

Returns:

Type Description
ChannelHistory

ChannelHistory (AsyncIterator)

Source code in interactions/models/discord/channel.py
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
def history(
    self,
    limit: int = 100,
    before: Snowflake_Type = None,
    after: Snowflake_Type = None,
    around: Snowflake_Type = None,
) -> ChannelHistory:
    """
    Get an async iterator for the history of this channel.

    Args:
        limit: The maximum number of messages to return (set to 0 for no limit)
        before: get messages before this message ID
        after: get messages after this message ID
        around: get messages "around" this message ID

    ??? Hint "Example Usage:"
        ```python
        async for message in channel.history(limit=0):
            if message.author.id == 174918559539920897:
                print("Found author's message")
                # ...
                break
        ```
        or
        ```python
        history = channel.history(limit=250)
        # Flatten the async iterator into a list
        messages = await history.flatten()
        ```

    Returns:
        ChannelHistory (AsyncIterator)

    """
    return ChannelHistory(self, limit, before, after, around)

purge(deletion_limit=50, search_limit=100, predicate=MISSING, avoid_loading_msg=True, return_messages=False, before=MISSING, after=MISSING, around=MISSING, reason=MISSING) async

Bulk delete messages within a channel. If a predicate is provided, it will be used to determine which messages to delete, otherwise all messages will be deleted within the deletion_limit.

Example Usage:
1
2
3
# this will delete the last 20 messages sent by a user with the given ID
deleted = await channel.purge(deletion_limit=20, predicate=lambda m: m.author.id == 174918559539920897)
await channel.send(f"{deleted} messages deleted")

Parameters:

Name Type Description Default
deletion_limit int

The target amount of messages to delete

50
search_limit int

How many messages to search through

100
predicate Callable[[Message], bool]

A function that returns True or False, and takes a message as an argument

MISSING
avoid_loading_msg bool

Should the bot attempt to avoid deleting its own loading messages (recommended enabled)

True
return_messages bool

Should the bot return the messages that were deleted

False
before Optional[Snowflake_Type]

Search messages before this ID

MISSING
after Optional[Snowflake_Type]

Search messages after this ID

MISSING
around Optional[Snowflake_Type]

Search messages around this ID

MISSING
reason Absent[Optional[str]]

The reason for this deletion

MISSING

Returns:

Type Description
int | List[Message]

The total amount of messages deleted

Source code in interactions/models/discord/channel.py
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
async def purge(
    self,
    deletion_limit: int = 50,
    search_limit: int = 100,
    predicate: Callable[["models.Message"], bool] = MISSING,
    avoid_loading_msg: bool = True,
    return_messages: bool = False,
    before: Optional[Snowflake_Type] = MISSING,
    after: Optional[Snowflake_Type] = MISSING,
    around: Optional[Snowflake_Type] = MISSING,
    reason: Absent[Optional[str]] = MISSING,
) -> int | List["models.Message"]:
    """
    Bulk delete messages within a channel. If a `predicate` is provided, it will be used to determine which messages to delete, otherwise all messages will be deleted within the `deletion_limit`.

    ??? Hint "Example Usage:"
        ```python
        # this will delete the last 20 messages sent by a user with the given ID
        deleted = await channel.purge(deletion_limit=20, predicate=lambda m: m.author.id == 174918559539920897)
        await channel.send(f"{deleted} messages deleted")
        ```

    Args:
        deletion_limit: The target amount of messages to delete
        search_limit: How many messages to search through
        predicate: A function that returns True or False, and takes a message as an argument
        avoid_loading_msg: Should the bot attempt to avoid deleting its own loading messages (recommended enabled)
        return_messages: Should the bot return the messages that were deleted
        before: Search messages before this ID
        after: Search messages after this ID
        around: Search messages around this ID
        reason: The reason for this deletion

    Returns:
        The total amount of messages deleted

    """
    if not predicate:

        def predicate(m) -> bool:
            return True

    to_delete = []

    # 1209600 14 days ago in seconds, 1420070400000 is used to convert to snowflake
    fourteen_days_ago = int((time.time() - 1209600) * 1000.0 - DISCORD_EPOCH) << 22
    async for message in self.history(limit=search_limit, before=before, after=after, around=around):
        if deletion_limit != 0 and len(to_delete) == deletion_limit:
            break

        if not predicate(message):
            # fails predicate
            continue

        if (
            avoid_loading_msg
            and message._author_id == self._client.user.id
            and MessageFlags.LOADING in message.flags
        ):
            continue

        if message.id < fourteen_days_ago:
            # message is too old to be purged
            continue

        to_delete.append(message)

    out = to_delete.copy()
    while len(to_delete):
        iteration = [to_delete.pop().id for i in range(min(100, len(to_delete)))]
        await self.delete_messages(iteration, reason=reason)
    return out if return_messages else len(out)

trigger_typing() async

Trigger a typing animation in this channel.

Source code in interactions/models/discord/channel.py
479
480
481
async def trigger_typing(self) -> None:
    """Trigger a typing animation in this channel."""
    await self._client.http.trigger_typing_indicator(self.id)

PermissionOverwrite

Bases: SnowflakeObject, DictSerializationMixin

Channel Permissions Overwrite object.

Note

id here is not an attribute of the overwrite, it is the ID of the overwritten instance

Source code in interactions/models/discord/channel.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class PermissionOverwrite(SnowflakeObject, DictSerializationMixin):
    """
    Channel Permissions Overwrite object.

    !!! note
        `id` here is not an attribute of the overwrite, it is the ID of the overwritten instance

    """

    type: "OverwriteType" = attrs.field(repr=True, converter=OverwriteType)
    """Permission overwrite type (role or member)"""
    allow: Optional["Permissions"] = attrs.field(
        repr=True, converter=optional_c(Permissions), kw_only=True, default=None
    )
    """Permissions to allow"""
    deny: Optional["Permissions"] = attrs.field(
        repr=True, converter=optional_c(Permissions), kw_only=True, default=None
    )
    """Permissions to deny"""

    @classmethod
    def for_target(cls, target_type: Union["models.Role", "models.Member", "models.User"]) -> "PermissionOverwrite":
        """
        Create a PermissionOverwrite for a role or member.

        Args:
            target_type: The type of the target (role or member)

        Returns:
            PermissionOverwrite

        """
        if isinstance(target_type, models.Role):
            return cls(type=OverwriteType.ROLE, id=target_type.id)
        if isinstance(target_type, (models.Member, models.User)):
            return cls(type=OverwriteType.MEMBER, id=target_type.id)
        raise TypeError("target_type must be a Role, Member or User")

    def add_allows(self, *perms: "Permissions") -> None:
        """
        Add permissions to allow.

        Args:
            *perms: Permissions to add

        """
        if not self.allow:
            self.allow = Permissions.NONE
        for perm in perms:
            self.allow |= perm

    def add_denies(self, *perms: "Permissions") -> None:
        """
        Add permissions to deny.

        Args:
            *perms: Permissions to add

        """
        if not self.deny:
            self.deny = Permissions.NONE
        for perm in perms:
            self.deny |= perm

allow: Optional[Permissions] = attrs.field(repr=True, converter=optional_c(Permissions), kw_only=True, default=None) class-attribute

Permissions to allow

deny: Optional[Permissions] = attrs.field(repr=True, converter=optional_c(Permissions), kw_only=True, default=None) class-attribute

Permissions to deny

type: OverwriteType = attrs.field(repr=True, converter=OverwriteType) class-attribute

Permission overwrite type (role or member)

add_allows(*perms)

Add permissions to allow.

Parameters:

Name Type Description Default
*perms Permissions

Permissions to add

()
Source code in interactions/models/discord/channel.py
206
207
208
209
210
211
212
213
214
215
216
217
def add_allows(self, *perms: "Permissions") -> None:
    """
    Add permissions to allow.

    Args:
        *perms: Permissions to add

    """
    if not self.allow:
        self.allow = Permissions.NONE
    for perm in perms:
        self.allow |= perm

add_denies(*perms)

Add permissions to deny.

Parameters:

Name Type Description Default
*perms Permissions

Permissions to add

()
Source code in interactions/models/discord/channel.py
219
220
221
222
223
224
225
226
227
228
229
230
def add_denies(self, *perms: "Permissions") -> None:
    """
    Add permissions to deny.

    Args:
        *perms: Permissions to add

    """
    if not self.deny:
        self.deny = Permissions.NONE
    for perm in perms:
        self.deny |= perm

for_target(target_type) classmethod

Create a PermissionOverwrite for a role or member.

Parameters:

Name Type Description Default
target_type Union[Role, Member, User]

The type of the target (role or member)

required

Returns:

Type Description
PermissionOverwrite

PermissionOverwrite

Source code in interactions/models/discord/channel.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@classmethod
def for_target(cls, target_type: Union["models.Role", "models.Member", "models.User"]) -> "PermissionOverwrite":
    """
    Create a PermissionOverwrite for a role or member.

    Args:
        target_type: The type of the target (role or member)

    Returns:
        PermissionOverwrite

    """
    if isinstance(target_type, models.Role):
        return cls(type=OverwriteType.ROLE, id=target_type.id)
    if isinstance(target_type, (models.Member, models.User)):
        return cls(type=OverwriteType.MEMBER, id=target_type.id)
    raise TypeError("target_type must be a Role, Member or User")

ThreadChannel

Bases: BaseChannel, MessageableMixin, WebhookMixin

Source code in interactions/models/discord/channel.py
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class ThreadChannel(BaseChannel, MessageableMixin, WebhookMixin):
    parent_id: Snowflake_Type = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake))
    """id of the text channel this thread was created"""
    owner_id: Snowflake_Type = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake))
    """id of the creator of the thread"""
    topic: Optional[str] = attrs.field(repr=False, default=None)
    """The thread topic (0-1024 characters)"""
    message_count: int = attrs.field(repr=False, default=0)
    """An approximate count of messages in a thread, stops counting at 50"""
    member_count: int = attrs.field(repr=False, default=0)
    """An approximate count of users in a thread, stops counting at 50"""
    archived: bool = attrs.field(repr=False, default=False)
    """Whether the thread is archived"""
    auto_archive_duration: int = attrs.field(
        repr=False,
        default=attrs.Factory(lambda self: self.default_auto_archive_duration, takes_self=True),
    )
    """Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080"""
    locked: bool = attrs.field(repr=False, default=False)
    """Whether the thread is locked"""
    archive_timestamp: Optional["models.Timestamp"] = attrs.field(
        repr=False, default=None, converter=optional_c(timestamp_converter)
    )
    """Timestamp when the thread's archive status was last changed, used for calculating recent activity"""
    create_timestamp: Optional["models.Timestamp"] = attrs.field(
        repr=False, default=None, converter=optional_c(timestamp_converter)
    )
    """Timestamp when the thread was created"""
    flags: ChannelFlags = attrs.field(repr=False, default=ChannelFlags.NONE, converter=ChannelFlags)
    """Flags for the thread"""

    _guild_id: Snowflake_Type = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake))

    @classmethod
    def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]:
        data = super()._process_dict(data, client)
        thread_metadata: dict = data.get("thread_metadata", {})
        data.update(thread_metadata)
        return data

    @property
    def is_private(self) -> bool:
        """Is this a private thread?"""
        return self.type == ChannelType.GUILD_PRIVATE_THREAD

    @property
    def guild(self) -> "models.Guild":
        """The guild this channel belongs to."""
        return self._client.cache.get_guild(self._guild_id)

    @property
    def parent_channel(self) -> Union[GuildText, "GuildForum"]:
        """The channel this thread is a child of."""
        return self._client.cache.get_channel(self.parent_id)

    @property
    def parent_message(self) -> Optional["Message"]:
        """The message this thread is a child of."""
        return self._client.cache.get_message(self.parent_id, self.id)

    @property
    def mention(self) -> str:
        """Returns a string that would mention this thread."""
        return f"<#{self.id}>"

    @property
    def permission_overwrites(self) -> List["PermissionOverwrite"]:
        """The permission overwrites for this channel."""
        return []

    @property
    def clyde_created(self) -> bool:
        """Whether this thread was created by Clyde."""
        return ChannelFlags.CLYDE_THREAD in self.flags

    def permissions_for(self, instance: Snowflake_Type) -> Permissions:
        """
        Calculates permissions for an instance

        Args:
            instance: Member or Role instance (or its ID)

        Returns:
            Permissions data

        Raises:
            ValueError: If could not find any member or role by given ID
            RuntimeError: If given instance is from another guild

        """
        if self.parent_channel:
            return self.parent_channel.permissions_for(instance)
        return Permissions.NONE

    async def fetch_members(self) -> List["models.ThreadMember"]:
        """Get the members that have access to this thread."""
        members_data = await self._client.http.list_thread_members(self.id)
        return models.ThreadMember.from_list(members_data, self._client)

    async def add_member(self, member: Union["models.Member", Snowflake_Type]) -> None:
        """
        Add a member to this thread.

        Args:
            member: The member to add

        """
        await self._client.http.add_thread_member(self.id, to_snowflake(member))

    async def remove_member(self, member: Union["models.Member", Snowflake_Type]) -> None:
        """
        Remove a member from this thread.

        Args:
            member: The member to remove

        """
        await self._client.http.remove_thread_member(self.id, to_snowflake(member))

    async def join(self) -> None:
        """Join this thread."""
        await self._client.http.join_thread(self.id)

    async def leave(self) -> None:
        """Leave this thread."""
        await self._client.http.leave_thread(self.id)

    async def archive(self, locked: bool = False, reason: Absent[str] = MISSING) -> "TYPE_THREAD_CHANNEL":
        """
        Helper method to archive this thread.

        Args:
            locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
            reason: The reason for this archive

        Returns:
            The archived thread channel object.

        """
        return await super().edit(locked=locked, archived=True, reason=reason)

archive_timestamp: Optional[models.Timestamp] = attrs.field(repr=False, default=None, converter=optional_c(timestamp_converter)) class-attribute

Timestamp when the thread's archive status was last changed, used for calculating recent activity

archived: bool = attrs.field(repr=False, default=False) class-attribute

Whether the thread is archived

auto_archive_duration: int = attrs.field(repr=False, default=attrs.Factory(lambda self: self.default_auto_archive_duration, takes_self=True)) class-attribute

Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080

clyde_created: bool property

Whether this thread was created by Clyde.

create_timestamp: Optional[models.Timestamp] = attrs.field(repr=False, default=None, converter=optional_c(timestamp_converter)) class-attribute

Timestamp when the thread was created

flags: ChannelFlags = attrs.field(repr=False, default=ChannelFlags.NONE, converter=ChannelFlags) class-attribute

Flags for the thread

guild: models.Guild property

The guild this channel belongs to.

is_private: bool property

Is this a private thread?

locked: bool = attrs.field(repr=False, default=False) class-attribute

Whether the thread is locked

member_count: int = attrs.field(repr=False, default=0) class-attribute

An approximate count of users in a thread, stops counting at 50

mention: str property

Returns a string that would mention this thread.

message_count: int = attrs.field(repr=False, default=0) class-attribute

An approximate count of messages in a thread, stops counting at 50

owner_id: Snowflake_Type = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake)) class-attribute

id of the creator of the thread

parent_channel: Union[GuildText, GuildForum] property

The channel this thread is a child of.

parent_id: Snowflake_Type = attrs.field(repr=False, default=None, converter=optional_c(to_snowflake)) class-attribute

id of the text channel this thread was created

parent_message: Optional[Message] property

The message this thread is a child of.

permission_overwrites: List[PermissionOverwrite] property

The permission overwrites for this channel.

topic: Optional[str] = attrs.field(repr=False, default=None) class-attribute

The thread topic (0-1024 characters)

add_member(member) async

Add a member to this thread.

Parameters:

Name Type Description Default
member Union[Member, Snowflake_Type]

The member to add

required
Source code in interactions/models/discord/channel.py
1947
1948
1949
1950
1951
1952
1953
1954
1955
async def add_member(self, member: Union["models.Member", Snowflake_Type]) -> None:
    """
    Add a member to this thread.

    Args:
        member: The member to add

    """
    await self._client.http.add_thread_member(self.id, to_snowflake(member))

archive(locked=False, reason=MISSING) async

Helper method to archive this thread.

Parameters:

Name Type Description Default
locked bool

whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it

False
reason Absent[str]

The reason for this archive

MISSING

Returns:

Type Description
TYPE_THREAD_CHANNEL

The archived thread channel object.

Source code in interactions/models/discord/channel.py
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
async def archive(self, locked: bool = False, reason: Absent[str] = MISSING) -> "TYPE_THREAD_CHANNEL":
    """
    Helper method to archive this thread.

    Args:
        locked: whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
        reason: The reason for this archive

    Returns:
        The archived thread channel object.

    """
    return await super().edit(locked=locked, archived=True, reason=reason)

fetch_members() async

Get the members that have access to this thread.

Source code in interactions/models/discord/channel.py
1942
1943
1944
1945
async def fetch_members(self) -> List["models.ThreadMember"]:
    """Get the members that have access to this thread."""
    members_data = await self._client.http.list_thread_members(self.id)
    return models.ThreadMember.from_list(members_data, self._client)

join() async

Join this thread.

Source code in interactions/models/discord/channel.py
1967
1968
1969
async def join(self) -> None:
    """Join this thread."""
    await self._client.http.join_thread(self.id)

leave() async

Leave this thread.

Source code in interactions/models/discord/channel.py
1971
1972
1973
async def leave(self) -> None:
    """Leave this thread."""
    await self._client.http.leave_thread(self.id)

permissions_for(instance)

Calculates permissions for an instance

Parameters:

Name Type Description Default
instance Snowflake_Type

Member or Role instance (or its ID)

required

Returns:

Type Description
Permissions

Permissions data

Raises:

Type Description
ValueError

If could not find any member or role by given ID

RuntimeError

If given instance is from another guild

Source code in interactions/models/discord/channel.py
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
def permissions_for(self, instance: Snowflake_Type) -> Permissions:
    """
    Calculates permissions for an instance

    Args:
        instance: Member or Role instance (or its ID)

    Returns:
        Permissions data

    Raises:
        ValueError: If could not find any member or role by given ID
        RuntimeError: If given instance is from another guild

    """
    if self.parent_channel:
        return self.parent_channel.permissions_for(instance)
    return Permissions.NONE

remove_member(member) async

Remove a member from this thread.

Parameters:

Name Type Description Default
member Union[Member, Snowflake_Type]

The member to remove

required
Source code in interactions/models/discord/channel.py
1957
1958
1959
1960
1961
1962
1963
1964
1965
async def remove_member(self, member: Union["models.Member", Snowflake_Type]) -> None:
    """
    Remove a member from this thread.

    Args:
        member: The member to remove

    """
    await self._client.http.remove_thread_member(self.id, to_snowflake(member))

ThreadableMixin

Source code in interactions/models/discord/channel.py
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class ThreadableMixin:
    async def create_thread(
        self,
        name: str,
        message: Absent[Snowflake_Type] = MISSING,
        thread_type: Absent[ChannelType] = MISSING,
        invitable: Absent[bool] = MISSING,
        rate_limit_per_user: Absent[int] = MISSING,
        auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
        reason: Absent[str] | None = None,
    ) -> "TYPE_THREAD_CHANNEL":
        """
        Creates a new thread in this channel. If a message is provided, it will be used as the initial message.

        Args:
            name: 1-100 character thread name
            message: The message to connect this thread to. Required for news channel.
            thread_type: Is the thread private or public. Not applicable to news channel, it will always be GUILD_NEWS_THREAD.
            invitable: whether non-moderators can add other non-moderators to a thread. Only applicable when creating a private thread.
            rate_limit_per_user: The time users must wait between sending messages (0-21600).
            auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
            reason: The reason for creating this thread.

        Returns:
            The created thread, if successful

        """
        if self.type == ChannelType.GUILD_NEWS and not message:
            raise ValueError("News channel must include message to create thread from.")

        if message and (thread_type or invitable):
            raise ValueError("Message cannot be used with thread_type or invitable.")

        if thread_type != ChannelType.GUILD_PRIVATE_THREAD and invitable:
            raise ValueError("Invitable only applies to private threads.")

        thread_data = await self._client.http.create_thread(
            channel_id=self.id,
            name=name,
            thread_type=thread_type,
            invitable=invitable,
            rate_limit_per_user=rate_limit_per_user,
            auto_archive_duration=auto_archive_duration,
            message_id=to_optional_snowflake(message),
            reason=reason,
        )
        return self._client.cache.place_channel_data(thread_data)

    async def fetch_public_archived_threads(
        self, limit: int | None = None, before: Optional["models.Timestamp"] = None
    ) -> "models.ThreadList":
        """
        Get a `ThreadList` of archived **public** threads available in this channel.

        Args:
            limit: optional maximum number of threads to return
            before: Returns threads before this timestamp

        Returns:
            A `ThreadList` of archived threads.

        """
        threads_data = await self._client.http.list_public_archived_threads(
            channel_id=self.id, limit=limit, before=before
        )
        threads_data["id"] = self.id
        return models.ThreadList.from_dict(threads_data, self._client)

    async def fetch_private_archived_threads(
        self, limit: int | None = None, before: Optional["models.Timestamp"] = None
    ) -> "models.ThreadList":
        """
        Get a `ThreadList` of archived **private** threads available in this channel.

        Args:
            limit: optional maximum number of threads to return
            before: Returns threads before this timestamp

        Returns:
            A `ThreadList` of archived threads.

        """
        threads_data = await self._client.http.list_private_archived_threads(
            channel_id=self.id, limit=limit, before=before
        )
        threads_data["id"] = self.id
        return models.ThreadList.from_dict(threads_data, self._client)

    async def fetch_archived_threads(
        self, limit: int | None = None, before: Optional["models.Timestamp"] = None
    ) -> "models.ThreadList":
        """
        Get a `ThreadList` of archived threads available in this channel.

        Args:
            limit: optional maximum number of threads to return
            before: Returns threads before this timestamp

        Returns:
            A `ThreadList` of archived threads.

        """
        threads_data = await self._client.http.list_private_archived_threads(
            channel_id=self.id, limit=limit, before=before
        )
        threads_data.update(
            await self._client.http.list_public_archived_threads(channel_id=self.id, limit=limit, before=before)
        )
        threads_data["id"] = self.id
        return models.ThreadList.from_dict(threads_data, self._client)

    async def fetch_joined_private_archived_threads(
        self, limit: int | None = None, before: Optional["models.Timestamp"] = None
    ) -> "models.ThreadList":
        """
        Get a `ThreadList` of threads the bot is a participant of in this channel.

        Args:
            limit: optional maximum number of threads to return
            before: Returns threads before this timestamp

        Returns:
            A `ThreadList` of threads the bot is a participant of.

        """
        threads_data = await self._client.http.list_joined_private_archived_threads(
            channel_id=self.id, limit=limit, before=before
        )
        threads_data["id"] = self.id
        return models.ThreadList.from_dict(threads_data, self._client)

    async def fetch_active_threads(self) -> "models.ThreadList":
        """
        Gets all active threads in the channel, including public and private threads.

        Returns:
            A `ThreadList` of active threads.

        """
        threads_data = await self._client.http.list_active_threads(guild_id=self._guild_id)

        # delete the items where the channel_id does not match
        removed_thread_ids = []
        cleaned_threads_data_threads = []
        for thread in threads_data["threads"]:
            if thread["parent_id"] == str(self.id):
                cleaned_threads_data_threads.append(thread)
            else:
                removed_thread_ids.append(thread["id"])
        threads_data["threads"] = cleaned_threads_data_threads

        cleaned_member_data_threads = [
            thread_member for thread_member in threads_data["members"] if thread_member["id"] not in removed_thread_ids
        ]
        threads_data["members"] = cleaned_member_data_threads

        return models.ThreadList.from_dict(threads_data, self._client)

    async def fetch_all_threads(self) -> "models.ThreadList":
        """
        Gets all threads in the channel. Active and archived, including public and private threads.

        Returns:
            A `ThreadList` of all threads.

        """
        threads = await self.fetch_active_threads()

        # update that data with the archived threads
        archived_threads = await self.fetch_archived_threads()
        threads.threads.extend(archived_threads.threads)
        threads.members.extend(archived_threads.members)

        return threads

create_thread(name, message=MISSING, thread_type=MISSING, invitable=MISSING, rate_limit_per_user=MISSING, auto_archive_duration=AutoArchiveDuration.ONE_DAY, reason=None) async

Creates a new thread in this channel. If a message is provided, it will be used as the initial message.

Parameters:

Name Type Description Default
name str

1-100 character thread name

required
message Absent[Snowflake_Type]

The message to connect this thread to. Required for news channel.

MISSING
thread_type Absent[ChannelType]

Is the thread private or public. Not applicable to news channel, it will always be GUILD_NEWS_THREAD.

MISSING
invitable Absent[bool]

whether non-moderators can add other non-moderators to a thread. Only applicable when creating a private thread.

MISSING
rate_limit_per_user Absent[int]

The time users must wait between sending messages (0-21600).

MISSING
auto_archive_duration AutoArchiveDuration

Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.

AutoArchiveDuration.ONE_DAY
reason Absent[str] | None

The reason for creating this thread.

None

Returns:

Type Description
TYPE_THREAD_CHANNEL

The created thread, if successful

Source code in interactions/models/discord/channel.py
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
async def create_thread(
    self,
    name: str,
    message: Absent[Snowflake_Type] = MISSING,
    thread_type: Absent[ChannelType] = MISSING,
    invitable: Absent[bool] = MISSING,
    rate_limit_per_user: Absent[int] = MISSING,
    auto_archive_duration: AutoArchiveDuration = AutoArchiveDuration.ONE_DAY,
    reason: Absent[str] | None = None,
) -> "TYPE_THREAD_CHANNEL":
    """
    Creates a new thread in this channel. If a message is provided, it will be used as the initial message.

    Args:
        name: 1-100 character thread name
        message: The message to connect this thread to. Required for news channel.
        thread_type: Is the thread private or public. Not applicable to news channel, it will always be GUILD_NEWS_THREAD.
        invitable: whether non-moderators can add other non-moderators to a thread. Only applicable when creating a private thread.
        rate_limit_per_user: The time users must wait between sending messages (0-21600).
        auto_archive_duration: Time before the thread will be automatically archived. Note 3 day and 7 day archive durations require the server to be boosted.
        reason: The reason for creating this thread.

    Returns:
        The created thread, if successful

    """
    if self.type == ChannelType.GUILD_NEWS and not message:
        raise ValueError("News channel must include message to create thread from.")

    if message and (thread_type or invitable):
        raise ValueError("Message cannot be used with thread_type or invitable.")

    if thread_type != ChannelType.GUILD_PRIVATE_THREAD and invitable:
        raise ValueError("Invitable only applies to private threads.")

    thread_data = await self._client.http.create_thread(
        channel_id=self.id,
        name=name,
        thread_type=thread_type,
        invitable=invitable,
        rate_limit_per_user=rate_limit_per_user,
        auto_archive_duration=auto_archive_duration,
        message_id=to_optional_snowflake(message),
        reason=reason,
    )
    return self._client.cache.place_channel_data(thread_data)

fetch_active_threads() async

Gets all active threads in the channel, including public and private threads.

Returns:

Type Description
ThreadList

A ThreadList of active threads.

Source code in interactions/models/discord/channel.py
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
async def fetch_active_threads(self) -> "models.ThreadList":
    """
    Gets all active threads in the channel, including public and private threads.

    Returns:
        A `ThreadList` of active threads.

    """
    threads_data = await self._client.http.list_active_threads(guild_id=self._guild_id)

    # delete the items where the channel_id does not match
    removed_thread_ids = []
    cleaned_threads_data_threads = []
    for thread in threads_data["threads"]:
        if thread["parent_id"] == str(self.id):
            cleaned_threads_data_threads.append(thread)
        else:
            removed_thread_ids.append(thread["id"])
    threads_data["threads"] = cleaned_threads_data_threads

    cleaned_member_data_threads = [
        thread_member for thread_member in threads_data["members"] if thread_member["id"] not in removed_thread_ids
    ]
    threads_data["members"] = cleaned_member_data_threads

    return models.ThreadList.from_dict(threads_data, self._client)

fetch_all_threads() async

Gets all threads in the channel. Active and archived, including public and private threads.

Returns:

Type Description
ThreadList

A ThreadList of all threads.

Source code in interactions/models/discord/channel.py
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
async def fetch_all_threads(self) -> "models.ThreadList":
    """
    Gets all threads in the channel. Active and archived, including public and private threads.

    Returns:
        A `ThreadList` of all threads.

    """
    threads = await self.fetch_active_threads()

    # update that data with the archived threads
    archived_threads = await self.fetch_archived_threads()
    threads.threads.extend(archived_threads.threads)
    threads.members.extend(archived_threads.members)

    return threads

fetch_archived_threads(limit=None, before=None) async

Get a ThreadList of archived threads available in this channel.

Parameters:

Name Type Description Default
limit int | None

optional maximum number of threads to return

None
before Optional[Timestamp]

Returns threads before this timestamp

None

Returns:

Type Description
ThreadList

A ThreadList of archived threads.

Source code in interactions/models/discord/channel.py
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
async def fetch_archived_threads(
    self, limit: int | None = None, before: Optional["models.Timestamp"] = None
) -> "models.ThreadList":
    """
    Get a `ThreadList` of archived threads available in this channel.

    Args:
        limit: optional maximum number of threads to return
        before: Returns threads before this timestamp

    Returns:
        A `ThreadList` of archived threads.

    """
    threads_data = await self._client.http.list_private_archived_threads(
        channel_id=self.id, limit=limit, before=before
    )
    threads_data.update(
        await self._client.http.list_public_archived_threads(channel_id=self.id, limit=limit, before=before)
    )
    threads_data["id"] = self.id
    return models.ThreadList.from_dict(threads_data, self._client)

fetch_joined_private_archived_threads(limit=None, before=None) async

Get a ThreadList of threads the bot is a participant of in this channel.

Parameters:

Name Type Description Default
limit int | None

optional maximum number of threads to return

None
before Optional[Timestamp]

Returns threads before this timestamp

None

Returns:

Type Description
ThreadList

A ThreadList of threads the bot is a participant of.

Source code in interactions/models/discord/channel.py
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
async def fetch_joined_private_archived_threads(
    self, limit: int | None = None, before: Optional["models.Timestamp"] = None
) -> "models.ThreadList":
    """
    Get a `ThreadList` of threads the bot is a participant of in this channel.

    Args:
        limit: optional maximum number of threads to return
        before: Returns threads before this timestamp

    Returns:
        A `ThreadList` of threads the bot is a participant of.

    """
    threads_data = await self._client.http.list_joined_private_archived_threads(
        channel_id=self.id, limit=limit, before=before
    )
    threads_data["id"] = self.id
    return models.ThreadList.from_dict(threads_data, self._client)

fetch_private_archived_threads(limit=None, before=None) async

Get a ThreadList of archived private threads available in this channel.

Parameters:

Name Type Description Default
limit int | None

optional maximum number of threads to return

None
before Optional[Timestamp]

Returns threads before this timestamp

None

Returns:

Type Description
ThreadList

A ThreadList of archived threads.

Source code in interactions/models/discord/channel.py
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
async def fetch_private_archived_threads(
    self, limit: int | None = None, before: Optional["models.Timestamp"] = None
) -> "models.ThreadList":
    """
    Get a `ThreadList` of archived **private** threads available in this channel.

    Args:
        limit: optional maximum number of threads to return
        before: Returns threads before this timestamp

    Returns:
        A `ThreadList` of archived threads.

    """
    threads_data = await self._client.http.list_private_archived_threads(
        channel_id=self.id, limit=limit, before=before
    )
    threads_data["id"] = self.id
    return models.ThreadList.from_dict(threads_data, self._client)

fetch_public_archived_threads(limit=None, before=None) async

Get a ThreadList of archived public threads available in this channel.

Parameters:

Name Type Description Default
limit int | None

optional maximum number of threads to return

None
before Optional[Timestamp]

Returns threads before this timestamp

None

Returns:

Type Description
ThreadList

A ThreadList of archived threads.

Source code in interactions/models/discord/channel.py
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
async def fetch_public_archived_threads(
    self, limit: int | None = None, before: Optional["models.Timestamp"] = None
) -> "models.ThreadList":
    """
    Get a `ThreadList` of archived **public** threads available in this channel.

    Args:
        limit: optional maximum number of threads to return
        before: Returns threads before this timestamp

    Returns:
        A `ThreadList` of archived threads.

    """
    threads_data = await self._client.http.list_public_archived_threads(
        channel_id=self.id, limit=limit, before=before
    )
    threads_data["id"] = self.id
    return models.ThreadList.from_dict(threads_data, self._client)

VoiceChannel

Bases: GuildChannel

Source code in interactions/models/discord/channel.py
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class VoiceChannel(GuildChannel):  # May not be needed, can be directly just GuildVoice.
    bitrate: int = attrs.field(
        repr=False,
    )
    """The bitrate (in bits) of the voice channel"""
    user_limit: int = attrs.field(
        repr=False,
    )
    """The user limit of the voice channel"""
    rtc_region: str = attrs.field(repr=False, default="auto")
    """Voice region id for the voice channel, automatic when set to None"""
    video_quality_mode: Union[VideoQualityMode, int] = attrs.field(repr=False, default=VideoQualityMode.AUTO)
    """The camera video quality mode of the voice channel, 1 when not present"""
    _voice_member_ids: list[Snowflake_Type] = attrs.field(repr=False, factory=list)

    async def edit(
        self,
        *,
        name: Absent[str] = MISSING,
        position: Absent[int] = MISSING,
        permission_overwrites: Absent[
            Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
        ] = MISSING,
        parent_id: Absent[Snowflake_Type] = MISSING,
        bitrate: Absent[int] = MISSING,
        user_limit: Absent[int] = MISSING,
        rtc_region: Absent[str] = MISSING,
        video_quality_mode: Absent[VideoQualityMode] = MISSING,
        reason: Absent[str] = MISSING,
        **kwargs,
    ) -> Union["GuildVoice", "GuildStageVoice"]:
        """
        Edit guild voice channel.

        Args:
            name: 1-100 character channel name
            position: the position of the channel in the left-hand listing
            permission_overwrites: a list of `PermissionOverwrite` to apply to the channel
            parent_id: the parent category `Snowflake_Type` for the channel
            bitrate: the bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers)
            user_limit: the user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit
            rtc_region: channel voice region id, automatic when not set
            video_quality_mode: the camera video quality mode of the voice channel
            reason: optional reason for audit logs

        Returns:
            The edited voice channel object.

        """
        return await super().edit(
            name=name,
            position=position,
            permission_overwrites=permission_overwrites,
            parent_id=parent_id,
            bitrate=bitrate,
            user_limit=user_limit,
            rtc_region=rtc_region,
            video_quality_mode=video_quality_mode,
            reason=reason,
            **kwargs,
        )

    @property
    def members(self) -> List["models.Member"]:
        """Returns a list of members that have access to this voice channel"""
        return [m for m in self.guild.members if Permissions.CONNECT in m.channel_permissions(self)]  # type: ignore

    @property
    def voice_members(self) -> List["models.Member"]:
        """
        Returns a list of members that are currently in the channel.

        !!! note
            This will not be accurate if the bot was offline while users joined the channel
        """
        return [self._client.cache.get_member(self._guild_id, member_id) for member_id in self._voice_member_ids]

    @property
    def voice_state(self) -> Optional["ActiveVoiceState"]:
        """Returns the voice state of the bot in this channel if it is connected"""
        return self._client.get_bot_voice_state(self._guild_id)

    async def connect(self, muted: bool = False, deafened: bool = False) -> "ActiveVoiceState":
        """
        Connect the bot to this voice channel, or move the bot to this voice channel if it is already connected in another voice channel.

        Args:
            muted: Whether the bot should be muted when connected.
            deafened: Whether the bot should be deafened when connected.

        Returns:
            The new active voice state on successfully connection.

        """
        if not self.voice_state:
            return await self._client.connect_to_vc(self._guild_id, self.id, muted, deafened)
        await self.voice_state.move(self.id)
        return self.voice_state

    async def disconnect(self) -> None:
        """
        Disconnect from the currently connected voice state.

        Raises:
            VoiceNotConnected: if the bot is not connected to a voice channel

        """
        if self.voice_state:
            return await self.voice_state.disconnect()
        raise VoiceNotConnected

bitrate: int = attrs.field(repr=False) class-attribute

The bitrate (in bits) of the voice channel

members: List[models.Member] property

Returns a list of members that have access to this voice channel

rtc_region: str = attrs.field(repr=False, default='auto') class-attribute

Voice region id for the voice channel, automatic when set to None

user_limit: int = attrs.field(repr=False) class-attribute

The user limit of the voice channel

video_quality_mode: Union[VideoQualityMode, int] = attrs.field(repr=False, default=VideoQualityMode.AUTO) class-attribute

The camera video quality mode of the voice channel, 1 when not present

voice_members: List[models.Member] property

Returns a list of members that are currently in the channel.

Note

This will not be accurate if the bot was offline while users joined the channel

voice_state: Optional[ActiveVoiceState] property

Returns the voice state of the bot in this channel if it is connected

connect(muted=False, deafened=False) async

Connect the bot to this voice channel, or move the bot to this voice channel if it is already connected in another voice channel.

Parameters:

Name Type Description Default
muted bool

Whether the bot should be muted when connected.

False
deafened bool

Whether the bot should be deafened when connected.

False

Returns:

Type Description
ActiveVoiceState

The new active voice state on successfully connection.

Source code in interactions/models/discord/channel.py
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
async def connect(self, muted: bool = False, deafened: bool = False) -> "ActiveVoiceState":
    """
    Connect the bot to this voice channel, or move the bot to this voice channel if it is already connected in another voice channel.

    Args:
        muted: Whether the bot should be muted when connected.
        deafened: Whether the bot should be deafened when connected.

    Returns:
        The new active voice state on successfully connection.

    """
    if not self.voice_state:
        return await self._client.connect_to_vc(self._guild_id, self.id, muted, deafened)
    await self.voice_state.move(self.id)
    return self.voice_state

disconnect() async

Disconnect from the currently connected voice state.

Raises:

Type Description
VoiceNotConnected

if the bot is not connected to a voice channel

Source code in interactions/models/discord/channel.py
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
async def disconnect(self) -> None:
    """
    Disconnect from the currently connected voice state.

    Raises:
        VoiceNotConnected: if the bot is not connected to a voice channel

    """
    if self.voice_state:
        return await self.voice_state.disconnect()
    raise VoiceNotConnected

edit(*, name=MISSING, position=MISSING, permission_overwrites=MISSING, parent_id=MISSING, bitrate=MISSING, user_limit=MISSING, rtc_region=MISSING, video_quality_mode=MISSING, reason=MISSING, **kwargs) async

Edit guild voice channel.

Parameters:

Name Type Description Default
name Absent[str]

1-100 character channel name

MISSING
position Absent[int]

the position of the channel in the left-hand listing

MISSING
permission_overwrites Absent[Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]]

a list of PermissionOverwrite to apply to the channel

MISSING
parent_id Absent[Snowflake_Type]

the parent category Snowflake_Type for the channel

MISSING
bitrate Absent[int]

the bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers)

MISSING
user_limit Absent[int]

the user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit

MISSING
rtc_region Absent[str]

channel voice region id, automatic when not set

MISSING
video_quality_mode Absent[VideoQualityMode]

the camera video quality mode of the voice channel

MISSING
reason Absent[str]

optional reason for audit logs

MISSING

Returns:

Type Description
Union[GuildVoice, GuildStageVoice]

The edited voice channel object.

Source code in interactions/models/discord/channel.py
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
async def edit(
    self,
    *,
    name: Absent[str] = MISSING,
    position: Absent[int] = MISSING,
    permission_overwrites: Absent[
        Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
    ] = MISSING,
    parent_id: Absent[Snowflake_Type] = MISSING,
    bitrate: Absent[int] = MISSING,
    user_limit: Absent[int] = MISSING,
    rtc_region: Absent[str] = MISSING,
    video_quality_mode: Absent[VideoQualityMode] = MISSING,
    reason: Absent[str] = MISSING,
    **kwargs,
) -> Union["GuildVoice", "GuildStageVoice"]:
    """
    Edit guild voice channel.

    Args:
        name: 1-100 character channel name
        position: the position of the channel in the left-hand listing
        permission_overwrites: a list of `PermissionOverwrite` to apply to the channel
        parent_id: the parent category `Snowflake_Type` for the channel
        bitrate: the bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers)
        user_limit: the user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit
        rtc_region: channel voice region id, automatic when not set
        video_quality_mode: the camera video quality mode of the voice channel
        reason: optional reason for audit logs

    Returns:
        The edited voice channel object.

    """
    return await super().edit(
        name=name,
        position=position,
        permission_overwrites=permission_overwrites,
        parent_id=parent_id,
        bitrate=bitrate,
        user_limit=user_limit,
        rtc_region=rtc_region,
        video_quality_mode=video_quality_mode,
        reason=reason,
        **kwargs,
    )

WebhookMixin

Source code in interactions/models/discord/channel.py
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
@attrs.define(eq=False, order=False, hash=False, slots=False, kw_only=True)
class WebhookMixin:
    async def create_webhook(self, name: str, avatar: Absent[UPLOADABLE_TYPE] = MISSING) -> "models.Webhook":
        """
        Create a webhook in this channel.

        Args:
            name: The name of the webhook
            avatar: An optional default avatar image to use

        Returns:
            The created webhook object

        Raises:
            ValueError: If you try to name the webhook "Clyde"

        """
        return await models.Webhook.create(self._client, self, name, avatar)  # type: ignore

    async def delete_webhook(self, webhook: "models.Webhook") -> None:
        """
        Delete a given webhook in this channel.

        Args:
            webhook: The webhook to delete

        """
        return await webhook.delete()

    async def fetch_webhooks(self) -> List["models.Webhook"]:
        """
        Fetches all the webhooks for this channel.

        Returns:
            List of webhook objects

        """
        resp = await self._client.http.get_channel_webhooks(self.id)
        return [models.Webhook.from_dict(d, self._client) for d in resp]

create_webhook(name, avatar=MISSING) async

Create a webhook in this channel.

Parameters:

Name Type Description Default
name str

The name of the webhook

required
avatar Absent[UPLOADABLE_TYPE]

An optional default avatar image to use

MISSING

Returns:

Type Description
Webhook

The created webhook object

Raises:

Type Description
ValueError

If you try to name the webhook "Clyde"

Source code in interactions/models/discord/channel.py
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
async def create_webhook(self, name: str, avatar: Absent[UPLOADABLE_TYPE] = MISSING) -> "models.Webhook":
    """
    Create a webhook in this channel.

    Args:
        name: The name of the webhook
        avatar: An optional default avatar image to use

    Returns:
        The created webhook object

    Raises:
        ValueError: If you try to name the webhook "Clyde"

    """
    return await models.Webhook.create(self._client, self, name, avatar)  # type: ignore

delete_webhook(webhook) async

Delete a given webhook in this channel.

Parameters:

Name Type Description Default
webhook Webhook

The webhook to delete

required
Source code in interactions/models/discord/channel.py
754
755
756
757
758
759
760
761
762
async def delete_webhook(self, webhook: "models.Webhook") -> None:
    """
    Delete a given webhook in this channel.

    Args:
        webhook: The webhook to delete

    """
    return await webhook.delete()

fetch_webhooks() async

Fetches all the webhooks for this channel.

Returns:

Type Description
List[Webhook]

List of webhook objects

Source code in interactions/models/discord/channel.py
764
765
766
767
768
769
770
771
772
773
async def fetch_webhooks(self) -> List["models.Webhook"]:
    """
    Fetches all the webhooks for this channel.

    Returns:
        List of webhook objects

    """
    resp = await self._client.http.get_channel_webhooks(self.id)
    return [models.Webhook.from_dict(d, self._client) for d in resp]

process_permission_overwrites(overwrites)

Processes a permission overwrite lists into format for sending to discord.

Parameters:

Name Type Description Default
overwrites Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]

The permission overwrites to process

required

Returns:

Type Description
List[dict]

The processed permission overwrites

Source code in interactions/models/discord/channel.py
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
def process_permission_overwrites(
    overwrites: Union[dict, PermissionOverwrite, List[Union[dict, PermissionOverwrite]]]
) -> List[dict]:
    """
    Processes a permission overwrite lists into format for sending to discord.

    Args:
        overwrites: The permission overwrites to process

    Returns:
        The processed permission overwrites

    """
    if not overwrites:
        return overwrites

    if isinstance(overwrites, dict):
        return [overwrites]

    if isinstance(overwrites, list):
        return list(map(to_dict, overwrites))

    if isinstance(overwrites, PermissionOverwrite):
        return [overwrites.to_dict()]

    raise ValueError(f"Invalid overwrites: {overwrites}")