ThreadChannel
classe · Source
Represents a thread channel on Discord.
Extends: ChannelImplements: TextBasedChannel
Properties
guild
The guild the thread is in Source
ownerId
The id of the member who created this thread Source
guildId
The id of the guild the channel is in Source
messages
A manager of the messages sent to this thread Source
members
A manager of the members that are part of this thread Source
name
The name of the thread Source
parentId
The id of the parent channel of this thread Source
locked
Whether the thread is locked Source
invitable
Whether members without MANAGE_THREADS can invite other members without MANAGE_THREADS Always null in public threads Source
archived
Whether the thread is archived Source
autoArchiveDuration
The amount of time (in minutes) after which the thread will automatically archive in case of no recent activity Source
archiveTimestamp
The timestamp when the thread's archive status was last changed If the thread was never archived or unarchived, this is the timestamp at which the thread was created Source
lastMessageId
The last message id sent in this thread, if one was sent Source
lastPinTimestamp
The timestamp when the last pinned message was pinned, if there was one Source
rateLimitPerUser
The rate limit per user (slowmode) for this thread in seconds Source
messageCount
Threads created before July 1, 2022 may have an inaccurate count. If you need an approximate value higher than that, use ThreadChannel#messages.cache.sizeSource
memberCount
The approximate count of users in this thread This stops counting at 50. If you need an approximate value higher than that, use ThreadChannel#members.cache.sizeSource
totalMessageSent
The number of messages ever sent in a thread, similar to ThreadChannel#messageCount except it will not decrement whenever a message is deleted Source
appliedTags
The tags applied to this thread Source
createdTimestamp
The timestamp when this thread was created. This isn't available for threads created before 2022-01-09 Source
guildMembers
A collection of associated guild member objects of this thread's members Source
archivedAt
The time at which this thread's archive status was last changed If the thread was never archived or unarchived, this is the time at which the thread was created Source
createdAt
The time the thread was created at Source
parent
The parent channel of this thread Source
joined
Whether the client user is a member of the thread. Source
editable
Whether the thread is editable by the client user (name, archived, autoArchiveDuration) Source
joinable
Whether the thread is joinable by the client user Source
manageable
Whether the thread is manageable by the client user, for deleting or editing rateLimitPerUser or locked. Source
viewable
Whether the thread is viewable by the client user Source
sendable
Whether the client user can send messages in this thread Source
unarchivable
Whether the thread is unarchivable by the client user Source
lastMessage
The Message object of the last message in the channel, if one was sent Source
lastPinAt
The date when the last pinned message was pinned, if there was one Source
type
The type of the channel Source
id
The channel's id Source
flags
The flags that are applied to the channel. Source
deleted
Whether or not the structure has been deleted Source
partial
Whether this Channel is a partial This is always false outside of DM channels. Source
client
The client that instantiated this Source
Methods
join
Makes the client user join the thread. Returns: Promise<ThreadChannel>Source
leave
Makes the client user leave the thread. Returns: Promise<ThreadChannel>Source
permissionsFor
Gets the overall set of permissions for a member or role in this thread's parent channel, taking overwrites into account. Parameters
| Name | Type | Description |
|---|---|---|
memberOrRole | GuildMemberResolvable | RoleResolvable | The member or role to obtain the overall permissions for |
checkAdmin? | boolean | Whether having ADMINISTRATOR will return all permissions Default: true. |
Returns: Readonly<Permissions>Source
fetchOwner
Fetches the owner of this thread. If the thread member object isn't needed, use ThreadChannel#ownerId instead. Parameters
| Name | Type | Description |
|---|---|---|
options? | BaseFetchOptions | The options for fetching the member |
Returns: Promise<?ThreadMember>Source
fetchStarterMessage
Fetches the message that started this thread, if any. The Promise will reject if the original message in a forum post is deleted or when the original message in the parent channel is deleted. If you just need the id of that message, use ThreadChannel#id instead. Parameters
| Name | Type | Description |
|---|---|---|
options? | BaseFetchOptions | Additional options for this fetch |
Returns: Promise<(Message\|null)>Source
edit
Edits this thread. Parameters
| Name | Type | Description |
|---|---|---|
data | ThreadEditData | The new data for this thread |
reason? | string | Reason for editing this thread |
Returns: Promise<ThreadChannel>
// Edit a thread
thread.edit({ name: 'new-thread' })
.then(editedThread => console.log(editedThread))
.catch(console.error);setArchived
Sets whether the thread is archived. Parameters
| Name | Type | Description |
|---|---|---|
archived? | boolean | Whether the thread is archived Default: true. |
reason? | string | Reason for archiving or unarchiving |
Returns: Promise<ThreadChannel>
// Archive the thread
thread.setArchived(true)
.then(newThread => console.log(`Thread is now ${newThread.archived ? 'archived' : 'active'}`))
.catch(console.error);setAutoArchiveDuration
Sets the duration after which the thread will automatically archive in case of no recent activity. Parameters
| Name | Type | Description |
|---|---|---|
autoArchiveDuration | ThreadAutoArchiveDuration | The amount of time (in minutes) after which the thread should automatically archive in case of no recent activity |
reason? | string | Reason for changing the auto archive duration |
Returns: Promise<ThreadChannel>
// Set the thread's auto archive time to 1 hour
thread.setAutoArchiveDuration(60)
.then(newThread => {
console.log(`Thread will now archive after ${newThread.autoArchiveDuration} minutes of inactivity`);
});
.catch(console.error);setInvitable
Sets whether members without the MANAGE_THREADS permission can invite other members without the MANAGE_THREADS permission to this thread. Parameters
| Name | Type | Description |
|---|---|---|
invitable? | boolean | Whether non-moderators can invite non-moderators to this thread Default: true. |
reason? | string | Reason for changing invite |
Returns: Promise<ThreadChannel>Source
setLocked
Sets whether the thread can be unarchived by anyone with SEND_MESSAGES permission. When a thread is locked only members with MANAGE_THREADS can unarchive it. Parameters
| Name | Type | Description |
|---|---|---|
locked? | boolean | Whether the thread is locked Default: true. |
reason? | string | Reason for locking or unlocking the thread |
Returns: Promise<ThreadChannel>
// Set the thread to locked
thread.setLocked(true)
.then(newThread => console.log(`Thread is now ${newThread.locked ? 'locked' : 'unlocked'}`))
.catch(console.error);setName
Sets a new name for this thread. Parameters
| Name | Type | Description |
|---|---|---|
name | string | The new name for the thread |
reason? | string | Reason for changing the thread's name |
Returns: Promise<ThreadChannel>
// Change the thread's name
thread.setName('not_general')
.then(newThread => console.log(`Thread's new name is ${newThread.name}`))
.catch(console.error);setRateLimitPerUser
Sets the rate limit per user (slowmode) for this thread. Parameters
| Name | Type | Description |
|---|---|---|
rateLimitPerUser | number | The new rate limit in seconds |
reason? | string | Reason for changing the thread's rate limit |
Returns: Promise<ThreadChannel>Source
pin
Pins this thread from the forum channel. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for pinning |
Returns: Promise<ThreadChannel>Source
unpin
Unpins this thread from the forum channel. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for unpinning |
Returns: Promise<ThreadChannel>Source
setAppliedTags
Set the applied tags for this channel (only applicable to forum threads) Parameters
| Name | Type | Description |
|---|---|---|
appliedTags | Array<Snowflake> | The tags to set for this channel |
reason? | string | Reason for changing the thread's applied tags |
Returns: Promise<ThreadChannel>Source
isPrivate
Whether this thread is a private thread Returns: booleanSource
delete
Deletes this thread. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for deleting this thread |
Returns: Promise<ThreadChannel>
// Delete the thread
thread.delete('cleaning out old threads')
.then(deletedThread => console.log(deletedThread))
.catch(console.error);send
Sends a message to this channel. Parameters
| Name | Type | Description |
|---|---|---|
options | string | MessagePayload | MessageOptions | The options to provide |
Returns: Promise<Message>
// Send a basic message
channel.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);// Send a remote file
channel.send({
files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
.then(console.log)
.catch(console.error);// Send a local file
channel.send({
files: [{
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg',
description: 'A description of the file'
}]
})
.then(console.log)
.catch(console.error);sendTyping
Sends a typing indicator in the channel. Returns: Promise<({message_send_cooldown_ms: number, thread_create_cooldown_ms: number}\|void)> — Resolves upon the typing status being sent
// Start typing in a channel
channel.sendTyping();createMessageCollector
Creates a Message Collector. Parameters
| Name | Type | Description |
|---|---|---|
options? | MessageCollectorOptions | The options to pass to the collector Default: {}. |
Returns: MessageCollector
// Create a message collector
const filter = m => m.content.includes('discord');
const collector = channel.createMessageCollector({ filter, time: 15_000 });
collector.on('collect', m => console.log(`Collected ${m.content}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));awaitMessages
Similar to createMessageCollector but in promise form. Resolves with a collection of messages that pass the specified filter. Parameters
| Name | Type | Description |
|---|---|---|
options? | AwaitMessagesOptions | Optional options to pass to the internal collector Default: {}. |
Returns: Promise<Collection<Snowflake, Message>>
// Await !vote messages
const filter = m => m.content.startsWith('!vote');
// Errors: ['time'] treats ending because of the time limit as an error
channel.awaitMessages({ filter, max: 4, time: 60_000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));toString
When concatenated with a string, this automatically returns the channel's mention instead of the Channel object. Returns: string
// Logs: Hello from <#123456789012345678>!
console.log(`Hello from ${channel}!`);fetch
Fetches this channel. Parameters
| Name | Type | Description |
|---|---|---|
force? | boolean | Whether to skip the cache check and request the API Default: true. |
Returns: Promise<Channel>Source
isText
Indicates whether this channel is text-based. Returns: booleanSource
isVoice
Indicates whether this channel is voice-based. Returns: booleanSource
isThread
Indicates whether this channel is a ThreadChannel. Returns: booleanSource
isThreadOnly
Indicates whether this channel is ThreadOnlyChannel. Returns: booleanSource
isDirectory
Indicates whether this channel is a DirectoryChannelReturns: booleanSource