Represents messages sent and received on Discord. More...
#include "message.h"
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... | |
message & | add_component (const component &c) |
Add a component (button) to message. More... | |
message & | add_embed (const embed &e) |
Add an embed to message. More... | |
message & | add_file (const std::string &filename, const std::string &filecontent, const std::string &filemimetype="") |
Add a file to the message. More... | |
message & | add_sticker (const snowflake &id) |
Add a sticker to this message. More... | |
message & | add_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... | |
message & | fill_from_json (nlohmann::json *j) |
Convert object from nlohmann::json. More... | |
message & | fill_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 poll & | get_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... | |
message & | operator= (const message &m)=default |
Copy a message object. More... | |
message & | operator= (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... | |
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. More... | |
message & | set_channel_id (snowflake _channel_id) |
Set the channel id. More... | |
message & | set_content (const std::string &c) |
Set the message content. More... | |
message & | set_file_content (const std::string &fc) |
Set the file content of the last file in list. More... | |
message & | set_filename (const std::string &fn) |
Set the filename of the last file in list. More... | |
message & | set_flags (uint16_t f) |
Set the flags. More... | |
message & | set_guild_id (snowflake _guild_id) |
Set the channel id. More... | |
message & | set_poll (const poll &p) |
Convenience method to set the poll. More... | |
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. More... | |
message & | set_type (message_type t) |
Set the message type. More... | |
bool | suppress_embeds () const |
True if embeds have been removed. More... | |
message & | suppress_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< poll > | attached_poll |
Optional poll attached to this message. More... | |
std::vector< attachment > | attachments |
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::component > | components |
Message components. More... | |
std::string | content |
Contents of the message. More... | |
time_t | edited |
When this message was edited. More... | |
std::vector< embed > | embeds |
Up to 10 dpp::embed objects. More... | |
std::vector< message_file_data > | file_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< channel > | mention_channels |
Channels mentioned in the message. More... | |
bool | mention_everyone |
Whether this message mentions everyone. More... | |
std::vector< snowflake > | mention_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 cluster * | owner |
The cluster which created this message object. More... | |
bool | pinned |
Whether this message is pinned. More... | |
std::vector< reaction > | reactions |
Optional: reactions to the message. More... | |
time_t | sent |
When this message was sent. More... | |
std::vector< sticker > | stickers |
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 | |
message & | fill_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 > |
Represents messages sent and received on Discord.
dpp::message::message | ( | ) |
Construct a new message object.
|
default |
|
default |
dpp::message::message | ( | class cluster * | o | ) |
Construct a new message object.
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) |
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.
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 |
dpp::message::message | ( | const embed & | _embed | ) |
Construct a new message object with content.
_embed | An embed to send |
Construct a new message object with a channel and content.
channel_id | The channel to send the message to |
_embed | An embed to send |
dpp::message::message | ( | const std::string & | content, |
message_type | type = mt_default |
||
) |
Construct a new message object with content.
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 |
References dpp::int32_not_null().
|
overridedefault |
Destroy the message object.
Add a component (button) to message.
c | component to add |
References flags.
Add an embed to message.
e | embed to add |
References type.
message & dpp::message::add_file | ( | const std::string & | filename, |
const std::string & | filecontent, | ||
const std::string & | filemimetype = "" |
||
) |
Add a file to the message.
filename | filename |
filecontent | raw file content contained in std::string |
filemimetype | optional mime type of the file |
Add a sticker to this message.
As of writing this, a message can only contain up to 3 stickers
id | id of the sticker to add |
Add a sticker to this message.
As of writing this, a message can only contain up to 3 stickers
s | sticker to add |
References file_data, and dpp::message_file_data::name.
|
inlineinherited |
Convert object to json string.
with_id | Whether to include the ID or not |
|
inlineinherited |
Convert object from nlohmann::json.
j | nlohmann::json object |
message & dpp::message::fill_from_json | ( | nlohmann::json * | j, |
cache_policy_t | cp | ||
) |
Fill this object from json.
j | JSON object to fill from |
cp | Cache policy for user records, whether or not we cache users when a message is received |
|
inlineprotected |
Read class values from json object.
j | A json object to read from |
|
inlineconstexprnoexceptinherited |
Get the creation time of this object according to Discord.
const poll & dpp::message::get_poll | ( | ) | const |
Convenience method to get the poll attached to this message.
std::bad_optional_access | if has_poll() == false |
std::string dpp::message::get_url | ( | ) | const |
Returns URL to message.
References dpp::json_interface< T >::fill_from_json(), and dpp::sticker::sticker_user.
|
noexcept |
Method to check if the message has a poll.
bool dpp::message::has_remix_attachment | ( | ) | const |
Returns true if message has remixed attachment.
bool dpp::message::has_thread | ( | ) | const |
True if has thread attached.
References flags, and dpp::m_is_voice_message.
bool dpp::message::is_crosspost | ( | ) | const |
Returns true if posted from other servers announcement channel via webhook.
bool dpp::message::is_crossposted | ( | ) | const |
Returns true if the message was crossposted to other servers.
bool dpp::message::is_dm | ( | ) | const |
Returns true if the message is from a DM.
bool dpp::message::is_ephemeral | ( | ) | const |
True if ephemeral (visible only to issuer of a slash command)
References dpp::snowflake_not_null().
bool dpp::message::is_loading | ( | ) | const |
True if loading.
bool dpp::message::is_source_message_deleted | ( | ) | const |
True if source message was deleted.
References flags, and dpp::m_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.
bool dpp::message::is_urgent | ( | ) | const |
bool dpp::message::is_voice_message | ( | ) | const |
True if the message is a voice message.
References dpp::cp_none, and dpp::cache_policy_t::user_policy.
|
inlineconstexprnoexceptinherited |
Comparison operator for comparing two managed objects by id.
other | Other object to compare against |
Copy a message object.
m | Message to copy |
Move a message object.
m | Message to move |
|
inlineconstexprnoexceptinherited |
Comparison operator for comparing two managed objects by id.
other | Other object to compare against |
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.
_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 |
Set the channel id.
_channel_id | channel id |
References attached_poll.
message & dpp::message::set_content | ( | const std::string & | c | ) |
Set the message content.
c | message content. It will be truncated to the maximum length of 4000 UTF-8 characters. |
Referenced by event_handler_test().
message & dpp::message::set_file_content | ( | const std::string & | fc | ) |
Set the file content of the last file in list.
fc | raw file content contained in std::string |
message & dpp::message::set_filename | ( | const std::string & | fn | ) |
Set the filename of the last file in list.
fn | filename |
message & dpp::message::set_flags | ( | uint16_t | f | ) |
Set the channel id.
_guild_id | channel id |
Convenience method to set the poll.
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.
_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) |
Referenced by dpp::message_create_t::send().
message & dpp::message::set_type | ( | message_type | t | ) |
Set the message type.
t | type to set |
References dpp::message_file_data::content, and file_data.
bool dpp::message::suppress_embeds | ( | ) | const |
True if embeds have been removed.
message & dpp::message::suppress_embeds | ( | bool | suppress | ) |
Set whether embeds should be suppressed.
suppress | whether embeds should be suppressed |
bool dpp::message::suppress_notifications | ( | ) | const |
True if the message will not trigger push and desktop notifications.
|
virtual |
Build JSON from this object.
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. |
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.
|
inlineinherited |
Convert object to nlohmann::json.
with_id | Whether to include the ID or not |
|
inlineprotected |
Build a JSON from this object.
with_id | True if an ID is to be included in the JSON |
|
friend |
struct dpp::message::allowed_ref dpp::message::allowed_mentions |
std::optional<poll> dpp::message::attached_poll |
Optional poll attached to this message.
Referenced by set_channel_id().
std::vector<attachment> dpp::message::attachments |
Any attached files.
user dpp::message::author |
The author of this message.
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().
std::vector<dpp::component> dpp::message::components |
Message components.
std::string dpp::message::content |
Contents of the message.
Referenced by event_handler_test().
time_t dpp::message::edited |
When this message was edited.
std::vector<embed> dpp::message::embeds |
Up to 10 dpp::embed objects.
std::vector<message_file_data> dpp::message::file_data |
An array of file data to use for uploading files.
Referenced by add_sticker(), and set_type().
uint16_t dpp::message::flags |
Flags made from dpp::message_flags.
Referenced by add_component(), has_thread(), is_source_message_deleted(), and is_urgent().
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().
|
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.
Referenced by dpp::poll::add_answer(), dpp::cluster::create_webhook(), dpp::cluster::current_user_join_thread(), dpp::invite::fill_from_json_impl(), dpp::command_permission::fill_from_json_impl(), dpp::interaction::get_resolved_role(), dpp::interaction::get_resolved_user(), dpp::cluster::global_bulk_command_create(), dpp::cluster::global_bulk_command_delete(), dpp::cluster::global_command_delete(), dpp::cluster::global_command_edit(), dpp::cluster::guild_ban_delete(), dpp::cluster::guild_command_create(), dpp::cluster::guild_command_edit_permissions(), dpp::cluster::guild_get_integrations(), dpp::events::guild_member_update::handle(), dpp::events::guild_role_create::handle(), dpp::events::channel_create::handle(), dpp::events::voice_state_update::handle(), dpp::discord_voice_client::handle_frame(), main(), dpp::component::set_disabled(), and dpp::select_option::set_label().
struct dpp::message::message_interaction_struct dpp::message::interaction |
guild_member dpp::message::member |
Optional: member properties for this message's author.
std::vector<channel> dpp::message::mention_channels |
Channels mentioned in the message.
bool dpp::message::mention_everyone |
Whether this message mentions everyone.
std::vector<snowflake> dpp::message::mention_roles |
Roles specifically mentioned in this message (only IDs currently).
std::vector<std::pair<user, guild_member> > dpp::message::mentions |
Users specifically mentioned in the message.
struct dpp::message::message_ref dpp::message::message_reference |
Referenced by to_json().
std::string dpp::message::nonce |
Optional: Used for validating a message was sent.
class cluster* dpp::message::owner |
The cluster which created this message object.
bool dpp::message::pinned |
Whether this message is pinned.
std::vector<reaction> dpp::message::reactions |
Optional: reactions to the message.
time_t dpp::message::sent |
When this message was sent.
std::vector<sticker> dpp::message::stickers |
Partial stickers.
Only id, name and format_type are filled
bool dpp::message::tts |
Whether this was a TTS message.
message_type dpp::message::type |
Message type.
Referenced by add_embed().
snowflake dpp::message::webhook_id |
Optional: Webhook ID.