TextBasedChannel
interface · Source
Interface for classes that have text-channel-like features.
Properties
messages
A manager of the messages sent to this channel Source
lastMessageId
The channel's last message id, if one was sent Source
lastPinTimestamp
The timestamp when the last pinned message was pinned, if there was one 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
Methods
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.`));fetchWebhooks
Fetches all webhooks for the channel. Returns: Promise<Collection<Snowflake, Webhook>>
// Fetch webhooks
channel.fetchWebhooks()
.then(hooks => console.log(`This channel has ${hooks.size} hooks`))
.catch(console.error);createWebhook
Creates a webhook for the channel. Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the webhook |
options? | ChannelWebhookCreateOptions | Options for creating the webhook |
Returns: Promise<Webhook> — Returns the created Webhook
// 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)setRateLimitPerUser
Sets the rate limit per user (slowmode) for this channel. Parameters
| Name | Type | Description |
|---|---|---|
rateLimitPerUser | number | The new rate limit in seconds |
reason? | string | Reason for changing the channel's rate limit |
Returns: Promise<this>Source
setNSFW
Sets whether this channel is flagged as NSFW. Parameters
| Name | Type | Description |
|---|---|---|
nsfw? | boolean | Whether the channel should be considered NSFW Default: true. |
reason? | string | Reason for changing the channel's NSFW flag |
Returns: Promise<this>Source