class ThreadChannel
extends
TextBasedChannelMixin(BaseChannel, true, [ 'fetchWebhooks', 'createWebhook', 'setNSFW',])export class ThreadChannel<ThreadOnly extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [ 'fetchWebhooks', 'createWebhook', 'setNSFW',])
Represents a thread channel on Discord.
Snowflake[] appliedTags :
The tags applied to this thread
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
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
ThreadAutoArchiveDuration | null autoArchiveDuration :
The amount of time (in minutes) after which the thread will automatically archive in case of no recent activity
The timestamp when this thread was created. This isn't available for threads created before 2022-01-09
readonlyboolean editable :
Whether the thread is editable by the client user (name, archived, autoArchiveDuration)
Readonly<ChannelFlagsBitField> flags :
The flags that are applied to the channel. This is only null
in a PartialGroupDMChannel. In all other cases, it is not null
.
Guild guild :
The guild the thread is in
Snowflake guildId :
The id of the guild the channel is in
readonlyCollection<Snowflake, GuildMember> guildMembers :
A collection of associated guild member objects of this thread's members
Whether members without the PermissionFlagsBits permission can invite other members to this thread. This property is always null
in public threads.
readonlyboolean joinable :
Whether the thread is joinable by the client user
readonlyboolean joined :
Whether the client user is a member of the thread.
readonlyoptionalMessage lastMessage? :
The Message object of the last message in the channel, if one was sent
optionalSnowflake lastMessageId? :
The last message id sent in this thread, if one was sent
readonlyoptionalDate lastPinAt? :
The date when the last pinned message was pinned, if there was one
optionalnumber lastPinTimestamp? :
The timestamp when the last pinned message was pinned, if there was one
readonlyboolean manageable :
Whether the thread is manageable by the client user, for deleting or editing rateLimitPerUser or locked.
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.size
ThreadMemberManager members :
A manager of the members that are part of this thread
The approximate count of messages in this thread Threads created before July 1, 2022 may have an inaccurate count. If you need an approximate value higher than that, use ThreadChannel#messages.cache.size
GuildMessageManager messages :
A manager of the messages sent to this thread
string name :
The name of the thread
readonlyIf<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel> | null parent :
The parent channel of this thread
readonlyboolean sendable :
Whether the client user can send messages in this thread
The number of messages ever sent in a thread, similar to messageCount except it will not decrement whenever a message is deleted
ThreadChannelType type :
The type of the channel
readonlyboolean unarchivable :
Whether the thread is unarchivable by the client user
readonlyboolean viewable :
Whether the thread is viewable by the client user
awaitMessageComponentoptions?: AwaitMessageComponentOptions) : Promise<MessageComponentInteraction> (
Collects a single component interaction that passes the filter. The Promise will reject if the time expires.
// Collect a message component interaction
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
channel.awaitMessageComponent({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was clicked!`))
.catch(console.error);
awaitMessagesoptions?: AwaitMessagesOptions) : Promise<Collection<Snowflake, Message>> (
Similar to createMessageCollector but in promise form. Resolves with a collection of messages that pass the specified filter.
// 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.`));
bulkDeletemessages: Collection<Snowflake, Message> | Array<MessageResolvable> | numberfilterOld?: boolean) : Promise<Collection<Snowflake, (Message|undefined)>> (
Bulk deletes given messages that are newer than two weeks.
// Bulk delete messages
channel.bulkDelete(5)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
Returns: Returns the deleted messages *
createMessageCollectoroptions?: MessageCollectorOptions) : MessageCollector (
Creates a Message Collector.
// Create a message collector
const filter = message => message.content.includes('discord');
const collector = channel.createMessageCollector({ filter, time: 15_000 });
collector.on('collect', message => console.log(`Collected ${message.content}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
createMessageComponentCollectoroptions?: MessageComponentCollectorOptions) : InteractionCollector (
Creates a component interaction collector.
// Create a button interaction collector
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
const collector = channel.createMessageComponentCollector({ filter, time: 15_000 });
collector.on('collect', interaction => console.log(`Collected ${interaction.customId}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
Deletes this thread.
// Delete the thread
thread.delete('cleaning out old threads')
.then(deletedThread => console.log(deletedThread))
.catch(console.error);
editoptions: ThreadEditOptions) : Promise<AnyThreadChannel> (
Edits this thread.
// Edit a thread
thread.edit({ name: 'new-thread' })
.then(editedThread => console.log(editedThread))
.catch(console.error);
fetchOwneroptions?: BaseFetchOptions) : Promise<ThreadMember | null> (
Fetches the owner of this thread. If the thread member object isn't needed, use ownerId instead.
fetchStarterMessageoptions?: BaseFetchOptions) : Promise<Message<true> | null> (
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 instead.
joinPromise<AnyThreadChannel> () :
Makes the client user join the thread.
leavePromise<AnyThreadChannel> () :
Makes the client user leave the thread.
permissionsFormemberOrRole: GuildMember | RolecheckAdmin?: boolean) : Readonly<PermissionsBitField> (
Gets the overall set of permissions for a member or role in this thread's parent channel, taking overwrites into account.
pinreason?: string) : Promise<ThreadChannel<true>> (
Pins this thread from the forum channel (only applicable to forum threads).
sendoptions: string | MessagePayload | MessageCreateOptions) : Promise<Message> (
Sends a message to this channel.
// 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);
Sends a typing indicator in the channel.
// Start typing in a channel
channel.sendTyping();
Returns: Resolves upon the typing status being sent *
setAppliedTags) : Promise<ThreadChannel<true>> (
Set the applied tags for this channel (only applicable to forum threads)
setArchived) : Promise<AnyThreadChannel> (
Sets whether the thread is archived.
// Archive the thread
thread.setArchived(true)
.then(newThread => console.log(`Thread is now ${newThread.archived ? 'archived' : 'active'}`))
.catch(console.error);
setAutoArchiveDurationautoArchiveDuration: ThreadAutoArchiveDurationreason?: string) : Promise<AnyThreadChannel> (
Sets the duration after which the thread will automatically archive in case of no recent activity.
// Set the thread's auto archive time to 1 hour
thread.setAutoArchiveDuration(ThreadAutoArchiveDuration.OneHour)
.then(newThread => {
console.log(`Thread will now archive after ${newThread.autoArchiveDuration} minutes of inactivity`);
});
.catch(console.error);
setInvitable) : Promise<AnyThreadChannel> (
Sets whether members without the PermissionFlagsBits permission can invite other members to this thread.
setLocked) : Promise<AnyThreadChannel> (
Sets whether the thread can be **unarchived* * by anyone with the PermissionFlagsBits permission. When a thread is locked, only members with the PermissionFlagsBits permission can unarchive it.
// Set the thread to locked
thread.setLocked(true)
.then(newThread => console.log(`Thread is now ${newThread.locked ? 'locked' : 'unlocked'}`))
.catch(console.error);
setName) : Promise<AnyThreadChannel> (
Sets a new name for this thread.
// Change the thread's name
thread.setName('not_general')
.then(newThread => console.log(`Thread's new name is ${newThread.name}`))
.catch(console.error);
setRateLimitPerUser) : Promise<ThreadChannel> (
Sets the rate limit per user (slowmode) for this thread.
toStringChannelMention () :
When concatenated with a string, this automatically returns the channel's mention instead of the Channel object.
// Logs: Hello from <#123456789012345678>!
console.log(`Hello from ${channel}!`);
unpinreason?: string) : Promise<ThreadChannel<true>> (
Unpins this thread from the forum channel (only applicable to forum threads).