Ask user why he joined the server + add him the member role

This commit is contained in:
2026-01-14 01:01:37 +01:00
parent 61c1e3f796
commit c04abccbb6
2 changed files with 40 additions and 3 deletions

View File

@@ -2,3 +2,5 @@
#include <dpp/dpp.h>
#include <dpp/nlohmann/json.hpp>
#include <iostream>

View File

@@ -18,8 +18,43 @@ int main(int argc, char const *argv[]) {
}
});
bot.on_guild_member_add([&bot](const dpp::guild_member_add_t& event) {
bot.guild_member_add_role(event.adding_guild.id, event.added.user_id, (dpp::snowflake)"979375572054589471");
bot.on_button_click([&bot](const dpp::button_click_t& event) {
dpp::interaction_modal_response modal("reason", "uwu2x");
modal.add_component(
dpp::component()
.set_label("Why did you join this server ?")
.set_id("reason")
.set_type(dpp::cot_text)
.set_text_style(dpp::text_paragraph)
.set_required(true)
);
event.dialog(modal);
});
bot.on_form_submit([&bot](const dpp::form_submit_t& event) {
bot.guild_member_add_role(
event.command.guild_id,
event.command.get_issuing_user().id,
dpp::snowflake("979375572054589471")
);
std::string reason_text = std::get<std::string>(event.components[0].value);
dpp::embed embed;
embed.set_color(dpp::colors::sti_blue)
.set_title("Welcome " + event.command.get_issuing_user().username)
.set_description("**" + event.command.get_issuing_user().username + "** joined the server because : " + reason_text)
.set_timestamp(time(nullptr));
bot.channel_get(
dpp::snowflake("979375590228500551"),
[&bot, embed](const dpp::confirmation_callback_t& callback) {
if (callback.is_error()) return;
const dpp::channel& channel = std::get<dpp::channel>(callback.value);
bot.message_create(dpp::message(channel.id, embed));
}
);
event.reply();
});
bot.on_ready([&bot](const dpp::ready_t& event) {