Table of Contents

Class SocketUserMessage

Namespace
Discord.WebSocket
Assembly
Discord.Net.WebSocket.dll

Represents a WebSocket-based message sent by a user.

public class SocketUserMessage : SocketMessage, IUserMessage, IMessage, ISnowflakeEntity, IEntity<ulong>, IDeletable
Inheritance
SocketUserMessage
Implements
Inherited Members
Extension Methods

Properties

Attachments

Returns all attachments included in this message.

public override IReadOnlyCollection<Attachment> Attachments { get; }

Property Value

IReadOnlyCollection<Attachment>

Collection of attachments.

EditedTimestamp

Gets the time of this message's last edit.

public override DateTimeOffset? EditedTimestamp { get; }

Property Value

DateTimeOffset?

Time of when the message was last edited; null if the message is never edited.

Embeds

Returns all embeds included in this message.

public override IReadOnlyCollection<Embed> Embeds { get; }

Property Value

IReadOnlyCollection<Embed>

Collection of embed objects.

ForwardedMessages

Gets a collection of partial messages that were forwarded with this message.

public IReadOnlyCollection<MessageSnapshot> ForwardedMessages { get; }

Property Value

IReadOnlyCollection<MessageSnapshot>

InteractionMetadata

Gets the interaction metadata for the interaction this message is a response to.

public IMessageInteractionMetadata InteractionMetadata { get; }

Property Value

IMessageInteractionMetadata

Remarks

Will be null if the message is not a response to an interaction.

IsPinned

Gets the value that indicates whether this message is pinned.

public override bool IsPinned { get; }

Property Value

bool

true if this message was added to its channel's pinned messages; otherwise false.

IsSuppressed

Gets the value that indicates whether or not this message's embeds are suppressed.

public override bool IsSuppressed { get; }

Property Value

bool

true if the embeds in this message have been suppressed (made invisible); otherwise false.

IsTTS

Gets the value that indicates whether this message was meant to be read-aloud by Discord.

public override bool IsTTS { get; }

Property Value

bool

true if this message was sent as a text-to-speech message; otherwise false.

MentionedChannels

Returns the channels mentioned in this message.

public override IReadOnlyCollection<SocketGuildChannel> MentionedChannels { get; }

Property Value

IReadOnlyCollection<SocketGuildChannel>

Collection of WebSocket-based guild channels.

MentionedEveryone

Gets the value that indicates whether this message mentioned everyone.

public override bool MentionedEveryone { get; }

Property Value

bool

true if this message mentioned everyone; otherwise false.

MentionedRoleIds

Gets the IDs of roles mentioned in this message.

public override IReadOnlyCollection<ulong> MentionedRoleIds { get; }

Property Value

IReadOnlyCollection<ulong>

A read-only collection of role IDs.

MentionedRoles

Returns the roles mentioned in this message.

public override IReadOnlyCollection<SocketRole> MentionedRoles { get; }

Property Value

IReadOnlyCollection<SocketRole>

Collection of WebSocket-based roles.

Remarks

This collection may be missing values due to the guild being missing from cache (i.e. in user app interaction context). In that case you can use the MentionedRoleIds property.

Poll

Gets the poll sent with this message.

public Poll? Poll { get; }

Property Value

Poll?

Remarks

Will be null if the message has no poll.

ReferencedMessage

Gets the referenced message if it is a crosspost, channel follow add, pin, or reply message.

public IUserMessage ReferencedMessage { get; }

Property Value

IUserMessage

The referenced message, if any is associated and still exists.

ResolvedData

Gets the resolved data if the message has components. null otherwise.

public MessageResolvedData ResolvedData { get; }

Property Value

MessageResolvedData

Stickers

public override IReadOnlyCollection<SocketSticker> Stickers { get; }

Property Value

IReadOnlyCollection<SocketSticker>

Tags

Gets all tags included in this message's content.

public override IReadOnlyCollection<ITag> Tags { get; }

Property Value

IReadOnlyCollection<ITag>

Methods

CrosspostAsync(RequestOptions)

Publishes (crossposts) this message.

public Task CrosspostAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for publishing this message.

Remarks

warning

This call will throw an InvalidOperationException if attempted in a non-news channel.

This method will publish (crosspost) the message. Please note, publishing (crossposting), is only available in news channels.

Exceptions

InvalidOperationException

This operation may only be called on a INewsChannel channel.

EndPollAsync(RequestOptions)

Immediately ends the poll.

public Task EndPollAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

Remarks

You cannot end polls from other users.

GetPollAnswerVotersAsync(uint, int?, ulong?, RequestOptions)

Get users that voted for this specific answer.

public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetPollAnswerVotersAsync(uint answerId, int? limit = null, ulong? afterId = null, RequestOptions options = null)

Parameters

answerId uint

The id on the answer to fetch voters for

limit int?

The number of users to request.

afterId ulong?

The id of a user to start after.

options RequestOptions

The options to be used when sending the request.

Returns

IAsyncEnumerable<IReadOnlyCollection<IUser>>

ModifyAsync(Action<MessageProperties>, RequestOptions)

Modifies this message.

public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null)

Parameters

func Action<MessageProperties>

A delegate containing the properties to modify the message with.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous modification operation.

Examples

The following example replaces the content of the message with Hello World!.

await msg.ModifyAsync(x => x.Content = "Hello World!");

Remarks

This method modifies this message with the specified properties. To see an example of this method and what properties are available, please refer to MessageProperties.

Exceptions

InvalidOperationException

Only the author of a message may modify the message.

ArgumentOutOfRangeException

Message content is too long, length must be less or equal to MaxMessageSize.

PinAsync(RequestOptions)

Adds this message to its channel's pinned messages.

public Task PinAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for pinning this message.

Resolve(TagHandling, TagHandling, TagHandling, TagHandling, TagHandling)

Transforms this message's text into a human-readable form by resolving its tags.

public string Resolve(TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)

Parameters

userHandling TagHandling

Determines how the user tag should be handled.

channelHandling TagHandling

Determines how the channel tag should be handled.

roleHandling TagHandling

Determines how the role tag should be handled.

everyoneHandling TagHandling

Determines how the @everyone tag should be handled.

emojiHandling TagHandling

Determines how the emoji tag should be handled.

Returns

string

Resolve(int, TagHandling, TagHandling, TagHandling, TagHandling, TagHandling)

public string Resolve(int startIndex, TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)

Parameters

startIndex int
userHandling TagHandling
channelHandling TagHandling
roleHandling TagHandling
everyoneHandling TagHandling
emojiHandling TagHandling

Returns

string

UnpinAsync(RequestOptions)

Removes this message from its channel's pinned messages.

public Task UnpinAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for unpinning this message.