Skip to content

TextBasedChannel

interface · Source

Interface for classes that have text-channel-like features.

Properties

messages

messages: MessageManager

A manager of the messages sent to this channel Source

lastMessageId

nullable

lastMessageId: Snowflake

The channel's last message id, if one was sent Source

lastPinTimestamp

nullable

lastPinTimestamp: number

The timestamp when the last pinned message was pinned, if there was one Source

lastMessage

readonly · nullable

lastMessage: Message

The Message object of the last message in the channel, if one was sent Source

lastPinAt

readonly · nullable

lastPinAt: Date

The date when the last pinned message was pinned, if there was one Source

Methods

send

async

async send(options: string | MessagePayload | MessageOptions): Promise<Message>

Sends a message to this channel. Parameters

NameTypeDescription
optionsstring | MessagePayload | MessageOptionsThe options to provide

Returns: Promise<Message>

js
// Send a basic message
channel.send('hello!')
  .then(message => console.log(`Sent message: ${message.content}`))
  .catch(console.error);
js
// Send a remote file
channel.send({
  files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
  .then(console.log)
  .catch(console.error);
js
// 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);

Source

sendTyping

sendTyping(): Promise<({message_send_cooldown_ms: number, thread_create_cooldown_ms: number}|void)>

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

js
// Start typing in a channel
channel.sendTyping();

Source

createMessageCollector

createMessageCollector(options?: MessageCollectorOptions): MessageCollector

Creates a Message Collector. Parameters

NameTypeDescription
options?MessageCollectorOptionsThe options to pass to the collector Default: {}.

Returns: MessageCollector

js
// 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`));

Source

awaitMessages

awaitMessages(options?: AwaitMessagesOptions): Promise<Collection<Snowflake, Message>>

Similar to createMessageCollector but in promise form. Resolves with a collection of messages that pass the specified filter. Parameters

NameTypeDescription
options?AwaitMessagesOptionsOptional options to pass to the internal collector Default: {}.

Returns: Promise<Collection<Snowflake, Message>>

js
// 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.`));

Source

fetchWebhooks

fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>

Fetches all webhooks for the channel. Returns: Promise<Collection<Snowflake, Webhook>>

js
// Fetch webhooks
channel.fetchWebhooks()
  .then(hooks => console.log(`This channel has ${hooks.size} hooks`))
  .catch(console.error);

Source

createWebhook

createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>

Creates a webhook for the channel. Parameters

NameTypeDescription
namestringThe name of the webhook
options?ChannelWebhookCreateOptionsOptions for creating the webhook

Returns: Promise<Webhook> — Returns the created Webhook

js
// Create a webhook for the current channel
channel.createWebhook('Snek', {
  avatar: 'https://i.imgur.com/mI8XcpG.jpg',
  reason: 'Needed a cool new Webhook'
})
  .then(console.log)
  .catch(console.error)

Source

setRateLimitPerUser

setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<this>

Sets the rate limit per user (slowmode) for this channel. Parameters

NameTypeDescription
rateLimitPerUsernumberThe new rate limit in seconds
reason?stringReason for changing the channel's rate limit

Returns: Promise<this>Source

setNSFW

setNSFW(nsfw?: boolean, reason?: string): Promise<this>

Sets whether this channel is flagged as NSFW. Parameters

NameTypeDescription
nsfw?booleanWhether the channel should be considered NSFW Default: true.
reason?stringReason for changing the channel's NSFW flag

Returns: Promise<this>Source

Unofficial software. Not affiliated with or supported by Discord.