D++ (DPP)  10.0.30
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. More...
 

Public Member Functions

 message ()
 Construct a new message object. More...
 
 message (class cluster *o)
 Construct a new message object. More...
 
 message (const embed &_embed)
 Construct a new message object with content. More...
 
 message (const message &m)=default
 
 message (const std::string &content, message_type type=mt_default)
 Construct a new message object with content. More...
 
 message (message &&m)=default
 
 message (snowflake channel_id, const embed &_embed)
 Construct a new message object with a channel and content. More...
 
 message (snowflake channel_id, const std::string &content, message_type type=mt_default)
 Construct a new message object with a channel and content. More...
 
 ~message () override=default
 Destroy the message object. 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_file (const std::string &filename, const std::string &filecontent, const std::string &filemimetype="")
 Add a file to the message. More...
 
messageadd_sticker (const snowflake &id)
 Add a sticker to this message. More...
 
messageadd_sticker (const sticker &s)
 Add a sticker to this message. More...
 
std::string build_json (bool with_id=false) const
 Convert object to json string. More...
 
messagefill_from_json (nlohmann::json *j)
 Convert object from nlohmann::json. More...
 
messagefill_from_json (nlohmann::json *j, cache_policy_t cp)
 Fill this object from json. More...
 
constexpr double get_creation_time () const noexcept
 Get the creation time of this object according to Discord. More...
 
const pollget_poll () const
 Convenience method to get the poll attached to this message. More...
 
std::string get_url () const
 Returns URL to message. More...
 
bool has_poll () const noexcept
 Method to check if the message has a poll. More...
 
bool has_remix_attachment () const
 Returns true if message has remixed attachment. More...
 
bool has_thread () const
 True if has thread attached. More...
 
bool is_crosspost () const
 Returns true if posted from other servers announcement channel via webhook. More...
 
bool is_crossposted () const
 Returns true if the message was crossposted to other servers. More...
 
bool is_dm () const
 Returns true if the message is from a DM. 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_source_message_deleted () const
 True if source message was deleted. 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 is_urgent () const
 True if urgent. More...
 
bool is_voice_message () const
 True if the message is a voice message. More...
 
constexpr bool operator!= (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
messageoperator= (const message &m)=default
 Copy a message object. More...
 
messageoperator= (message &&m)=default
 Move a message object. More...
 
constexpr bool operator== (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. 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...
 
messageset_channel_id (snowflake _channel_id)
 Set the channel id. More...
 
messageset_content (const std::string &c)
 Set the message content. More...
 
messageset_file_content (const std::string &fc)
 Set the file content of the last file in list. More...
 
messageset_filename (const std::string &fn)
 Set the filename of the last file in list. More...
 
messageset_flags (uint16_t f)
 Set the flags. More...
 
messageset_guild_id (snowflake _guild_id)
 Set the channel id. More...
 
messageset_poll (const poll &p)
 Convenience method to set the poll. More...
 
messageset_reference (snowflake _message_id, snowflake _guild_id=0, snowflake _channel_id=0, bool fail_if_not_exists=false)
 Set the original message reference for replies/crossposts. More...
 
messageset_type (message_type t)
 Set the message type. More...
 
bool suppress_embeds () const
 True if embeds have been removed. More...
 
messagesuppress_embeds (bool suppress)
 Set whether embeds should be suppressed. More...
 
bool suppress_notifications () const
 True if the message will not trigger push and desktop notifications. More...
 
virtual json to_json (bool with_id, bool is_interaction_response) const
 Build JSON from this object. More...
 
auto to_json (bool with_id=false) const
 Convert object to nlohmann::json. More...
 

Public Attributes

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

Protected Member Functions

messagefill_from_json_impl (nlohmann::json *j)
 Read class values from json object. More...
 
json to_json_impl (bool with_id=false) const
 Build a JSON from this object. More...
 

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,
const std::string &  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 ( const std::string &  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

References dpp::int32_not_null().

Here is the call graph for this function:

◆ ~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

References flags.

◆ add_embed()

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

Add an embed to message.

Parameters
eembed to add
Returns
message& reference to self

References type.

◆ add_file()

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

Add a file to the message.

Parameters
filenamefilename
filecontentraw file content contained in std::string
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

References file_data, and dpp::message_file_data::name.

◆ 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

References dpp::json_interface< T >::fill_from_json(), and dpp::sticker::sticker_user.

Here is the call graph for this function:

◆ 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

References flags, and dpp::m_is_voice_message.

◆ 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

References dpp::snowflake_not_null().

Here is the call graph for this function:

◆ 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

References flags, and dpp::m_thread_mention_failed.

◆ 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

References flags, and dpp::m_suppress_notifications.

◆ is_voice_message()

bool dpp::message::is_voice_message ( ) const

True if the message is a voice message.

Returns
True if voice message

References dpp::cp_none, and dpp::cache_policy_t::user_policy.

◆ 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

References attached_poll.

◆ set_content()

message & dpp::message::set_content ( const std::string &  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

Referenced by event_handler_test().

Here is the caller graph for this function:

◆ set_file_content()

message & dpp::message::set_file_content ( const std::string &  fc)

Set the file content of the last file in list.

Parameters
fcraw file content contained in std::string
Returns
message& reference to self
Deprecated:
Use message::add_file instead

◆ set_filename()

message & dpp::message::set_filename ( const std::string &  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 
)

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)
Returns
message& reference to self

Referenced by dpp::message_create_t::send().

Here is the caller graph for this function:

◆ set_type()

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

Set the message type.

Parameters
ttype to set
Returns
message& reference to self

References dpp::message_file_data::content, and file_data.

◆ 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]

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

References dpp::message::message_ref::channel_id, dpp::message::message_ref::fail_if_not_exists, dpp::message::message_ref::guild_id, dpp::message::message_ref::message_id, and message_reference.

◆ 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.

Referenced by set_channel_id().

◆ 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.

Referenced by event_handler_test(), dpp::attachment::get_issued_time(), and dpp::message_create_t::send().

◆ components

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

Message components.

◆ content

std::string dpp::message::content

Contents of the message.

Referenced by event_handler_test().

◆ 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!

Referenced by add_sticker(), and set_type().

◆ flags

uint16_t dpp::message::flags

◆ guild_id

snowflake dpp::message::guild_id

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

Referenced by dpp::commandhandler::route(), and dpp::commandhandler::string_has_prefix().

◆ id

◆ 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

Referenced by to_json().

◆ 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.

Referenced by add_embed().

◆ 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.

The documentation for this struct was generated from the following files: