#include <dpp/dpp.h>
int main() {
dpp::message m{"Test"};
std::string id{event.command.id.str()};
m.add_component(
.set_label("Click me!")
.set_id(id)
)
);
co_await event.co_reply(m);
return b.custom_id ==
id;
}
);
event.edit_original_response(
dpp::message{
"You clicked the button!"});
}
});
bot.global_command_create(command);
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
event_router_t< log_t > on_log
Called when a log message is to be written to the log. You can attach any logging system here you wis...
Definition cluster.h:692
event_router_t< button_click_t > on_button_click
Called when a button is clicked attached to a message. Button clicks are triggered by discord when bu...
Definition cluster.h:744
Represents the component object. A component is a clickable button or drop down list within a discord...
Definition message.h:497
component & set_type(component_type ct)
Set the type of the component. Button components (type dpp::cot_button) should always be contained wi...
component & add_component(const component &c)
Add a sub-component, only valid for action rows. Adding subcomponents to a component will automatical...
std::string get_command_name() const
Get the command name for a command interaction.
snowflake id
Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID,...
Definition managed.h:39
Represents an application command, created by your bot either globally, or on a guild.
Definition appcommand.h:1436
A coroutine task. It starts immediately on construction and can be co_await-ed, making it perfect for...
Definition task.h:95
constexpr const char b[]
Definition unicode_emoji.h:5255
constexpr const char id[]
Definition unicode_emoji.h:5229
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
auto run_once()
Run some code within an if() statement only once.
Definition once.h:41
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
@ cot_button
Clickable button.
Definition message.h:48
dpp::cluster * owner
Cluster owning the event dispatch.
Definition dispatcher.h:102
void reply(command_completion_event_t callback=utility::log_error()) const
Acknowledge interaction without displaying a message to the user, for use with button and select menu...
interaction command
command interaction
Definition dispatcher.h:789
Represents messages sent and received on Discord.
Definition message.h:2350
Session ready.
Definition dispatcher.h:1072
User has issued a slash command.
Definition dispatcher.h:806
Note that there is a problem with that! If the user never clicks your button, or if the message gets deleted, your coroutine will be stuck waiting... And waiting... Forever until your bot shuts down, occupying a space in memory. This is where the next example comes into play as a solution, with a button that expires with time.