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 (class cluster *o)
 Construct a new message object. More...
 
virtual ~message ()
 Destroy the message object. 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 (snowflake channel_id, const embed &_embed)
 Construct a new message object with a channel and content. More...
 
 message (const std::string &content, message_type type=mt_default)
 Construct a new message object with content. 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_allowed_mentions (bool _parse_users, bool _parse_roles, bool _parse_everyone, bool _replied_user, 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={cp_aggressive, cp_aggressive, cp_aggressive})
 
std::string build_json (bool with_id=false, bool is_interaction_response=false) 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 news channel via webhook. More...
 
bool suppress_embeds () const
 True if embeds have been removed. 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...
 
messageadd_component (const component &c)
 Add a component (button) to message. More...
 
messageadd_embed (const embed &e)
 Add an embed to message. More...
 
messageset_flags (uint8_t f)
 Set the flags. More...
 
messageset_type (message_type t)
 Set the message type. More...
 
messageset_filename (const std::string &fn)
 Set the filename of the last file in list. More...
 
messageset_file_content (const std::string &fc)
 Set the file content of the last file in list. More...
 
messageadd_file (const std::string &filename, const std::string &filecontent)
 Add a file to the message. More...
 
messageset_content (const std::string &c)
 Set the message content. More...
 
double get_creation_time () const
 Get the creation time of this object according to Discord. More...
 
bool operator== (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
bool operator!= (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 

Public Attributes

snowflake channel_id
 
snowflake guild_id
 
user author
 
guild_member member
 
std::string content
 
std::vector< dpp::componentcomponents
 
time_t sent
 
time_t edited
 
bool tts
 
bool mention_everyone
 
std::vector< std::pair< user, guild_member > > mentions
 
std::vector< snowflakemention_roles
 
std::vector< channelmention_channels
 
std::vector< attachmentattachments
 
std::vector< embedembeds
 
std::vector< reactionreactions
 
std::string nonce
 
bool pinned
 
snowflake webhook_id
 
uint8_t flags
 
std::vector< stickerstickers
 
std::vector< std::string > filename
 
std::vector< std::string > filecontent
 
message_type type
 
struct dpp::message::message_ref message_reference
 
struct dpp::message::message_interaction_struct interaction
 
struct dpp::message::allowed_ref allowed_mentions
 
class clusterowner
 The cluster which created this message object. 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...
 

Detailed Description

Represents messages sent and received on Discord.

Constructor & Destructor Documentation

◆ message() [1/5]

dpp::message::message ( )

Construct a new message object.

◆ message() [2/5]

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()

virtual dpp::message::~message ( )
virtual

Destroy the message object.

◆ message() [3/5]

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 2000 UTF-8 characters.
typeThe message type to create

◆ message() [4/5]

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() [5/5]

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 2000 UTF-8 characters.
typeThe message type to create

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

Add a file to the message.

Parameters
filenamefilename
filecontentraw file content contained in std::string
Returns
message& reference to self

◆ build_json()

std::string dpp::message::build_json ( bool  with_id = false,
bool  is_interaction_response = false 
) const

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

◆ fill_from_json()

message & dpp::message::fill_from_json ( nlohmann::json *  j,
cache_policy_t  cp = {cp_aggressivecp_aggressivecp_aggressive} 
)

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

◆ get_creation_time()

double dpp::managed::get_creation_time ( ) const
inherited

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.

◆ 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 news 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_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_urgent()

bool dpp::message::is_urgent ( ) const

True if urgent.

Returns
true if urgent

◆ operator!=()

bool dpp::managed::operator!= ( const managed other) const
noexceptinherited

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==()

bool dpp::managed::operator== ( const managed other) const
noexceptinherited

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,
bool  _parse_roles,
bool  _parse_everyone,
bool  _replied_user,
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
_parse_roleswhether or not to parse roles in the message content or embeds
_parse_everyonewhether or not to parse everyone/here in the message content or embeds
_replied_userif set to true and this is a reply, then ping the user we reply to
userslist of user ids to allow pings for
roleslist of role ids to allow pings for
Returns
message& reference to self

◆ 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 2000 UTF-8 characters.
Returns
message& reference to self

◆ 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

◆ 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

◆ set_flags()

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

Set the flags.

Parameters
fflags to set
Returns
message& reference to self

◆ 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

◆ 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()

bool dpp::message::suppress_embeds ( ) const

True if embeds have been removed.

Returns
true if embeds removed

Member Data Documentation

◆ allowed_mentions

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

◆ attachments

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

any attached files

◆ author

user dpp::message::author

the author of this message (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 (may be 0 if never edited)

◆ embeds

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

zero or more dpp::embed objects

◆ filecontent

std::vector<std::string> dpp::message::filecontent

File content to upload (raw binary)

◆ filename

std::vector<std::string> dpp::message::filename

Name of file to upload (for use server-side in discord's url)

◆ flags

uint8_t dpp::message::flags

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. (Discord: not all types supported) 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

◆ 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

Stickers

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