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

Search
Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for dpp::interaction:
[legend]

## Public Member Functions

| interaction ()
| Construct a new interaction object.
virtual | ~interaction ()=default
| Destroy the interaction object.
std::string | build_json (bool with_id=false) const
| Convert object to json string.
interaction & | fill_from_json (nlohmann::json *j)
| Convert object from nlohmann::json.
dpp::snowflake | get_authorizing_integration_owner (application_integration_types type) const
| Get the user who installed the application for a given type.
autocomplete_interaction | get_autocomplete_interaction () const
| Get the autocomplete interaction object.
const dpp::channel & | get_channel () const
| Get the channel this command originated on.
command_interaction | get_command_interaction () const
| Get the command interaction object.
std::string | get_command_name () const
| Get the command name for a command interaction.
component_interaction | get_component_interaction () const
| Get the component interaction object.
const dpp::message & | get_context_message () const
| Get the message this action refers to if it is a context menu command.
constexpr double | get_creation_time () const noexcept
| Get the creation time of this object according to Discord.
const dpp::guild & | get_guild () const
| Get the guild this command originated on.
const dpp::user & | get_issuing_user () const
| Get the user who issued this command.
const dpp::attachment & | 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.
const dpp::channel & | 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.
const dpp::guild_member & | 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.
const dpp::message & | 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.
const dpp::permission & | 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.
const dpp::role & | 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.
const dpp::user & | 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.
bool | is_guild_interaction () const
| Returns true if this interaction occurred as a guild-invited interaction, e.g. within a guild's channel, or a DM of a user in that guild.
bool | is_user_app_interaction () const
| Returns true if this interaction occurred as a user-app interaction, e.g. within a DM or group DM, added to the user not a guild.
constexpr bool | operator!= (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
constexpr bool | operator== (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
auto | to_json (bool with_id=false) const
| Convert object to nlohmann::json.

## Public Attributes

permission | app_permissions
| Permissions of the bot in the channel/guild where this command was issued.
snowflake | application_id
| ID of the application this interaction is for.
uint32_t | attachment_size_limit
| Attachment size limit in bytes for this interaction. Will be the discord default if not provided by the interaction.
std::map< application_integration_types, snowflake > | authorizing_integration_owners
| Context where the interaction was triggered from.
cache_policy_t | cache_policy
| Cache policy from cluster.
dpp::channel | channel
| Optional: The partial channel object where it was sent from.
snowflake | channel_id
| Optional: the channel it was sent from.
std::optional< interaction_context_type > | context
| Context where the interaction was triggered from.
std::variant< command_interaction, component_interaction, autocomplete_interaction > | data
| Optional: the command data payload.
std::vector< entitlement > | entitlements
| For monetized apps, any entitlements for the invoking user, representing access to premium SKUs.
snowflake | guild_id
| Optional: the guild it was sent from.
std::string | guild_locale
| Guild's locale (language) - for guild interactions only.
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.
std::string | locale
| User's locale (language).
guild_member | member
| Optional: guild member data for the invoking user, including permissions. Filled when the interaction is invoked in a guild.
snowflake | message_id
| Originating message id for context menu actions.
message | msg
| Originating message for context menu actions.
command_resolved | resolved
| Resolved data e.g. users, members, roles, channels, permissions, etc.
std::string | token
| A continuation token for responding to the interaction.
uint8_t | type
| The type of interaction from dpp::interaction_type.
user | usr
| User object for the invoking user.
uint8_t | version
| Read-only property, always 1.

## Protected Member Functions

interaction & | fill_from_json_impl (nlohmann::json *j)
| Fill object properties from JSON.
template<typename T, typename C>
const T & | get_resolved (snowflake id, const C &resolved_set) const
| Get a resolved object from the resolved set.
virtual json | to_json_impl (bool with_id=false) const
| Build a json for this object.

## Friends

struct | json_interface< interaction >

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

virtual default

Destroy the interaction object.

## Member Function Documentation

## ◆ build_json()

std::string dpp::json_interface< interaction >::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()

interaction & dpp::json_interface< interaction >::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_impl()

interaction & dpp::interaction::fill_from_json_impl | ( | nlohmann::json * | j | ) |

protected

Fill object properties from JSON.

Parameters

  j | JSON to fill from

Returns
  interaction& Reference to self

## ◆ get_authorizing_integration_owner()

dpp::snowflake dpp::interaction::get_authorizing_integration_owner | ( | application_integration_types | type | ) | const

Get the user who installed the application for a given type.

Parameters

  type | Type of installation for the command, e.g. dpp::ait_guild_install or dpp::ait_user_install.

Returns
  The snowflake of the user. In the event this type is not allowed for the given command, this will return a default-initialised snowflake with value 0.

## ◆ get_autocomplete_interaction()

autocomplete_interaction dpp::interaction::get_autocomplete_interaction | ( |  | ) | const

Get the autocomplete interaction object.

Exceptions

  dpp::logic_exception | if 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_exception | Command 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_exception | if 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_exception | if 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

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

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

Get the guild this command originated on.

Returns
  const dpp::guild& guild

Exceptions

  dpp::logic_exception | Command 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()

template<typename T, typename C>

const T & dpp::interaction::get_resolved | ( | snowflake | id,
|  | const C & | resolved_set ) const

inline protected

Get a resolved object from the resolved set.

Template Parameters

  T | type of object to retrieve
  C | container definition for resolved container

Parameters

  id | Snowflake ID
  resolved_set | container for the type

Returns
  const T& retrieved type

Exceptions

  dpp::logic_exception | on object not found in resolved set

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

  id | Attachment snowflake ID to find

Returns
  const dpp::attachment& file attachment

Exceptions

  dpp::logic_exception | on 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

  id | Channel snowflake ID to find

Returns
  const dpp::channel& channel

Exceptions

  dpp::logic_exception | on 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

  id | User snowflake ID to find

Returns
  const dpp::guild_member& guild member

Exceptions

  dpp::logic_exception | on 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

  id | Message snowflake ID to find

Returns
  const dpp::message& message

Exceptions

  dpp::logic_exception | on 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

  id | User snowflake ID to find

Returns
  const dpp::permission& total permissions for the user including overrides on the channel where the command was issued.

Exceptions

  dpp::logic_exception | on 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

  id | Role snowflake ID to find

Returns
  const dpp::role& role

Exceptions

  dpp::logic_exception | on 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

  id | User snowflake ID to find

Returns
  const dpp::user& user

Exceptions

  dpp::logic_exception | on object not found in resolved set

## ◆ is_guild_interaction()

bool dpp::interaction::is_guild_interaction | ( |  | ) | const

Returns true if this interaction occurred as a guild-invited interaction, e.g. within a guild's channel, or a DM of a user in that guild.

Returns
  true if a guild interaction

## ◆ is_user_app_interaction()

bool dpp::interaction::is_user_app_interaction | ( |  | ) | const

Returns true if this interaction occurred as a user-app interaction, e.g. within a DM or group DM, added to the user not a guild.

Returns
  true if a user-app interaction

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

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

## ◆ to_json()

auto dpp::json_interface< interaction >::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_impl()

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

protected virtual

Build a json for this object.

Parameters

  with_id | True if to include the ID in the JSON

Returns
  json JSON object

## Friends And Related Symbol Documentation

## ◆ json_interface< interaction >

friend struct json_interface< interaction >

friend

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

## ◆ attachment_size_limit

uint32_t dpp::interaction::attachment_size_limit

Attachment size limit in bytes for this interaction. Will be the discord default if not provided by the interaction.

## ◆ authorizing_integration_owners

std::map<application_integration_types, snowflake> dpp::interaction::authorizing_integration_owners

Context where the interaction was triggered from.

## ◆ cache_policy

cache_policy_t dpp::interaction::cache_policy

Cache policy from cluster.

## ◆ channel

dpp::channel dpp::interaction::channel

Optional: The partial channel object where it was sent from.

## ◆ channel_id

snowflake dpp::interaction::channel_id

Optional: the channel it was sent from.

## ◆ context

std::optional<interaction_context_type> dpp::interaction::context

Context where the interaction was triggered from.

## ◆ data

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

Optional: the command data payload.

## ◆ entitlements

std::vector<entitlement> dpp::interaction::entitlements

For monetized apps, any entitlements for the invoking user, representing access to premium SKUs.

## ◆ 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. Filled when the interaction is invoked in a guild.

## ◆ 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 data e.g. users, members, roles, channels, permissions, 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 from 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 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