Members
(readonly, nullable) lastMessage :Message
The Message object of the last message in the channel, if one was sent
Type:
(readonly, nullable) lastPinAt :Date
The date when the last pinned message was pinned, if there was one
Type:
- Date
(readonly) typing :boolean
Whether or not the typing indicator is being shown in the channel
Type:
- boolean
(readonly) typingCount :number
Number of times `startTyping` has been called
Type:
- number
Methods
awaitMessages(filter, optionsopt) → {Promise.<Collection.<Snowflake, Message>>}
Similar to createMessageCollector but in promise form.
Resolves with a collection of messages that pass the specified filter.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
filter |
CollectorFilter | The filter function to use | ||
options |
AwaitMessagesOptions |
<optional> |
{} | Optional options to pass to the internal collector |
Returns:
Example
// 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: 60000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
(async) bulkDelete(messages, filterOldopt) → {Promise.<Collection.<Snowflake, Message>>}
Bulk deletes given messages that are newer than two weeks.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
messages |
Collection.<Snowflake, Message> | Array.<MessageResolvable> | number | Messages or number of messages to delete | ||
filterOld |
boolean |
<optional> |
false | Filter messages to remove those which are older than two weeks automatically |
Returns:
Deleted messages
Example
// Bulk delete messages
channel.bulkDelete(5)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
createMessageCollector(filter, optionsopt) → {MessageCollector}
Creates a Message Collector.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
filter |
CollectorFilter | The filter to create the collector with | ||
options |
MessageCollectorOptions |
<optional> |
{} | The options to pass to the collector |
Returns:
- Type
- MessageCollector
Example
// Create a message collector
const filter = m => m.content.includes('discord');
const collector = channel.createMessageCollector(filter, { time: 15000 });
collector.on('collect', m => console.log(`Collected ${m.content}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
(async) send(contentopt, optionsopt) → {Promise.<(Message|Array.<Message>)>}
Sends a message to this channel.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
content |
StringResolvable | APIMessage |
<optional> |
'' | The content to send |
options |
MessageOptions | MessageAdditions |
<optional> |
{} | The options to provide |
Returns:
Examples
// 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'
}]
})
.then(console.log)
.catch(console.error);
// Send an embed with a local image inside
channel.send('This is an embed', {
embed: {
thumbnail: {
url: 'attachment://file.jpg'
}
},
files: [{
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
}]
})
.then(console.log)
.catch(console.error);
startTyping(countopt) → {Promise}
Starts a typing indicator in the channel.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
count |
number |
<optional> |
1 | The number of times startTyping should be considered to have been called |
Returns:
Resolves once the bot stops typing gracefully, or rejects when an error occurs
- Type
- Promise
Examples
// Start typing in a channel, or increase the typing count by one
channel.startTyping();
// Start typing in a channel with a typing count of five, or set it to five
channel.startTyping(5);
stopTyping(forceopt)
Stops the typing indicator in the channel.
The indicator will only stop if this is called as many times as startTyping().
It can take a few seconds for the client user to stop typing.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
force |
boolean |
<optional> |
false | Whether or not to reset the call count and force the indicator to stop |
Examples
// Reduce the typing count by one and stop typing if it reached 0
channel.stopTyping();
// Force typing to fully stop regardless of typing count
channel.stopTyping(true);