Class RestMessage
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
jsonModelJsonMessageclientRestClient
Properties
Activity
Sent with Rich Presence-related chat embeds.
public MessageActivity? Activity { get; }
Property Value
Application
Sent with Rich Presence-related chat embeds.
public Application? Application { get; }
Property Value
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
Attachments
A list containing the message's attachments.
public IReadOnlyList<Attachment> Attachments { get; }
Property Value
Author
The User object of the message's author.
public User Author { get; }
Property Value
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
ChannelId
The ID of the channel the message was sent in.
public ulong ChannelId { get; }
Property Value
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
Content
The text contents of the message.
public string Content { get; }
Property Value
EditedAt
If the message has been edited, contains the timestamp of the latest edit, otherwise null.
public DateTimeOffset? EditedAt { get; }
Property Value
Embeds
A list of Embed objects, representing any embedded content present in the message.
public IReadOnlyList<Embed> Embeds { get; }
Property Value
Flags
A MessageFlags object indicating the message's applied flags.
public MessageFlags Flags { get; }
Property Value
Id
The ID of the message.
public override ulong Id { get; }
Property Value
Interaction
Sent if the message is a response to an interaction.
[Obsolete("Replaced by 'InteractionMetadata'")]
public MessageInteraction? Interaction { get; }
Property Value
InteractionMetadata
Sent if the message is sent as a result of an interaction.
public MessageInteractionMetadata? InteractionMetadata { get; }
Property Value
IsPinned
Whether this message is pinned in a channel.
public bool IsPinned { get; }
Property Value
IsTts
Whether the message was a Text-To-Speech message.
public bool IsTts { get; }
Property Value
MentionEveryone
Whether the message mentions @everyone.
public bool MentionEveryone { get; }
Property Value
MentionedChannels
A list of GuildChannelMention objects indexed by their IDs, containing channels specifically mentioned in the message.
public IReadOnlyList<GuildChannelMention> MentionedChannels { get; }
Property Value
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
MentionedUsers
A list of users specifically mentioned in the message.
public IReadOnlyList<User> MentionedUsers { get; }
Property Value
MessageReference
Contains data showing the source of a crosspost, channel follow add, pin, or message reply.
public MessageReference? MessageReference { get; }
Property Value
MessageSnapshots
A list of messages associated with the message reference.
public IReadOnlyList<MessageSnapshot> MessageSnapshots { get; }
Property Value
Nonce
Used for validating that a message was sent.
public string? Nonce { get; }
Property Value
Poll
The message's contained poll, if it has one, otherwise null.
public MessagePoll? Poll { get; }
Property Value
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
ReferencedMessage
The message associated with the MessageReference.
public RestMessage? ReferencedMessage { get; }
Property Value
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
RoleSubscriptionData
Contains information about the role subscription purchase or renewal that prompted this RoleSubscriptionPurchase message.
public RoleSubscriptionData? RoleSubscriptionData { get; }
Property Value
SharedClientTheme
The custom client-side theme shared in the message, if any.
public SharedClientTheme? SharedClientTheme { get; }
Property Value
StartedThread
The GuildThread that was started from this message, if any.
public GuildThread? StartedThread { get; }
Property Value
Stickers
A list of stickers sent within the message.
public IReadOnlyList<MessageSticker> Stickers { get; }
Property Value
Type
The type of the message.
public MessageType Type { get; }
Property Value
WebhookId
public ulong? WebhookId { get; }
Property Value
Methods
AddReactionAsync(ReactionEmojiProperties, RestRequestProperties?, CancellationToken)
Adds a reaction to a specific message.
public Task AddReactionAsync(ReactionEmojiProperties emoji, RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
emojiReactionEmojiPropertiesThe emoji to use as the reaction.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
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
threadFromMessagePropertiesGuildThreadFromMessagePropertiesThe properties of the thread to create.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
CrosspostAsync(RestRequestProperties?, CancellationToken)
Crossposts a message from an announcement channel to subscribed channels.
public Task<RestMessage> CrosspostAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
DeleteAllReactionsAsync(RestRequestProperties?, CancellationToken)
Removes all reactions from a message.
public Task DeleteAllReactionsAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
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
emojiReactionEmojiPropertiesThe emoji to remove from all users.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
DeleteAsync(RestRequestProperties?, CancellationToken)
Deletes a specific message from a channel.
public Task DeleteAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
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
emojiReactionEmojiPropertiesThe emoji to remove as a reaction.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
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
emojiReactionEmojiPropertiesThe emoji to remove as a reaction.
userIdulongThe ID of the user whose reaction will be removed.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
EndPollAsync(RestRequestProperties?, CancellationToken)
public Task<RestMessage> EndPollAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiescancellationTokenCancellationToken
Returns
GetAsync(RestRequestProperties?, CancellationToken)
Retrieves a message from a channel by its ID.
public Task<RestMessage> GetAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
GetPollAnswerVotersAsync(int, PaginationProperties<ulong>?, RestRequestProperties?)
public IAsyncEnumerable<User> GetPollAnswerVotersAsync(int answerId, PaginationProperties<ulong>? paginationProperties = null, RestRequestProperties? properties = null)
Parameters
answerIdintpaginationPropertiesPaginationProperties<ulong>propertiesRestRequestProperties
Returns
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
emojiReactionEmojiPropertiesThe emoji to filter reactions by.
paginationPropertiesMessageReactionsPaginationPropertiesPagination options for fetching users, or null to use defaults.
propertiesRestRequestPropertiesOptional properties to customize each request, can be null.
Returns
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
actionAction<MessageOptions>An action that sets the new message properties.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
PinAsync(RestRequestProperties?, CancellationToken)
Pins a message in a channel.
public Task PinAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
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
replyMessageReplyMessagePropertiesThe message to reply with.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
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
messageMessagePropertiesThe content and properties of the message to send.
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
UnpinAsync(RestRequestProperties?, CancellationToken)
Unpins a message from a channel.
public Task UnpinAsync(RestRequestProperties? properties = null, CancellationToken cancellationToken = default)
Parameters
propertiesRestRequestPropertiesOptional properties to customize the request, can be null.
cancellationTokenCancellationTokenA token that can be used to cancel the operation before it completes.
Returns
Remarks
Requires the PinMessages permission. Fires a ChannelPinsUpdate event.