Discord's newest features support sending buttons alongside messages, which when clicked by the user trigger an interaction which is routed by D++ as an on_button_click
event. To make use of this, use this code as in this example.
dpp::message msg(event.command.channel_id, "this text has a button");
msg.add_component(
dpp::component().add_component(
dpp::component()
.set_label("Click me!")
.set_type(dpp::cot_button)
.set_emoji(dpp::unicode_emoji::smile)
.set_style(dpp::cos_danger)
.set_id("myid")
)
);
event.reply(msg);
}
});
event.reply(
"You clicked: " + event.
custom_id);
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"button",
"Send a message with a button!", bot.me.id));
}
});
return 0;
}
When the feature is functioning, the code below will produce buttons on the reply message like in the image below: