| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::message Struct Reference

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

`#include <message.h>`

Inheritance diagram for dpp::message:
[legend]
Collaboration diagram for dpp::message:
[legend]

## 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.
| message (class cluster *o)
| Construct a new message object.
| message (const embed &_embed)
| Construct a new message object with content.
| message (const message &m)=default
| message (message &&m)=default
| message (snowflake channel_id, const embed &_embed)
| Construct a new message object with a channel and content.
| message (snowflake channel_id, std::string_view content, message_type type=mt_default)
| Construct a new message object with a channel and content.
| message (std::string_view content, message_type type=mt_default)
| Construct a new message object with content.
| ~message () override=default
| Destroy the message object.
message & | add_component (const component &c)
| Add a component to a message.
message & | add_component_v2 (const component &c)
| Add a component to a message.
message & | add_embed (const embed &e)
| Add an embed to message.
message & | add_file (std::string_view filename, std::string_view filecontent, std::string_view filemimetype="")
| Add a file to the message.
message & | add_json_components (const std::string &json)
| Add pre-generated components to a message.
message & | add_sticker (const snowflake &id)
| Add a sticker to this message.
message & | add_sticker (const sticker &s)
| Add a sticker to this message.
std::string | build_json (bool with_id=false) const
| Convert object to json string.
message & | fill_from_json (nlohmann::json *j)
| Convert object from nlohmann::json.
message & | fill_from_json (nlohmann::json *j, cache_policy_t cp)
constexpr double | get_creation_time () const noexcept
| Get the creation time of this object according to Discord.
const poll & | get_poll () const
| Convenience method to get the poll attached to this message.
std::string | get_url () const
| Returns URL to message.
bool | has_poll () const noexcept
| Method to check if the message has a poll.
bool | has_remix_attachment () const
| Returns true if message has remixed attachment.
bool | has_snapshot () const
| True if the message has a snapshot.
bool | has_thread () const
| True if has thread attached.
bool | is_crosspost () const
| Returns true if posted from other servers announcement channel via webhook.
bool | is_crossposted () const
| Returns true if the message was crossposted to other servers.
bool | is_dm () const
| Returns true if the message is from a DM.
bool | is_ephemeral () const
| True if ephemeral (visible only to issuer of a slash command).
bool | is_loading () const
| True if loading.
bool | is_source_message_deleted () const
| True if source message was deleted.
bool | is_thread_mention_failed () const
| Returns true if this message failed to mention some roles and add their members to the thread.
bool | is_urgent () const
| True if urgent.
bool | is_using_components_v2 () const
| True if the message is using components v2.
bool | is_voice_message () const
| True if the message is a voice message.
constexpr bool | operator!= (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
message & | operator= (const message &m)=default
| Copy a message object.
message & | operator= (message &&m)=default
| Move a message object.
constexpr bool | operator== (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
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.
message & | set_channel_id (snowflake _channel_id)
| Set the channel id.
message & | set_content (std::string_view c)
| Set the message content.
message & | set_file_content (std::string_view fc)
| Set the file content of the last file in list.
message & | set_filename (std::string_view fn)
| Set the filename of the last file in list.
message & | set_flags (uint16_t f)
| Set the flags.
message & | set_guild_id (snowflake _guild_id)
| Set the channel id.
message & | set_poll (const poll &p)
| Convenience method to set the poll.
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.
message & | set_type (message_type t)
| Set the message type.
bool | suppress_embeds () const
| True if embeds have been removed.
message & | suppress_embeds (bool suppress)
| Set whether embeds should be suppressed.
bool | suppress_notifications () const
| True if the message will not trigger push and desktop notifications.
auto | to_json (bool with_id=false) const
| Convert object to nlohmann::json.
virtual json | to_json (bool with_id, bool is_interaction_response) const

## Public Attributes

struct dpp::message::allowed_ref | allowed_mentions
std::optional< poll > | attached_poll
| Optional poll attached to this message.
std::vector< attachment > | attachments
| Any attached files.
user | author
| The author of this message.
snowflake | channel_id
| ID of the channel the message was sent in.
std::vector< dpp::component > | components
| Message components.
json | components_json
| Pre-generated components as JSON. This overrides the components array if it is set.
std::string | content
| Contents of the message.
time_t | edited
| When this message was edited.
std::vector< embed > | embeds
| Up to 10 dpp::embed objects.
std::vector< message_file_data > | file_data
| An array of file data to use for uploading files.
uint16_t | flags
| Flags made from dpp::message_flags.
snowflake | guild_id
| Optional: ID of the guild the message was sent in.
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.
struct dpp::message::message_interaction_struct | interaction
interaction_metadata_type | interaction_metadata
| Sent if the message is sent as a result of an interaction.
guild_member | member
| Optional: member properties for this message's author.
std::vector< channel > | mention_channels
| Channels mentioned in the message.
bool | mention_everyone
| Whether this message mentions everyone.
std::vector< snowflake > | mention_roles
| Roles specifically mentioned in this message (only IDs currently).
std::vector< std::pair< user, guild_member > > | mentions
| Users specifically mentioned in the message.
struct dpp::message::message_ref | message_reference
message_snapshot< message > | message_snapshots
| Message snapshots for a forwarded message.
std::string | nonce
| Optional: Used for validating a message was sent.
class cluster * | owner
| The cluster which created this message object.
bool | pinned
| Whether this message is pinned.
std::vector< reaction > | reactions
| Optional: reactions to the message.
time_t | sent
| When this message was sent.
std::vector< sticker > | stickers
| Partial stickers. Only id, name and format_type are filled.
bool | tts
| Whether this was a TTS message.
message_type | type
| Message type.
snowflake | webhook_id
| Optional: Webhook ID.

## Protected Member Functions

message & | fill_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

  o | Owning 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_id | The channel to send the message to
  content | The content of the message. It will be truncated to the maximum length of 4000 UTF-8 characters.
  type | The message type to create

## ◆ message() [6/8]

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

Construct a new message object with content.

Parameters

  _embed | An 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_id | The channel to send the message to
  _embed | An 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

  content | The content of the message. It will be truncated to the maximum length of 4000 UTF-8 characters.
  type | The message type to create

## ◆ ~message()

dpp::message::~message | ( |  | ) |

override default

Destroy the message object.

## Member Function Documentation

## ◆ add_component()

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

Add a component to a message.

Note
  If the component type you add is only available in components v2, this method will automatically add the m_using_components_v2 flag to your message.

Parameters

  c | component to add

Returns
  message& reference to self

## ◆ add_component_v2()

message & dpp::message::add_component_v2 | ( | const component & | c | ) |

Add a component to a message.

Note
  If the component type you add is only available in components v2, this method will automatically add the m_using_components_v2 flag to your message.

This is an alias of add_component() for readability when using components v2, so you can use add_component_v2() everywhere. It does exactly the same as add_component().

Parameters

  c | component to add

Returns
  message& reference to self

## ◆ add_embed()

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

Add an embed to message.

Parameters

  e | embed 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

  filename | filename
  filecontent | raw file content
  filemimetype | optional mime type of the file

Returns
  message& reference to self

## ◆ add_json_components()

message & dpp::message::add_json_components | ( | const std::string & | json | ) |

Add pre-generated components to a message.

Note
  This is intended to accept pre-generated component json from external tools such as https://discord.builders

Parameters

  json | components json to add. The JSON will be validated

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

  id | id 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

  s | sticker to add

Returns
  message& reference to self

## ◆ build_json()

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

inline inherited

Convert object to json string.

Parameters

  with_id | Whether 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 | ) |

inline inherited

Convert object from nlohmann::json.

Parameters

  j | nlohmann::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

  j | JSON object to fill from
  cp | Cache 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 | ) |

inline protected

Read class values from json object

Parameters

  j | A json object to read from

Returns
  A reference to self

## ◆ get_creation_time()

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

inline constexpr noexcept 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.

## ◆ get_poll()

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

nodiscard

Convenience method to get the poll attached to this message.

Exceptions

  std::bad_optional_access | if 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

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

bool dpp::message::has_snapshot | ( |  | ) | const

True if the message has a snapshot.

Returns
  True if voice message

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

bool dpp::message::is_using_components_v2 | ( |  | ) | const

True if the message is using components v2.

Returns
  True if voice message

## ◆ is_voice_message()

bool dpp::message::is_voice_message | ( |  | ) | const

True if the message is a voice message.

Returns
  True if voice message

## ◆ operator!=()

bool dpp::managed::operator!= | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other 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

  m | Message to copy

Returns
  message& Reference to self

## ◆ operator=() [2/2]

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

default

Move a message object.

Parameters

  m | Message to move

Returns
  message& Reference to self

## ◆ operator==()

bool dpp::managed::operator== | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other 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_users | whether or not to parse users in the message content or embeds, default false
  _parse_roles | whether or not to parse roles in the message content or embeds, default false
  _parse_everyone | whether or not to parse everyone/here in the message content or embeds, default false
  _replied_user | if set to true and this is a reply, then ping the user we reply to, default false
  users | list of user ids to allow pings for, default an empty vector
  roles | list 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_id | channel id

Returns
  message& reference to self

## ◆ set_content()

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

Set the message content.

Parameters

  c | message 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

  fc | raw 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

  fn | filename

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

  f | flags 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_id | channel 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_id | message id to reply to
  _guild_id | guild id to reply to (optional)
  _channel_id | channel id to reply to (optional)
  fail_if_not_exists | true if the message send should fail if these values are invalid (optional)
  type | Type of reference

Returns
  message& reference to self

## ◆ set_type()

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

Set the message type.

Parameters

  t | type 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

  suppress | whether 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]

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

inline inherited

Convert object to nlohmann::json.

Parameters

  with_id | Whether 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() [2/2]

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

virtual

Build JSON from this object.

Parameters

  with_id | True if the ID is to be included in the built JSON
  is_interaction_response | Set 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_impl()

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

inline protected

Build a JSON from this object.

Parameters

  with_id | True if an ID is to be included in the JSON

Returns
  JSON

## Friends And Related Symbol 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.

## ◆ components_json

json dpp::message::components_json

Pre-generated components as JSON. This overrides the components array if it is set.

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

## ◆ interaction_metadata

interaction_metadata_type dpp::message::interaction_metadata

Sent if the message is sent as a result of an 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 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0