Table of Contents

Class RestMessage

Namespace
NetCord.Rest
Assembly
NetCord.dll

Represents a message sent in a channel within Discord.

public class RestMessage : ClientEntity, IEntity, ISpanFormattable, IFormattable, IEquatable<Entity>, IJsonModel<JsonMessage>
Inheritance
RestMessage
Implements
Derived
Inherited Members

Constructors

RestMessage(JsonMessage, RestClient)

public RestMessage(JsonMessage jsonModel, RestClient client)

Parameters

jsonModel JsonMessage
client RestClient

Properties

Activity

Sent with Rich Presence-related chat embeds.

public MessageActivity? Activity { get; }

Property Value

MessageActivity

Application

Sent with Rich Presence-related chat embeds.

public Application? Application { get; }

Property Value

Application

ApplicationId

If the message is an Interaction response/followup or an application-owned Webhook, the ID of the Application.

public ulong? ApplicationId { get; }

Property Value

ulong?

Attachments

A list containing the message's attachments.

public IReadOnlyList<Attachment> Attachments { get; }

Property Value

IReadOnlyList<Attachment>

Author

The User object of the message's author.

public User Author { get; }

Property Value

User

Remarks

If the message is generated by a Webhook, the User object will correspond to the webhook's ID, username, and avatar.

Call

The call associated with the message, if any.

public MessageCall? Call { get; }

Property Value

MessageCall

ChannelId

The ID of the channel the message was sent in.

public ulong ChannelId { get; }

Property Value

ulong

Components

A list of IMessageComponent objects, contains components like Buttons, ActionRows, or other interactive components if any are present.

public IReadOnlyList<IMessageComponent> Components { get; }

Property Value

IReadOnlyList<IMessageComponent>

Content

The text contents of the message.

public string Content { get; }

Property Value

string

EditedAt

If the message has been edited, contains the timestamp of the latest edit, otherwise null.

public DateTimeOffset? EditedAt { get; }

Property Value

DateTimeOffset?

Embeds

A list of Embed objects, representing any embedded content present in the message.

public IReadOnlyList<Embed> Embeds { get; }

Property Value

IReadOnlyList<Embed>

Flags

A MessageFlags object indicating the message's applied flags.

public MessageFlags Flags { get; }

Property Value

MessageFlags

Id

The ID of the message.

public override ulong Id { get; }

Property Value

ulong

Interaction

Sent if the message is a response to an interaction.

[Obsolete("Replaced by 'InteractionMetadata'")]
public MessageInteraction? Interaction { get; }

Property Value

MessageInteraction

InteractionMetadata

Sent if the message is sent as a result of an interaction.

public MessageInteractionMetadata? InteractionMetadata { get; }

Property Value

MessageInteractionMetadata

IsPinned

Whether this message is pinned in a channel.

public bool IsPinned { get; }

Property Value

bool

IsTts

Whether the message was a Text-To-Speech message.

public bool IsTts { get; }

Property Value

bool

MentionEveryone

Whether the message mentions @everyone.

public bool MentionEveryone { get; }

Property Value

bool

MentionedChannels

A list of GuildChannelMention objects indexed by their IDs, containing channels specifically mentioned in the message.

public IReadOnlyList<GuildChannelMention> MentionedChannels { get; }

Property Value

IReadOnlyList<GuildChannelMention>

Remarks

This list is only populated for messages with the Crossposted flag set.

Only text channels visible to everyone in a lurkable guild will ever be included.

MentionedRoleIds

A list of IDs corresponding to roles specifically mentioned in the message.

public IReadOnlyList<ulong> MentionedRoleIds { get; }

Property Value

IReadOnlyList<ulong>

MentionedUsers

A list of users specifically mentioned in the message.

public IReadOnlyList<User> MentionedUsers { get; }

Property Value

IReadOnlyList<User>

MessageReference

Contains data showing the source of a crosspost, channel follow add, pin, or message reply.

public MessageReference? MessageReference { get; }

Property Value

MessageReference

MessageSnapshots

A list of messages associated with the message reference.

public IReadOnlyList<MessageSnapshot> MessageSnapshots { get; }

Property Value

IReadOnlyList<MessageSnapshot>

Nonce

Used for validating that a message was sent.

public string? Nonce { get; }

Property Value

string

Poll

The message's contained poll, if it has one, otherwise null.

public MessagePoll? Poll { get; }

Property Value

MessagePoll

Remarks

This is always null if the MessageContent intent is not set.

Position

A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a GuildThread.

public int? Position { get; }

Property Value

int?

Remarks

It can be used to estimate the relative position of the message in a thread in tandem with the TotalMessageSent property of the parent thread.

Reactions

A list of MessageReaction objects, representing all reactions to the message.

public IReadOnlyList<MessageReaction> Reactions { get; }

Property Value

IReadOnlyList<MessageReaction>

ReferencedMessage

The message associated with the MessageReference.

public RestMessage? ReferencedMessage { get; }

Property Value

RestMessage

Remarks

This field is only returned for messages with a MessageType of Reply or ThreadStarterMessage. If the message is a reply but the ReferencedMessage field is not present, the backend did not attempt to fetch the message that was being replied to, so its state is unknown. If the field exists but is null, the referenced message was deleted.

ResolvedData

Contains information about the User, GuildUser, IGuildChannel, and Role objects in the message's auto-populated selection menus.

public InteractionResolvedData? ResolvedData { get; }

Property Value

InteractionResolvedData

RoleSubscriptionData

Contains information about the role subscription purchase or renewal that prompted this RoleSubscriptionPurchase message.

public RoleSubscriptionData? RoleSubscriptionData { get; }

Property Value

RoleSubscriptionData

SharedClientTheme

The custom client-side theme shared in the message, if any.

public SharedClientTheme? SharedClientTheme { get; }

Property Value

SharedClientTheme

StartedThread

The GuildThread that was started from this message, if any.

public GuildThread? StartedThread { get; }

Property Value

GuildThread

Stickers

A list of stickers sent within the message.

public IReadOnlyList<MessageSticker> Stickers { get; }

Property Value

IReadOnlyList<MessageSticker>

Type

The type of the message.

public MessageType Type { get; }

Property Value

MessageType

WebhookId

If the message was generated by a Webhook, contains the webhook's ID, otherwise null.

public ulong? WebhookId { get; }

Property Value

ulong?

Methods

AddReactionAsync(ReactionEmojiProperties, RestRequestProperties?, CancellationToken)

Adds a reaction to a specific message.

public Task AddReactionAsync(ReactionEmojiProperties emoji, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

emoji ReactionEmojiProperties

The emoji to use as the reaction.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

CreateGuildThreadAsync(GuildThreadFromMessageProperties, RestRequestProperties?, CancellationToken)

Creates a thread from an existing message in a text channel.

public Task<GuildThread> CreateGuildThreadAsync(GuildThreadFromMessageProperties threadFromMessageProperties, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

threadFromMessageProperties GuildThreadFromMessageProperties

The properties of the thread to create.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<GuildThread>

CrosspostAsync(RestRequestProperties?, CancellationToken)

Crossposts a message from an announcement channel to subscribed channels.

public Task<RestMessage> CrosspostAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

DeleteAllReactionsAsync(RestRequestProperties?, CancellationToken)

Removes all reactions from a message.

public Task DeleteAllReactionsAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

DeleteAllReactionsForEmojiAsync(ReactionEmojiProperties, RestRequestProperties?, CancellationToken)

Removes all reactions of a specific emoji from a message.

public Task DeleteAllReactionsForEmojiAsync(ReactionEmojiProperties emoji, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

emoji ReactionEmojiProperties

The emoji to remove from all users.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

DeleteAsync(RestRequestProperties?, CancellationToken)

Deletes a specific message from a channel.

public Task DeleteAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

DeleteCurrentUserReactionAsync(ReactionEmojiProperties, RestRequestProperties?, CancellationToken)

Removes the current user's reaction from a specific message.

public Task DeleteCurrentUserReactionAsync(ReactionEmojiProperties emoji, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

emoji ReactionEmojiProperties

The emoji to remove as a reaction.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

DeleteUserReactionAsync(ReactionEmojiProperties, ulong, RestRequestProperties?, CancellationToken)

Removes a specific user's reaction from a message.

public Task DeleteUserReactionAsync(ReactionEmojiProperties emoji, ulong userId, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

emoji ReactionEmojiProperties

The emoji to remove as a reaction.

userId ulong

The ID of the user whose reaction will be removed.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

EndPollAsync(RestRequestProperties?, CancellationToken)

public Task<RestMessage> EndPollAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties
cancellationToken CancellationToken

Returns

Task<RestMessage>

GetAsync(RestRequestProperties?, CancellationToken)

Retrieves a message from a channel by its ID.

public Task<RestMessage> GetAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

GetPollAnswerVotersAsync(int, PaginationProperties<ulong>?, RestRequestProperties?)

public IAsyncEnumerable<User> GetPollAnswerVotersAsync(int answerId, PaginationProperties<ulong>? paginationProperties = null, RestRequestProperties? properties = null)

Parameters

answerId int
paginationProperties PaginationProperties<ulong>
properties RestRequestProperties

Returns

IAsyncEnumerable<User>

GetReactionsAsync(ReactionEmojiProperties, MessageReactionsPaginationProperties?, RestRequestProperties?)

Retrieves a paginated list of users who reacted to a message with a specific emoji.

public IAsyncEnumerable<User> GetReactionsAsync(ReactionEmojiProperties emoji, MessageReactionsPaginationProperties? paginationProperties = null, RestRequestProperties? properties = null)

Parameters

emoji ReactionEmojiProperties

The emoji to filter reactions by.

paginationProperties MessageReactionsPaginationProperties

Pagination options for fetching users, or null to use defaults.

properties RestRequestProperties

Optional properties to customize each request, can be null.

Returns

IAsyncEnumerable<User>

ModifyAsync(Action<MessageOptions>, RestRequestProperties?, CancellationToken)

Modifies the properties of a specific message.

public Task<RestMessage> ModifyAsync(Action<MessageOptions> action, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

action Action<MessageOptions>

An action that sets the new message properties.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

PinAsync(RestRequestProperties?, CancellationToken)

Pins a message in a channel.

public Task PinAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

Remarks

Requires the PinMessages permission. Fires a ChannelPinsUpdate event.

ReplyAsync(ReplyMessageProperties, RestRequestProperties?, CancellationToken)

Replies to the message, returning the resulting reply.

public Task<RestMessage> ReplyAsync(ReplyMessageProperties replyMessage, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

replyMessage ReplyMessageProperties

The message to reply with.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

SendAsync(MessageProperties, RestRequestProperties?, CancellationToken)

Sends a new message to the specified text channel.

public Task<RestMessage> SendAsync(MessageProperties message, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

message MessageProperties

The content and properties of the message to send.

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task<RestMessage>

UnpinAsync(RestRequestProperties?, CancellationToken)

Unpins a message from a channel.

public Task UnpinAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)

Parameters

properties RestRequestProperties

Optional properties to customize the request, can be null.

cancellationToken CancellationToken

A token that can be used to cancel the operation before it completes.

Returns

Task

Remarks

Requires the PinMessages permission. Fires a ChannelPinsUpdate event.