Skip to main content

CreateMessage

Struct CreateMessage 

Source
#[non_exhaustive]
pub struct CreateMessage {
Show 14 fields pub content: Option<CompactString>, pub nonce: Option<Nonce>, pub tts: bool, pub embeds: Vec<Embed>, pub allowed_mentions: Option<AllowedMentions>, pub message_reference: Option<MessageReference>, pub components: Vec<Component>, pub sticker_ids: Vec<StickerId>, pub attachments: Option<Vec<AttachmentRequest>>, pub flags: Option<MessageFlags>, pub enforce_nonce: bool, pub poll: Option<CreatePoll>, pub shared_client_theme: Option<SharedClientTheme>, pub files: Vec<FileUpload>,
}
Expand description

The body of Create Message (POST /channels/{channel.id}/messages).

At least one of content, embeds, sticker_ids, components, files, poll or shared_client_theme must be set; a forward needs only message_reference. With MessageFlags::IS_COMPONENTS_V2, only components (and files) may be set.

Every file in files gets its attachments entry automatically (D-094), and the request is then sent as multipart/form-data.

discord.js counterpart: MessageCreateOptions / RESTPostAPIChannelMessageJSONBody.

§Examples

use djs_model::rest::{CreateMessage, FileUpload};

let body = CreateMessage::from("Pong!");
assert_eq!(serde_json::to_string(&body).unwrap(), r#"{"content":"Pong!"}"#);

let body = CreateMessage::from("A log").file(FileUpload::new("log.txt", "line 1\nline 2\n"));
assert_eq!(
    serde_json::to_string(&body).unwrap(),
    r#"{"content":"A log","attachments":[{"id":0,"filename":"log.txt"}]}"#
);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§content: Option<CompactString>

The text (up to 2000 characters).

§nonce: Option<Nonce>

A value to recognize the message in its MESSAGE_CREATE event (up to 25 characters).

§tts: bool

Whether the message is read aloud (needs SEND_TTS_MESSAGES).

§embeds: Vec<Embed>

Up to 10 rich embeds (up to 6000 characters in total).

§allowed_mentions: Option<AllowedMentions>

Which mentions in the content notify.

§message_reference: Option<MessageReference>

The message to reply to or forward.

§components: Vec<Component>

The components.

§sticker_ids: Vec<StickerId>

Up to 3 stickers of the guild to send.

§attachments: Option<Vec<AttachmentRequest>>

Explicit attachment entries. Usually left out: every file gets one automatically, unless an entry with its files[n] index is listed here.

§flags: Option<MessageFlags>§enforce_nonce: bool

With a nonce: if the same author sent a message with the same nonce in the last few minutes, that message is returned instead of creating a new one.

§poll: Option<CreatePoll>

A poll to create with the message.

§shared_client_theme: Option<SharedClientTheme>

A client theme to share through the message.

§files: Vec<FileUpload>

Files to upload with the message (D-087).

Implementations§

Source§

impl CreateMessage

Source

pub fn content(self, content: impl Into<CompactString>) -> Self

Sets the text (up to 2000 characters).

discord.js counterpart: the content option.

Source

pub fn embed(self, embed: Embed) -> Self

Adds an embed after the ones set before (up to 10, 6000 characters in all; check them with djs_builders::validate_embeds).

discord.js counterpart: an item of the embeds option.

Source

pub fn embeds(self, embeds: impl IntoIterator<Item = Embed>) -> Self

Replaces the embeds. When editing a message (or updating it from a component), an empty list removes its embeds, while not calling this keeps them.

discord.js counterpart: the embeds option.

Source

pub fn component(self, component: impl Into<Component>) -> Self

Adds a top-level component (an action row, or a Components V2 item with the IS_COMPONENTS_V2 flag) after the ones set before.

discord.js counterpart: an item of the components option.

Source

pub fn components(self, components: impl IntoIterator<Item = Component>) -> Self

Replaces the top-level components. When editing a message (or updating it from a component), an empty list removes its components, while not calling this keeps them.

discord.js counterpart: the components option.

Source

pub fn allowed_mentions(self, mentions: AllowedMentions) -> Self

Sets which mentions of the text notify their targets.

discord.js counterpart: the allowedMentions option.

Source

pub fn no_mentions(self) -> Self

Lets no mention notify anyone: no @everyone, role or user ping, whatever the text contains. The safe choice for text that comes from users.

discord.js counterpart: allowedMentions: { parse: [] }.

Source

pub fn flags(self, flags: MessageFlags) -> Self

Replaces the message flags (only some can be sent; see MessageFlags).

discord.js counterpart: the flags option.

Source

pub fn suppress_embeds(self) -> Self

Hides the embeds Discord would generate for the links in the text (adds SUPPRESS_EMBEDS to the flags).

discord.js counterpart: flags: MessageFlags.SuppressEmbeds.

Source

pub fn suppress_notifications(self) -> Self

Sends the message without push and desktop notifications (adds SUPPRESS_NOTIFICATIONS to the flags; “@silent” in the client).

discord.js counterpart: flags: MessageFlags.SuppressNotifications.

Source

pub fn file(self, file: FileUpload) -> Self

Attaches a file, after the ones set before.

discord.js counterpart: an item of the files option.

Source

pub fn files(self, files: impl IntoIterator<Item = FileUpload>) -> Self

Replaces the attached files.

discord.js counterpart: the files option.

Source

pub fn attachments( self, attachments: impl IntoIterator<Item = AttachmentRequest>, ) -> Self

Sets the attachment metadata: descriptions of the uploaded files, or, when editing, the existing attachments to keep (an empty list removes them all).

discord.js counterpart: the attachments option.

Source

pub fn poll(self, poll: CreatePoll) -> Self

Attaches a poll.

discord.js counterpart: the poll option.

Source

pub const fn tts(self, tts: bool) -> Self

Sets whether the message is read aloud (needs SEND_TTS_MESSAGES).

discord.js counterpart: the tts option.

Source§

impl CreateMessage

The setters of the fields only CreateMessage has (D-290).

Source

pub const fn reply_to(self, message_id: MessageId) -> Self

Makes the message a reply to message_id, in the same channel.

discord.js counterpart: reply: { messageReference }.

Source

pub fn message_reference(self, reference: MessageReference) -> Self

Sets the message this one replies to or forwards.

discord.js counterpart: the reply and forward options.

Source

pub fn sticker(self, sticker_id: StickerId) -> Self

Adds a sticker of the guild, after the ones set before (up to 3).

discord.js counterpart: an item of the stickers option.

Source

pub fn stickers(self, sticker_ids: impl IntoIterator<Item = StickerId>) -> Self

Replaces the stickers (up to 3 of the guild’s).

discord.js counterpart: the stickers option.

Source

pub fn nonce(self, nonce: Nonce, enforce: bool) -> Self

Sets a value to recognize the message in its MESSAGE_CREATE event; with enforce, a message with the same nonce sent by the same author in the last few minutes is returned instead of creating a new one.

discord.js counterpart: the nonce and enforceNonce options.

Source

pub fn shared_client_theme(self, theme: SharedClientTheme) -> Self

Shares a client theme through the message.

discord.js counterpart: none (not in discord.js v14).

Trait Implementations§

Source§

impl Clone for CreateMessage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CreateMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CreateMessage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&str> for CreateMessage

Source§

fn from(content: &str) -> Self

Converts to this type from the input type.
Source§

impl From<CompactString> for CreateMessage

Source§

fn from(content: CompactString) -> Self

Converts to this type from the input type.
Source§

impl From<String> for CreateMessage

Source§

fn from(content: String) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for CreateMessage

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CreateMessage

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CreateMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.