DMChannel
classe · Source
Represents a direct message channel between two users.
Extends: ChannelImplements: TextBasedChannel
Properties
messages
A manager of the messages belonging to this channel Source
recipient
The recipient on the other end of the DM 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
messageRequest
Whether the channel is a message request Source
messageRequestTimestamp
The timestamp when the message request was created Source
partial
Whether this DMChannel is a partial Source
voiceUsers
The user in this voice-based channel Source
shard
Get current shard Source
voiceAdapterCreator
The voice state adapter for this client that can be used with @discordjs/voice to play audio in DM / Group DM channels. 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
type
The type of the channel Source
id
The channel's id Source
flags
The flags that are applied to the channel. Source
createdTimestamp
The timestamp the channel was created at Source
createdAt
The time the channel was created at Source
deleted
Whether or not the structure has been deleted Source
client
The client that instantiated this Source
Methods
acceptMessageRequest
Accept this DMChannel. Returns: Promise<DMChannel>Source
cancelMessageRequest
Cancel this DMChannel. Returns: Promise<DMChannel>Source
fetch
Fetch this DMChannel. Parameters
| Name | Type | Description |
|---|---|---|
force? | boolean | Whether to skip the cache check and request the API Default: true. |
Returns: Promise<DMChannel>Source
toString
When concatenated with a string, this automatically returns the recipient's mention instead of the DMChannel object. Returns: string
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${channel}!`);sync
Sync VoiceState of this DMChannel. Returns: undefinedSource
ring
Ring the user's phone / PC (call) Returns: Promise<void>Source
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.`));delete
Deletes this channel. Returns: Promise<Channel>
// Delete the channel
channel.delete()
.then(console.log)
.catch(console.error);isText
Indicates whether this channel is text-based. Returns: booleanSource
isVoice
Indicates whether this channel is voice-based. Returns: booleanSource
isThread
Indicates whether this channel is a ThreadChannel. Returns: booleanSource
isThreadOnly
Indicates whether this channel is ThreadOnlyChannel. Returns: booleanSource
isDirectory
Indicates whether this channel is a DirectoryChannelReturns: booleanSource