DMChannel

export class DMChannel extends BaseChannel
export class DMChannel extends BaseChannel
Represents a direct message channel between two users.
Readonly
client:Client<true>
The client that instantiated this
Inherited from Base
Readonly
createdAt:Date | null
The time the channel was created at
Inherited from BaseChannel
Readonly
createdTimestamp:number | null
The timestamp the channel was created at
Inherited from BaseChannel
The flags that are applied to the channel. This is only null in a PartialGroupDMChannel. In all other cases, it is not null.
The channel's id
Inherited from BaseChannel
Readonly
lastMessage?:Message
The Message object of the last message in the channel, if one was sent
lastMessageId?:Snowflake
The channel's last message id, if one was sent
Readonly
lastPinAt?:Date
The date when the last pinned message was pinned, if there was one
lastPinTimestamp?:number
The timestamp when the last pinned message was pinned, if there was one
A manager of the messages belonging to this channel
Readonly
partial:false
Whether this Channel is a partial This is always false outside of DM channels.
Inherited from BaseChannel
Readonly
recipient:User | null
The recipient on the other end of the DM
recipientId:Snowflake
The recipient's id
The type of the channel
Readonly
url:string
The URL to the channel
Inherited from BaseChannel
awaitMessageComponent(options?):Promise<MessageComponentInteraction>
Collects a single component interaction that passes the filter. The Promise will reject if the time expires.
Example
// 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);
// 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);
NameTypeOptionalDescription
optionsAwaitMessageComponentOptionsYesOptions to pass to the internal collector
awaitMessages(options?):Promise<Collection<Snowflake, Message>>
Similar to createMessageCollector but in promise form. Resolves with a collection of messages that pass the specified filter.
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: 60_000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
// 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.`));
NameTypeOptionalDescription
optionsAwaitMessagesOptionsYesOptional options to pass to the internal collector
createMessageCollector(options?):MessageCollector
Creates a Message Collector.
Example
// 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`));
// 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`));
NameTypeOptionalDescription
optionsMessageCollectorOptionsYesThe options to pass to the collector
createMessageComponentCollector(options?):InteractionCollector
Creates a component interaction collector.
Example
// 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`));
// 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`));
NameTypeOptionalDescription
optionsMessageComponentCollectorOptionsYesOptions to send to the collector
delete():Promise<this>
Deletes this channel.
Example
// Delete the channel
channel.delete()
.then(console.log)
.catch(console.error);
// Delete the channel
channel.delete()
.then(console.log)
.catch(console.error);
Inherited from BaseChannel
fetch(force?):Promise<this>
Fetch this DMChannel.
NameTypeOptionalDescription
forcebooleanYesWhether to skip the cache check and request the API
Indicates whether this channel is DM-based (either a or a PartialGroupDMChannel).
Inherited from BaseChannel
isSendable():this is SendableChannels
Indicates whether this channel is sendable.
Inherited from BaseChannel
isTextBased():this is TextBasedChannel
Indicates whether this channel is text-based.
Inherited from BaseChannel
isThread():this is AnyThreadChannel
Indicates whether this channel is a .
Inherited from BaseChannel
isThreadOnly():this is ThreadOnlyChannel
Indicates whether this channel is .
Inherited from BaseChannel
isVoiceBased():this is VoiceBasedChannel
Indicates whether this channel is .
Inherited from BaseChannel
send(options):Promise<Message>
Sends a message to this channel.
Example
// Send a basic message
channel.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
// Send a basic message
channel.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
Example
// 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 remote file
channel.send({
files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
.then(console.log)
.catch(console.error);
Example
// 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);
// 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);
NameTypeOptionalDescription
optionsstring | MessagePayload | MessageCreateOptionsNoThe options to provide
sendTyping():Promise<void>
Sends a typing indicator in the channel.
Returns
Resolves upon the typing status being sent *
Example
// Start typing in a channel
channel.sendTyping();
// Start typing in a channel
channel.sendTyping();
toJSON(...props):unknown
NameTypeOptionalDescription
...propsRecord<string, boolean | string>[]NoNone
Inherited from Base
toString():UserMention
When concatenated with a string, this automatically returns the recipient's mention instead of the DMChannel object.
Example
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${channel}!`);
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${channel}!`);
valueOf():string