Skip to content
Bilal Bassam edited this page Dec 12, 2024 · 28 revisions

Represents a text channel in a Discord guild, where guild members and webhooks can send and receive messages.

Instances of this class should not be constructed by users.

Properties Inherited From GuildChannel, TextChannel

Name Type Description
category GuildCategoryChannel/nil The parent channel category that may contain this channel.
client Client A shortcut to the client object to which this container is visible.
createdAt number The Unix time in seconds at which this object was created by Discord. Additional decimal points may be present, though only the first 3 (milliseconds) should be considered accurate. Equivalent to Date.parseSnowflake(Snowflake.id).
guild Guild The guild in which this channel exists.
id string The Snowflake ID that can be used to identify the object. This is guaranteed to be unique except in cases where an object shares the ID of its parent.
mentionString string A string that, when included in a message content, may resolve as a link to a channel in the official Discord client.
messages WeakCache An iterable weak cache of all messages that are visible to the client. Messages that are not referenced elsewhere are eventually garbage collected. To access a message that may exist but is not cached, use TextChannel:getMessage.
name string The name of the channel. This should be between 2 and 100 characters in length.
parent Container/Client The parent object of to which this container is a child. For example, the parent of a role is the guild in which the role exists.
permissionOverwrites Cache An iterable cache of all overwrites that exist in this channel. To access an overwrite that may exist, but is not cached, use GuildChannel:getPermissionOverwriteFor.
position number The position of the channel, where 0 is the highest.
private boolean Whether the "everyone" role has permission to view this channel. In the Discord channel, private text channels are indicated with a lock icon and private voice channels are not visible.
timestamp string The date and time at which this object was created by Discord, represented as an ISO 8601 string plus microseconds when available. Equivalent to Date.fromSnowflake(Snowflake.id):toISO().
type number The channel type. See the channelType enumeration for a human-readable representation.

Properties

Name Type Description
isNews boolean Whether this channel is a news channel of type 5.
members FilteredIterable A filtered iterable of guild members that have permission to read this channel. If you want to check whether a specific member has permission to read this channel, it would be better to get the member object elsewhere and use Member:hasPermission rather than check whether the member exists here.
nsfw boolean Whether this channel is marked as NSFW (not safe for work).
rateLimit number Slowmode rate limit per guild member.
topic string/nil The channel's topic. This should be between 1 and 1024 characters.

Methods Inherited From GuildChannel, TextChannel

__eq()

Defines the behavior of the == operator. Allows containers to be directly compared according to their type and __hash return values.

Returns: boolean


__hash()

Returns Snowflake.id

Returns: string


__tostring()

Defines the behavior of the tostring function. All containers follow the format ClassName: hash.

Returns: string


broadcastTyping()

Indicates in the channel that the client's user "is typing".

This method always makes an HTTP request.

Returns: boolean


createInvite(payload)

Parameter Type Optional
payload table

Creates an invite to the channel. Optional payload fields are: max_age: number time in seconds until expiration, default = 86400 (24 hours), max_uses: number total number of uses allowed, default = 0 (unlimited), temporary: boolean whether the invite grants temporary membership, default = false, unique: boolean whether a unique code should be guaranteed, default = false

This method always makes an HTTP request.

Returns: Invite


delete()

Permanently deletes the channel. This cannot be undone!

This method always makes an HTTP request.

Returns: boolean


getDate()

Returns a unique Date object that represents when the object was created by Discord. Equivalent to Date.fromSnowflake(Snowflake.id)

This method only operates on data in memory.

Returns: Date


getFirstMessage()

Returns the first message found in the channel, if any exist. This is not a cache shortcut; an HTTP request is made each time this method is called.

This method always makes an HTTP request.

Returns: Message


getInvites()

Returns a newly constructed cache of all invite objects for the channel. The cache and its objects are not automatically updated via gateway events. You must call this method again to get the updated objects.

This method always makes an HTTP request.

Returns: Cache


getLastMessage()

Returns the last message found in the channel, if any exist. This is not a cache shortcut; an HTTP request is made each time this method is called.

This method always makes an HTTP request.

Returns: Message


getMessage(id)

Parameter Type
id Message-ID-Resolvable

Gets a message object by ID. If the object is already cached, then the cached object will be returned; otherwise, an HTTP request is made.

This method may make an HTTP request.

Returns: Message


getMessages(limit)

Parameter Type Optional
limit number

Returns a newly constructed cache of between 1 and 100 (default = 50) message objects found in the channel. While the cache will never automatically gain or lose objects, the objects that it contains may be updated by gateway events.

This method always makes an HTTP request.

Returns: SecondaryCache


getMessagesAfter(id, limit)

Parameter Type Optional
id Message-ID-Resolvable
limit number

Returns a newly constructed cache of between 1 and 100 (default = 50) message objects found in the channel after a specific id. While the cache will never automatically gain or lose objects, the objects that it contains may be updated by gateway events.

This method always makes an HTTP request.

Returns: SecondaryCache


getMessagesAround(id, limit)

Parameter Type Optional
id Message-ID-Resolvable
limit number

Returns a newly constructed cache of between 1 and 100 (default = 50) message objects found in the channel around a specific point. While the cache will never automatically gain or lose objects, the objects that it contains may be updated by gateway events.

This method always makes an HTTP request.

Returns: SecondaryCache


getMessagesBefore(id, limit)

Parameter Type Optional
id Message-ID-Resolvable
limit number

Returns a newly constructed cache of between 1 and 100 (default = 50) message objects found in the channel before a specific id. While the cache will never automatically gain or lose objects, the objects that it contains may be updated by gateway events.

This method always makes an HTTP request.

Returns: SecondaryCache


getPermissionOverwriteFor(obj)

Parameter Type
obj Role/Member

Returns a permission overwrite object corresponding to the provided member or role object. If a cached overwrite is not found, an empty overwrite with zero-permissions is returned instead. Therefore, this can be used to create a new overwrite when one does not exist. Note that the member or role must exist in the same guild as the channel does.

This method only operates on data in memory.

Returns: PermissionOverwrite


getPinnedMessages()

Returns a newly constructed cache of up to 50 messages that are pinned in the channel. While the cache will never automatically gain or lose objects, the objects that it contains may be updated by gateway events.

This method always makes an HTTP request.

Returns: SecondaryCache


moveDown(n)

Parameter Type
n number

Moves a channel down its list. The parameter n indicates how many spaces the channel should be moved, clamped to the lowest position, with a default of 1 if it is omitted. This will also normalize the positions of all channels.

This method always makes an HTTP request.

Returns: boolean


moveUp(n)

Parameter Type
n number

Moves a channel up its list. The parameter n indicates how many spaces the channel should be moved, clamped to the highest position, with a default of 1 if it is omitted. This will also normalize the positions of all channels.

This method always makes an HTTP request.

Returns: boolean


send(content)

Parameter Type
content string/table

Sends a message to the channel. If content is a string, then this is simply sent as the message content. If it is a table, more advanced formatting is allowed. See managing messages for more information.

This method always makes an HTTP request.

Returns: Message


sendf(content, ...)

Parameter Type
content string
... *

Sends a message to the channel with content formatted with ... via string.format

This method always makes an HTTP request.

Returns: Message


setCategory(id)

Parameter Type
id Channel-ID-Resolvable

Sets the channel's parent category.

This method always makes an HTTP request.

Returns: boolean


setName(name)

Parameter Type
name string

Sets the channel's name. This must be between 2 and 100 characters in length.

This method always makes an HTTP request.

Returns: boolean


Methods

bulkDelete(messages)

Parameter Type
messages Message-ID-Resolvables

Bulk deletes multiple messages, from 2 to 100, from the channel. Messages over 2 weeks old cannot be deleted and will return an error.

This method always makes an HTTP request.

Returns: boolean


createWebhook(name)

Parameter Type
name string

Creates a webhook for this channel. The name must be between 2 and 32 characters in length.

This method always makes an HTTP request.

Returns: Webhook


disableNSFW()

Disables the NSFW setting for the channel. NSFW channels are hidden from users until the user explicitly requests to view them.

This method always makes an HTTP request.

Returns: boolean


enableNSFW()

Enables the NSFW setting for the channel. NSFW channels are hidden from users until the user explicitly requests to view them.

This method always makes an HTTP request.

Returns: boolean


follow(targetId)

Parameter Type
targetId Channel-ID-Resolvable

Follow this News channel and publish announcements to targetId. Returns a 403 HTTP error if GuildTextChannel.isNews is false.

This method always makes an HTTP request.

Returns: string


getWebhooks()

Returns a newly constructed cache of all webhook objects for the channel. The cache and its objects are not automatically updated via gateway events. You must call this method again to get the updated objects.

This method always makes an HTTP request.

Returns: Cache


setRateLimit(limit)

Parameter Type
limit number

Sets the channel's slowmode rate limit in seconds. This must be between 0 and 120. Passing 0 or nil will clear the limit.

This method always makes an HTTP request.

Returns: boolean


setTopic(topic)

Parameter Type
topic string

Sets the channel's topic. This must be between 1 and 1024 characters. Pass nil to remove the topic.

This method always makes an HTTP request.

Returns: boolean


Clone this wiki locally