Class: DMChannel

DMChannel

Represents a direct message channel between two users.

Constructor

new DMChannel(client, data)

Parameters:
Name Type Description
client Client The instantiating client
data Object The data for the DM channel
Implements:
Source:

Extends

Members

(readonly) client :Client

The client that instantiated this
Type:
Overrides:
Source:

(readonly) createdAt :Date

The time the channel was created at
Type:
  • Date
Overrides:
Source:

(readonly) createdTimestamp :number

The timestamp the channel was created at
Type:
  • number
Overrides:
Source:

deleted :boolean

Whether the channel has been deleted
Type:
  • boolean
Overrides:
Source:

id :Snowflake

The unique ID of the channel
Type:
Overrides:
Source:

(readonly, nullable) lastMessage :Message

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

(nullable) lastMessageID :Snowflake

The ID of the last message in the channel, if one was sent
Type:
Source:

(readonly, nullable) lastPinAt :Date

The date when the last pinned message was pinned, if there was one
Type:
  • Date
Implements:
Source:

(nullable) lastPinTimestamp :number

The timestamp when the last pinned message was pinned, if there was one
Type:
  • number
Source:

messages :MessageManager

A manager of the messages belonging to this channel
Type:
Source:

(readonly) partial :boolean

Whether this DMChannel is a partial
Type:
  • boolean
Source:

recipient :User

The recipient on the other end of the DM
Type:
Source:

type :string

The type of the channel, either: * `dm` - a DM channel * `text` - a guild text channel * `voice` - a guild voice channel * `category` - a guild category channel * `news` - a guild news channel * `store` - a guild store channel * `unknown` - a generic channel of unknown type, could be Channel or GuildChannel
Type:
  • string
Overrides:
Source:

(readonly) typing :boolean

Whether or not the typing indicator is being shown in the channel
Type:
  • boolean
Implements:
Source:

(readonly) typingCount :number

Number of times `startTyping` has been called
Type:
  • number
Implements:
Source:

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
Implements:
Source:
Returns:
Type
Promise.<Collection.<Snowflake, Message>>
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.`));

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
Implements:
Source:
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`));

delete() → {Promise.<Channel>}

Deletes this channel.
Overrides:
Source:
Returns:
Type
Promise.<Channel>
Example
// Delete the channel
channel.delete()
  .then(console.log)
  .catch(console.error);

fetch(forceopt) → {Promise.<DMChannel>}

Fetch this DMChannel.
Parameters:
Name Type Attributes Default Description
force boolean <optional>
false Whether to skip the cache check and request the API
Overrides:
Source:
Returns:
Type
Promise.<DMChannel>

isText() → {boolean}

Indicates whether this channel is text-based.
Overrides:
Source:
Returns:
Type
boolean

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
Implements:
Source:
Returns:
Type
Promise.<(Message|Array.<Message>)>
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
Implements:
Source:
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
Implements:
Source:
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);

toString() → {string}

When concatenated with a string, this automatically returns the recipient's mention instead of the DMChannel object.
Overrides:
Source:
Returns:
Type
string
Example
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${channel}!`);