D++ (DPP)
C++ Discord API Bot Library
dpp::message Struct Reference

Represents messages sent and received on Discord. More...

#include <message.h>

+ Inheritance diagram for dpp::message:
+ Collaboration diagram for dpp::message:

Classes

struct  allowed_ref
 Allowed mentions details. More...
 
struct  message_interaction_struct
 Reference to an interaction. More...
 
struct  message_ref
 Reference to another message, e.g. a reply. More...
 

Public Member Functions

 message ()
 Construct a new message object. More...
 
 message (const message &m)=default
 
 message (message &&m)=default
 
 message (class cluster *o)
 Construct a new message object. More...
 
 message (snowflake channel_id, std::string_view content, message_type type=mt_default)
 Construct a new message object with a channel and content. More...
 
 message (const embed &_embed)
 Construct a new message object with content. More...
 
 message (snowflake channel_id, const embed &_embed)
 Construct a new message object with a channel and content. More...
 
 message (std::string_view content, message_type type=mt_default)
 Construct a new message object with content. More...
 
 ~message () override=default
 Destroy the message object. More...
 
messageoperator= (const message &m)=default
 Copy a message object. More...
 
messageoperator= (message &&m)=default
 Move a message object. More...
 
messageset_reference (snowflake _message_id, snowflake _guild_id=0, snowflake _channel_id=0, bool fail_if_not_exists=false, message_ref_type type=mrt_default)
 Set the original message reference for replies/crossposts. More...
 
messageset_allowed_mentions (bool _parse_users=false, bool _parse_roles=false, bool _parse_everyone=false, bool _replied_user=false, const std::vector< snowflake > &users={}, const std::vector< snowflake > &roles={})
 Set the allowed mentions object for pings on the message. More...
 
messagefill_from_json (nlohmann::json *j, cache_policy_t cp)
 
virtual json to_json (bool with_id, bool is_interaction_response) const
 
bool is_crossposted () const
 Returns true if the message was crossposted to other servers. More...
 
bool is_crosspost () const
 Returns true if posted from other servers announcement channel via webhook. More...
 
bool suppress_embeds () const
 True if embeds have been removed. More...
 
messagesuppress_embeds (bool suppress)
 Set whether embeds should be suppressed. More...
 
bool is_source_message_deleted () const
 True if source message was deleted. More...
 
bool is_urgent () const
 True if urgent. More...
 
bool has_thread () const
 True if has thread attached. More...
 
bool is_ephemeral () const
 True if ephemeral (visible only to issuer of a slash command) More...
 
bool is_loading () const
 True if loading. More...
 
bool is_thread_mention_failed () const
 Returns true if this message failed to mention some roles and add their members to the thread. More...
 
bool suppress_notifications () const
 True if the message will not trigger push and desktop notifications. More...
 
bool is_voice_message () const
 True if the message is a voice message. More...
 
messageadd_component (const component &c)
 Add a component (button) to message. More...
 
messageadd_embed (const embed &e)
 Add an embed to message. More...
 
messageadd_sticker (const sticker &s)
 Add a sticker to this message. More...
 
messageadd_sticker (const snowflake &id)
 Add a sticker to this message. More...
 
messageset_flags (uint16_t f)
 Set the flags. More...
 
messageset_type (message_type t)
 Set the message type. More...
 
messageset_filename (std::string_view fn)
 Set the filename of the last file in list. More...
 
messageset_file_content (std::string_view fc)
 Set the file content of the last file in list. More...
 
messageadd_file (std::string_view filename, std::string_view filecontent, std::string_view filemimetype="")
 Add a file to the message. More...
 
messageset_content (std::string_view c)
 Set the message content. More...
 
messageset_channel_id (snowflake _channel_id)
 Set the channel id. More...
 
messageset_guild_id (snowflake _guild_id)
 Set the channel id. More...
 
bool is_dm () const
 Returns true if the message is from a DM. More...
 
bool has_remix_attachment () const
 Returns true if message has remixed attachment. More...
 
std::string get_url () const
 Returns URL to message. More...
 
messageset_poll (const poll &p)
 Convenience method to set the poll. More...
 
const pollget_poll () const
 Convenience method to get the poll attached to this message. More...
 
bool has_poll () const noexcept
 Method to check if the message has a poll. More...
 
constexpr double get_creation_time () const noexcept
 Get the creation time of this object according to Discord. More...
 
constexpr bool operator== (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
constexpr bool operator!= (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
messagefill_from_json (nlohmann::json *j)
 Convert object from nlohmann::json. More...
 
auto to_json (bool with_id=false) const
 Convert object to nlohmann::json. More...
 
std::string build_json (bool with_id=false) const
 Convert object to json string. More...
 

Public Attributes

snowflake channel_id
 ID of the channel the message was sent in. More...
 
snowflake guild_id
 Optional: ID of the guild the message was sent in. More...
 
user author
 The author of this message. More...
 
guild_member member
 Optional: member properties for this message's author. More...
 
std::string content
 Contents of the message. More...
 
std::vector< dpp::componentcomponents
 Message components. More...
 
time_t sent
 When this message was sent. More...
 
time_t edited
 When this message was edited. More...
 
std::vector< std::pair< user, guild_member > > mentions
 Users specifically mentioned in the message. More...
 
std::vector< snowflakemention_roles
 Roles specifically mentioned in this message (only IDs currently). More...
 
std::vector< channelmention_channels
 Channels mentioned in the message. More...
 
std::vector< attachmentattachments
 Any attached files. More...
 
std::vector< embedembeds
 Up to 10 dpp::embed objects. More...
 
std::vector< reactionreactions
 Optional: reactions to the message. More...
 
std::string nonce
 Optional: Used for validating a message was sent. More...
 
snowflake webhook_id
 Optional: Webhook ID. More...
 
std::vector< stickerstickers
 Partial stickers. Only id, name and format_type are filled. More...
 
std::vector< message_file_datafile_data
 An array of file data to use for uploading files. More...
 
struct dpp::message::message_ref message_reference
 
message_snapshot< messagemessage_snapshots
 Message snapshots for a forwarded message. More...
 
struct dpp::message::message_interaction_struct interaction
 
struct dpp::message::allowed_ref allowed_mentions
 
class clusterowner
 The cluster which created this message object. More...
 
message_type type
 Message type. More...
 
uint16_t flags
 Flags made from dpp::message_flags. More...
 
bool pinned
 Whether this message is pinned. More...
 
bool tts
 Whether this was a TTS message. More...
 
bool mention_everyone
 Whether this message mentions everyone. More...
 
std::optional< pollattached_poll
 Optional poll attached to this message. More...
 
snowflake id = {}
 Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata. More...
 

Protected Member Functions

messagefill_from_json_impl (nlohmann::json *j)
 
json to_json_impl (bool with_id=false) const
 

Friends

struct json_interface< message >
 

Detailed Description

Represents messages sent and received on Discord.

Constructor & Destructor Documentation

◆ message() [1/8]

dpp::message::message ( )

Construct a new message object.

◆ message() [2/8]

dpp::message::message ( const message m)
default

◆ message() [3/8]

dpp::message::message ( message &&  m)
default

◆ message() [4/8]

dpp::message::message ( class cluster o)

Construct a new message object.

Parameters
oOwning cluster, passed down to various things such as dpp::attachment. Owning cluster is optional (can be nullptr) and if nulled, will prevent some functions such as attachment::download from functioning (they will throw, if used)

◆ message() [5/8]

dpp::message::message ( snowflake  channel_id,
std::string_view  content,
message_type  type = mt_default 
)

Construct a new message object with a channel and content.

Parameters
channel_idThe channel to send the message to
contentThe content of the message. It will be truncated to the maximum length of 4000 UTF-8 characters.
typeThe message type to create

◆ message() [6/8]

dpp::message::message ( const embed _embed)

Construct a new message object with content.

Parameters
_embedAn embed to send

◆ message() [7/8]

dpp::message::message ( snowflake  channel_id,
const embed _embed 
)

Construct a new message object with a channel and content.

Parameters
channel_idThe channel to send the message to
_embedAn embed to send

◆ message() [8/8]

dpp::message::message ( std::string_view  content,
message_type  type = mt_default 
)

Construct a new message object with content.

Parameters
contentThe content of the message. It will be truncated to the maximum length of 4000 UTF-8 characters.
typeThe message type to create

◆ ~message()

dpp::message::~message ( )
overridedefault

Destroy the message object.

Member Function Documentation

◆ add_component()

message & dpp::message::add_component ( const component c)

Add a component (button) to message.

Parameters
ccomponent to add
Returns
message& reference to self

◆ add_embed()

message & dpp::message::add_embed ( const embed e)

Add an embed to message.

Parameters
eembed to add
Returns
message& reference to self

◆ add_file()

message & dpp::message::add_file ( std::string_view  filename,
std::string_view  filecontent,
std::string_view  filemimetype = "" 
)

Add a file to the message.

Parameters
filenamefilename
filecontentraw file content
filemimetypeoptional mime type of the file
Returns
message& reference to self

◆ add_sticker() [1/2]

message & dpp::message::add_sticker ( const snowflake id)

Add a sticker to this message.

As of writing this, a message can only contain up to 3 stickers

Parameters
idid of the sticker to add
Returns
message& reference to self

◆ add_sticker() [2/2]

message & dpp::message::add_sticker ( const sticker s)

Add a sticker to this message.

As of writing this, a message can only contain up to 3 stickers

Parameters
ssticker to add
Returns
message& reference to self

◆ build_json()

std::string dpp::json_interface< message >::build_json ( bool  with_id = false) const
inlineinherited

Convert object to json string.

Parameters
with_idWhether to include the ID or not
Note
Some fields are conditionally filled, do not rely on all fields being present
Returns
std::string Json built from the structure

◆ fill_from_json() [1/2]

message & dpp::json_interface< message >::fill_from_json ( nlohmann::json *  j)
inlineinherited

Convert object from nlohmann::json.

Parameters
jnlohmann::json object
Returns
T& Reference to self for fluent calling

◆ fill_from_json() [2/2]

message & dpp::message::fill_from_json ( nlohmann::json *  j,
cache_policy_t  cp 
)

Fill this object from json.

Parameters
jJSON object to fill from
cpCache policy for user records, whether or not we cache users when a message is received
Returns
A reference to self

◆ fill_from_json_impl()

message & dpp::message::fill_from_json_impl ( nlohmann::json *  j)
inlineprotected

Read class values from json object

Parameters
jA json object to read from
Returns
A reference to self

◆ get_creation_time()

constexpr double dpp::managed::get_creation_time ( ) const
inlineconstexprnoexceptinherited

Get the creation time of this object according to Discord.

Returns
double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.

◆ get_poll()

const poll & dpp::message::get_poll ( ) const

Convenience method to get the poll attached to this message.

Exceptions
std::bad_optional_accessif has_poll() == false
Returns
const poll& Poll attached to this object

◆ get_url()

std::string dpp::message::get_url ( ) const

Returns URL to message.

Returns
string of URL to message

◆ has_poll()

bool dpp::message::has_poll ( ) const
noexcept

Method to check if the message has a poll.

Returns
bool Whether the message has a poll

◆ has_remix_attachment()

bool dpp::message::has_remix_attachment ( ) const

Returns true if message has remixed attachment.

Returns
true if message has remixed attachment

◆ has_thread()

bool dpp::message::has_thread ( ) const

True if has thread attached.

Returns
true if has thread attached

◆ is_crosspost()

bool dpp::message::is_crosspost ( ) const

Returns true if posted from other servers announcement channel via webhook.

Returns
true if posted from other server

◆ is_crossposted()

bool dpp::message::is_crossposted ( ) const

Returns true if the message was crossposted to other servers.

Returns
true if crossposted

◆ is_dm()

bool dpp::message::is_dm ( ) const

Returns true if the message is from a DM.

Returns
true if message is a DM

◆ is_ephemeral()

bool dpp::message::is_ephemeral ( ) const

True if ephemeral (visible only to issuer of a slash command)

Returns
true if ephemeral

◆ is_loading()

bool dpp::message::is_loading ( ) const

True if loading.

Returns
true if loading

◆ is_source_message_deleted()

bool dpp::message::is_source_message_deleted ( ) const

True if source message was deleted.

Returns
true if source message deleted

◆ is_thread_mention_failed()

bool dpp::message::is_thread_mention_failed ( ) const

Returns true if this message failed to mention some roles and add their members to the thread.

Returns
true if this message failed to mention some roles and add their members to the thread

◆ is_urgent()

bool dpp::message::is_urgent ( ) const

True if urgent.

Returns
true if urgent

◆ is_voice_message()

bool dpp::message::is_voice_message ( ) const

True if the message is a voice message.

Returns
True if voice message

◆ operator!=()

constexpr bool dpp::managed::operator!= ( const managed other) const
inlineconstexprnoexceptinherited

Comparison operator for comparing two managed objects by id.

Parameters
otherOther object to compare against
Returns
true objects are not the same id
false objects are the same id

◆ operator=() [1/2]

message & dpp::message::operator= ( const message m)
default

Copy a message object.

Parameters
mMessage to copy
Returns
message& Reference to self

◆ operator=() [2/2]

message & dpp::message::operator= ( message &&  m)
default

Move a message object.

Parameters
mMessage to move
Returns
message& Reference to self

◆ operator==()

constexpr bool dpp::managed::operator== ( const managed other) const
inlineconstexprnoexceptinherited

Comparison operator for comparing two managed objects by id.

Parameters
otherOther object to compare against
Returns
true objects are the same id
false objects are not the same id

◆ set_allowed_mentions()

message & dpp::message::set_allowed_mentions ( bool  _parse_users = false,
bool  _parse_roles = false,
bool  _parse_everyone = false,
bool  _replied_user = false,
const std::vector< snowflake > &  users = {},
const std::vector< snowflake > &  roles = {} 
)

Set the allowed mentions object for pings on the message.

Parameters
_parse_userswhether or not to parse users in the message content or embeds, default false
_parse_roleswhether or not to parse roles in the message content or embeds, default false
_parse_everyonewhether or not to parse everyone/here in the message content or embeds, default false
_replied_userif set to true and this is a reply, then ping the user we reply to, default false
userslist of user ids to allow pings for, default an empty vector
roleslist of role ids to allow pings for, default an empty vector
Returns
message& reference to self

◆ set_channel_id()

message & dpp::message::set_channel_id ( snowflake  _channel_id)

Set the channel id.

Parameters
_channel_idchannel id
Returns
message& reference to self

◆ set_content()

message & dpp::message::set_content ( std::string_view  c)

Set the message content.

Parameters
cmessage content. It will be truncated to the maximum length of 4000 UTF-8 characters.
Returns
message& reference to self

◆ set_file_content()

message & dpp::message::set_file_content ( std::string_view  fc)

Set the file content of the last file in list.

Parameters
fcraw file content
Returns
message& reference to self
Deprecated:
Use message::add_file instead

◆ set_filename()

message & dpp::message::set_filename ( std::string_view  fn)

Set the filename of the last file in list.

Parameters
fnfilename
Returns
message& reference to self
Deprecated:
Use message::add_file instead

◆ set_flags()

message & dpp::message::set_flags ( uint16_t  f)

Set the flags.

Parameters
fflags to set from dpp::message_flags
Returns
message& reference to self

◆ set_guild_id()

message & dpp::message::set_guild_id ( snowflake  _guild_id)

Set the channel id.

Parameters
_guild_idchannel id
Returns
message& reference to self

◆ set_poll()

message & dpp::message::set_poll ( const poll p)

Convenience method to set the poll.

Returns
message& Self reference for method chaining

◆ set_reference()

message & dpp::message::set_reference ( snowflake  _message_id,
snowflake  _guild_id = 0,
snowflake  _channel_id = 0,
bool  fail_if_not_exists = false,
message_ref_type  type = mrt_default 
)

Set the original message reference for replies/crossposts.

Parameters
_message_idmessage id to reply to
_guild_idguild id to reply to (optional)
_channel_idchannel id to reply to (optional)
fail_if_not_existstrue if the message send should fail if these values are invalid (optional)
typeType of reference
Returns
message& reference to self

◆ set_type()

message & dpp::message::set_type ( message_type  t)

Set the message type.

Parameters
ttype to set
Returns
message& reference to self

◆ suppress_embeds() [1/2]

bool dpp::message::suppress_embeds ( ) const

True if embeds have been removed.

Returns
true if embeds removed

◆ suppress_embeds() [2/2]

message & dpp::message::suppress_embeds ( bool  suppress)

Set whether embeds should be suppressed.

Parameters
suppresswhether embeds should be suppressed
Returns
message& reference to self

◆ suppress_notifications()

bool dpp::message::suppress_notifications ( ) const

True if the message will not trigger push and desktop notifications.

Returns
True if notifications suppressed

◆ to_json() [1/2]

virtual json dpp::message::to_json ( bool  with_id,
bool  is_interaction_response 
) const
virtual

Build JSON from this object.

Parameters
with_idTrue if the ID is to be included in the built JSON
is_interaction_responseSet to true if this message is intended to be included in an interaction response. This will exclude some fields that are not valid in interactions at this time.
Returns
The JSON text of the message

◆ to_json() [2/2]

auto dpp::json_interface< message >::to_json ( bool  with_id = false) const
inlineinherited

Convert object to nlohmann::json.

Parameters
with_idWhether to include the ID or not
Note
Some fields are conditionally filled, do not rely on all fields being present
Returns
json Json built from the structure

◆ to_json_impl()

json dpp::message::to_json_impl ( bool  with_id = false) const
inlineprotected

Build a JSON from this object.

Parameters
with_idTrue if an ID is to be included in the JSON
Returns
JSON

Friends And Related Function Documentation

◆ json_interface< message >

friend struct json_interface< message >
friend

Member Data Documentation

◆ allowed_mentions

struct dpp::message::allowed_ref dpp::message::allowed_mentions

◆ attached_poll

std::optional<poll> dpp::message::attached_poll

Optional poll attached to this message.

◆ attachments

std::vector<attachment> dpp::message::attachments

Any attached files.

◆ author

user dpp::message::author

The author of this message.

Warning
This is not guaranteed to be a valid user.

◆ channel_id

snowflake dpp::message::channel_id

ID of the channel the message was sent in.

◆ components

std::vector<dpp::component> dpp::message::components

Message components.

◆ content

std::string dpp::message::content

Contents of the message.

◆ edited

time_t dpp::message::edited

When this message was edited.

Note
This may be 0 if never edited.

◆ embeds

std::vector<embed> dpp::message::embeds

Up to 10 dpp::embed objects.

◆ file_data

std::vector<message_file_data> dpp::message::file_data

An array of file data to use for uploading files.

Note
You should use dpp::message::add_file to add data to this!

◆ flags

uint16_t dpp::message::flags

Flags made from dpp::message_flags.

◆ guild_id

snowflake dpp::message::guild_id

Optional: ID of the guild the message was sent in.

◆ id

snowflake dpp::managed::id = {}
inherited

Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.

◆ interaction

struct dpp::message::message_interaction_struct dpp::message::interaction

◆ member

guild_member dpp::message::member

Optional: member properties for this message's author.

◆ mention_channels

std::vector<channel> dpp::message::mention_channels

Channels mentioned in the message.

Warning
Not all types supported.
Note
Discord: Only textual channels that are visible to everyone in a lurkable guild will ever be included. Only crossposted messages (via Channel Following) currently include mention_channels at all. (includes ID, Guild ID, Type, Name).

◆ mention_everyone

bool dpp::message::mention_everyone

Whether this message mentions everyone.

◆ mention_roles

std::vector<snowflake> dpp::message::mention_roles

Roles specifically mentioned in this message (only IDs currently).

◆ mentions

std::vector<std::pair<user, guild_member> > dpp::message::mentions

Users specifically mentioned in the message.

◆ message_reference

struct dpp::message::message_ref dpp::message::message_reference

◆ message_snapshots

message_snapshot<message> dpp::message::message_snapshots

Message snapshots for a forwarded message.

◆ nonce

std::string dpp::message::nonce

Optional: Used for validating a message was sent.

◆ owner

class cluster* dpp::message::owner

The cluster which created this message object.

◆ pinned

bool dpp::message::pinned

Whether this message is pinned.

◆ reactions

std::vector<reaction> dpp::message::reactions

Optional: reactions to the message.

◆ sent

time_t dpp::message::sent

When this message was sent.

◆ stickers

std::vector<sticker> dpp::message::stickers

Partial stickers. Only id, name and format_type are filled.

◆ tts

bool dpp::message::tts

Whether this was a TTS message.

◆ type

message_type dpp::message::type

Message type.

◆ webhook_id

snowflake dpp::message::webhook_id

Optional: Webhook ID.

Note
If the message is generated by a webhook, its ID will be here. Otherwise, the field will be 0.
D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0