Table of Contents

Class SocketMessage

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

Represents a WebSocket-based message.

public abstract class SocketMessage : SocketEntity<ulong>, IMessage, ISnowflakeEntity, IEntity<ulong>, IDeletable
Inheritance
SocketMessage
Implements
Derived
Inherited Members
Extension Methods

Properties

Activity

Gets the activity associated with a message.

public MessageActivity Activity { get; }

Property Value

MessageActivity

A message's activity, if any is associated.

Remarks

Sent with Rich Presence-related chat embeds. This often refers to activity that requires end-user's interaction, such as a Spotify Invite activity.

Application

Gets the application associated with a message.

public MessageApplication Application { get; }

Property Value

MessageApplication

A message's application, if any is associated.

Remarks

Sent with Rich-Presence-related chat embeds.

Attachments

Returns all attachments included in this message.

public virtual IReadOnlyCollection<Attachment> Attachments { get; }

Property Value

IReadOnlyCollection<Attachment>

Collection of attachments.

Author

Gets the author of this message.

public SocketUser Author { get; }

Property Value

SocketUser

A WebSocket-based user object.

Channel

Gets the source channel of the message.

public ISocketMessageChannel Channel { get; }

Property Value

ISocketMessageChannel

A WebSocket-based message channel.

CleanContent

Gets the clean content for this message.

public string CleanContent { get; }

Property Value

string

A string that contains the body of the message stripped of mentions, markdown, emojis and pings; note that this field may be empty if there is an embed.

Remarks

This will be empty if the privileged MessageContent is disabled.

Components

public IReadOnlyCollection<ActionRowComponent> Components { get; }

Property Value

IReadOnlyCollection<ActionRowComponent>

Content

Gets the content for this message.

public string Content { get; }

Property Value

string

A string that contains the body of the message; note that this field may be empty if there is an embed.

Remarks

This will be empty if the privileged MessageContent is disabled.

CreatedAt

Gets when the snowflake was created.

public DateTimeOffset CreatedAt { get; }

Property Value

DateTimeOffset

A DateTimeOffset representing when the entity was first created.

EditedTimestamp

Gets the time of this message's last edit.

public virtual 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 virtual IReadOnlyCollection<Embed> Embeds { get; }

Property Value

IReadOnlyCollection<Embed>

Collection of embed objects.

Flags

Gets the flags related to this message.

public MessageFlags? Flags { get; }

Property Value

MessageFlags?

A message's flags, if any is associated.

Remarks

This value is determined by bitwise OR-ing MessageFlags values together.

Interaction

Gets the interaction this message is a response to.

public MessageInteraction<SocketUser> Interaction { get; }

Property Value

MessageInteraction<SocketUser>

IsPinned

Gets the value that indicates whether this message is pinned.

public virtual 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 virtual 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 virtual 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 virtual 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 virtual bool MentionedEveryone { get; }

Property Value

bool

true if this message mentioned everyone; otherwise false.

MentionedRoles

Returns the roles mentioned in this message.

public virtual IReadOnlyCollection<SocketRole> MentionedRoles { get; }

Property Value

IReadOnlyCollection<SocketRole>

Collection of WebSocket-based roles.

MentionedUsers

Returns the users mentioned in this message.

public IReadOnlyCollection<SocketUser> MentionedUsers { get; }

Property Value

IReadOnlyCollection<SocketUser>

Collection of WebSocket-based users.

Reactions

Gets all reactions included in this message.

public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions { get; }

Property Value

IReadOnlyDictionary<IEmote, ReactionMetadata>

Reference

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

public MessageReference Reference { get; }

Property Value

MessageReference

A message's reference, if any is associated.

Remarks

Sent with cross-posted messages, meaning they were published from news channels and received by subscriber channels, channel follow adds, pins, and message replies.

RoleSubscriptionData

Gets the data of the role subscription purchase or renewal that prompted this RoleSubscriptionPurchase message.

public MessageRoleSubscriptionData RoleSubscriptionData { get; }

Property Value

MessageRoleSubscriptionData

A MessageRoleSubscriptionData if the message is a role subscription purchase message; otherwise null.

Source

Gets the source type of this message.

public MessageSource Source { get; }

Property Value

MessageSource

Stickers

public virtual IReadOnlyCollection<SocketSticker> Stickers { get; }

Property Value

IReadOnlyCollection<SocketSticker>

Tags

Gets all tags included in this message's content.

public virtual IReadOnlyCollection<ITag> Tags { get; }

Property Value

IReadOnlyCollection<ITag>

Thread

Gets the thread that was started from this message.

public SocketThreadChannel Thread { get; }

Property Value

SocketThreadChannel

An IThreadChannel object if this message has thread attached; otherwise null.

Timestamp

Gets the time this message was sent.

public DateTimeOffset Timestamp { get; }

Property Value

DateTimeOffset

Time of when the message was sent.

Type

Gets the type of this message.

public MessageType Type { get; }

Property Value

MessageType

Methods

AddReactionAsync(IEmote, RequestOptions)

Adds a reaction to this message.

public Task AddReactionAsync(IEmote emote, RequestOptions options = null)

Parameters

emote IEmote

The emoji used to react to this message.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for adding a reaction to this message.

Examples

The following example adds the reaction, 💕, to the message.

await msg.AddReactionAsync(new Emoji("\U0001f495"));
See Also

DeleteAsync(RequestOptions)

Deletes this object and all its children.

public Task DeleteAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

GetReactionUsersAsync(IEmote, int, RequestOptions, ReactionType)

Gets all users that reacted to a message with a given emote.

public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null, ReactionType type = ReactionType.Normal)

Parameters

emote IEmote
limit int

The number of users to request.

options RequestOptions

The options to be used when sending the request.

type ReactionType

The type of the reaction you wish to get users for.

Returns

IAsyncEnumerable<IReadOnlyCollection<IUser>>

Paged collection of users.

Examples

The following example gets the users that have reacted with the emoji 💕 to the message.

var emoji = new Emoji("\U0001f495");
var reactedUsers = await message.GetReactionUsersAsync(emoji, 100).FlattenAsync();

Remarks

important

The returned collection is an asynchronous enumerable object; one must call FlattenAsync<T>(IAsyncEnumerable<IEnumerable<T>>) to access the users as a collection.

warning

Do not fetch too many users at once! This may cause unwanted preemptive rate limit or even actual rate limit, causing your bot to freeze!

This method will attempt to fetch the number of reactions specified under limit. The library will attempt to split up the requests according to your limit and MaxUserReactionsPerBatch. In other words, should the user request 500 reactions, and the MaxUserReactionsPerBatch constant is 100, the request will be split into 5 individual requests; thus returning 5 individual asynchronous responses, hence the need of flattening.

RemoveAllReactionsAsync(RequestOptions)

Removes all reactions from this message.

public Task RemoveAllReactionsAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous removal operation.

RemoveAllReactionsForEmoteAsync(IEmote, RequestOptions)

Removes all reactions with a specific emoji from this message.

public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null)

Parameters

emote IEmote

The emoji used to react to this message.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous removal operation.

RemoveReactionAsync(IEmote, IUser, RequestOptions)

Removes a reaction from message.

public Task RemoveReactionAsync(IEmote emote, IUser user, RequestOptions options = null)

Parameters

emote IEmote

The emoji used to react to this message.

user IUser

The user that added the emoji.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for removing a reaction to this message.

Examples

The following example removes the reaction, 💕, added by the message author from the message.

await msg.RemoveReactionAsync(new Emoji("\U0001f495"), msg.Author);
See Also

RemoveReactionAsync(IEmote, ulong, RequestOptions)

Removes a reaction from message.

public Task RemoveReactionAsync(IEmote emote, ulong userId, RequestOptions options = null)

Parameters

emote IEmote

The emoji used to react to this message.

userId ulong

The ID of the user that added the emoji.

options RequestOptions

The options to be used when sending the request.

Returns

Task

A task that represents the asynchronous operation for removing a reaction to this message.

Examples

The following example removes the reaction, 💕, added by the user with ID 84291986575613952 from the message.

await msg.RemoveReactionAsync(new Emoji("\U0001f495"), 84291986575613952);
See Also

ToString()

Gets the content of the message.

public override string ToString()

Returns

string

Content of the message.