D++ (DPP)
C++ Discord API Bot Library
dpp::interaction Class Reference

An interaction represents a user running a command and arrives via the dpp::cluster::on_interaction_create event. This is further split into the events on_form_submit, on_slashcommand, on_user_context_menu, on_button_click, on_select_menu, etc. More...

#include <appcommand.h>

+ Inheritance diagram for dpp::interaction:
+ Collaboration diagram for dpp::interaction:

Public Member Functions

 interaction ()
 Construct a new interaction object. More...
 
virtual ~interaction ()=default
 Destroy the interaction object. More...
 
const dpp::userget_resolved_user (snowflake id) const
 Get a user associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
const dpp::channelget_channel () const
 Get the channel this command originated on. More...
 
const dpp::guildget_guild () const
 Get the guild this command originated on. More...
 
const dpp::userget_issuing_user () const
 Get the user who issued this command. More...
 
const dpp::messageget_context_message () const
 Get the message this action refers to if it is a context menu command. More...
 
const dpp::roleget_resolved_role (snowflake id) const
 Get a role associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
const dpp::channelget_resolved_channel (snowflake id) const
 Get a channel associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
const dpp::guild_memberget_resolved_member (snowflake id) const
 Get a guild member associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
const dpp::permissionget_resolved_permission (snowflake id) const
 Get a permission associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
const dpp::messageget_resolved_message (snowflake id) const
 Get a message associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
const dpp::attachmentget_resolved_attachment (snowflake id) const
 Get an uploaded attachment associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls. More...
 
command_interaction get_command_interaction () const
 Get the command interaction object. More...
 
component_interaction get_component_interaction () const
 Get the component interaction object. More...
 
autocomplete_interaction get_autocomplete_interaction () const
 Get the autocomplete interaction object. More...
 
std::string get_command_name () const
 Get the command name for a command interaction. More...
 
interactionfill_from_json (nlohmann::json *j)
 Fill object properties from JSON. More...
 
std::string build_json (bool with_id=false) const
 Build a json string for this object. 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 application_id
 id of the application this interaction is for More...
 
uint8_t type
 the type of interaction (dpp::interaction_type) More...
 
std::variant< command_interaction, component_interaction, autocomplete_interactiondata
 Optional: the command data payload. More...
 
snowflake guild_id
 Optional: the guild it was sent from. More...
 
snowflake channel_id
 Optional: the channel it was sent from. More...
 
snowflake message_id
 Originating message id for context menu actions. More...
 
permission app_permissions
 Permissions of the bot in the channel/guild where this command was issued. More...
 
message msg
 Originating message for context menu actions. More...
 
guild_member member
 Optional: guild member data for the invoking user, including permissions. More...
 
user usr
 User object for the invoking user. More...
 
std::string token
 a continuation token for responding to the interaction More...
 
uint8_t version
 read-only property, always 1 More...
 
command_resolved resolved
 Resolved user/role etc. More...
 
std::string locale
 User's locale (language) More...
 
std::string guild_locale
 Guild's locale (language) - for guild interactions only. More...
 
cache_policy_t cache_policy
 Cache policy from cluster. 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

An interaction represents a user running a command and arrives via the dpp::cluster::on_interaction_create event. This is further split into the events on_form_submit, on_slashcommand, on_user_context_menu, on_button_click, on_select_menu, etc.

Constructor & Destructor Documentation

◆ interaction()

dpp::interaction::interaction ( )

Construct a new interaction object.

◆ ~interaction()

virtual dpp::interaction::~interaction ( )
virtualdefault

Destroy the interaction object.

Member Function Documentation

◆ build_json()

std::string dpp::interaction::build_json ( bool  with_id = false) const
virtual

Build a json string for this object.

Parameters
with_idTrue if to include the ID in the JSON
Returns
std::string JSON string

Reimplemented from dpp::json_interface< interaction >.

◆ fill_from_json()

interaction & dpp::interaction::fill_from_json ( nlohmann::json *  j)

Fill object properties from JSON.

Parameters
jJSON to fill from
Returns
interaction& Reference to self

◆ get_autocomplete_interaction()

autocomplete_interaction dpp::interaction::get_autocomplete_interaction ( ) const

Get the autocomplete interaction object.

Exceptions
dpp::logic_exceptionif the interaction is not for an autocomplete
Returns
autocomplete_interaction object

◆ get_channel()

const dpp::channel & dpp::interaction::get_channel ( ) const

Get the channel this command originated on.

Returns
const dpp::channel& channel
Exceptions
dpp::logic_errorCommand originated from a DM or channel not in cache

◆ get_command_interaction()

command_interaction dpp::interaction::get_command_interaction ( ) const

Get the command interaction object.

Exceptions
dpp::logic_exceptionif the interaction is not for a command
Returns
command_interaction object

◆ get_command_name()

std::string dpp::interaction::get_command_name ( ) const

Get the command name for a command interaction.

Returns
std::string command interaction, or empty string if the interaction is not for a command.

◆ get_component_interaction()

component_interaction dpp::interaction::get_component_interaction ( ) const

Get the component interaction object.

Exceptions
dpp::logic_exceptionif the interaction is not for a component
Returns
component_interaction object

◆ get_context_message()

const dpp::message & dpp::interaction::get_context_message ( ) const

Get the message this action refers to if it is a context menu command.

Returns
const dpp::message& context menu message

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

◆ get_guild()

const dpp::guild & dpp::interaction::get_guild ( ) const

Get the guild this command originated on.

Returns
const dpp::guild& guild
Exceptions
dpp::logic_errorCommand originated from a DM or guild not in cache

◆ get_issuing_user()

const dpp::user & dpp::interaction::get_issuing_user ( ) const

Get the user who issued this command.

Returns
const dpp::user& user

◆ get_resolved_attachment()

const dpp::attachment & dpp::interaction::get_resolved_attachment ( snowflake  id) const

Get an uploaded attachment associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idAttachment snowflake ID to find
Returns
const dpp::attachment& file attachment
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ get_resolved_channel()

const dpp::channel & dpp::interaction::get_resolved_channel ( snowflake  id) const

Get a channel associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idChannel snowflake ID to find
Returns
const dpp::channel& channel
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ get_resolved_member()

const dpp::guild_member & dpp::interaction::get_resolved_member ( snowflake  id) const

Get a guild member associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idUser snowflake ID to find
Returns
const dpp::guild_member& guild member
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ get_resolved_message()

const dpp::message & dpp::interaction::get_resolved_message ( snowflake  id) const

Get a message associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idMessage snowflake ID to find
Returns
const dpp::message& message
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ get_resolved_permission()

const dpp::permission & dpp::interaction::get_resolved_permission ( snowflake  id) const

Get a permission associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idUser snowflake ID to find
Returns
const dpp::permission& permissions for the user including overrides on the channel where the command was issued.
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ get_resolved_role()

const dpp::role & dpp::interaction::get_resolved_role ( snowflake  id) const

Get a role associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idRole snowflake ID to find
Returns
const dpp::role& role
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ get_resolved_user()

const dpp::user & dpp::interaction::get_resolved_user ( snowflake  id) const

Get a user associated with the slash command from the resolved list. The resolved list contains associated structures for this command and does not use the cache or require any extra API calls.

Parameters
idUser snowflake ID to find
Returns
const dpp::user& user
Exceptions
dpp::logic_exceptionon object not found in resolved set

◆ 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

Member Data Documentation

◆ app_permissions

permission dpp::interaction::app_permissions

Permissions of the bot in the channel/guild where this command was issued.

◆ application_id

snowflake dpp::interaction::application_id

id of the application this interaction is for

◆ cache_policy

cache_policy_t dpp::interaction::cache_policy

Cache policy from cluster.

◆ channel_id

snowflake dpp::interaction::channel_id

Optional: the channel it was sent from.

◆ data

std::variant<command_interaction, component_interaction, autocomplete_interaction> dpp::interaction::data

Optional: the command data payload.

◆ guild_id

snowflake dpp::interaction::guild_id

Optional: the guild it was sent from.

◆ guild_locale

std::string dpp::interaction::guild_locale

Guild's locale (language) - for guild interactions only.

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

◆ locale

std::string dpp::interaction::locale

User's locale (language)

◆ member

guild_member dpp::interaction::member

Optional: guild member data for the invoking user, including permissions.

◆ message_id

snowflake dpp::interaction::message_id

Originating message id for context menu actions.

◆ msg

message dpp::interaction::msg

Originating message for context menu actions.

◆ resolved

command_resolved dpp::interaction::resolved

Resolved user/role etc.

◆ token

std::string dpp::interaction::token

a continuation token for responding to the interaction

◆ type

uint8_t dpp::interaction::type

the type of interaction (dpp::interaction_type)

◆ usr

user dpp::interaction::usr

User object for the invoking user.

◆ version

uint8_t dpp::interaction::version

read-only property, always 1

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