@@ -113,6 +113,38 @@ class Client : public Discord {
113
113
permissions.add_integration_types (DiscordCPP::ApplicationCommand::GUILD_INSTALL);
114
114
create_application_command (permissions);
115
115
116
+ ApplicationCommand role_cmd;
117
+ role_cmd.set_name (" role" );
118
+ role_cmd.set_description (" add/remove roles from a member" );
119
+ role_cmd.set_type (DiscordCPP::ApplicationCommand::CHAT_INPUT);
120
+ role_cmd.add_contexts (DiscordCPP::ApplicationCommand::GUILD);
121
+ role_cmd.add_integration_types (DiscordCPP::ApplicationCommand::GUILD_INSTALL);
122
+ ApplicationCommandValueOption member;
123
+ member.set_type (DiscordCPP::ApplicationCommandOption::USER);
124
+ member.set_name (" member" );
125
+ member.set_description (" member" );
126
+ member.set_required (true );
127
+ ApplicationCommandValueOption role;
128
+ role.set_type (DiscordCPP::ApplicationCommandOption::ROLE);
129
+ role.set_name (" role" );
130
+ role.set_description (" role" );
131
+ role.set_required (true );
132
+ ApplicationCommandSubcommand add;
133
+ add.set_type (DiscordCPP::ApplicationCommandOption::SUB_COMMAND);
134
+ add.set_name (" add" );
135
+ add.set_description (" assign role to member" );
136
+ add.add_option (member);
137
+ add.add_option (role);
138
+ ApplicationCommandSubcommand remove ;
139
+ remove .set_type (DiscordCPP::ApplicationCommandOption::SUB_COMMAND);
140
+ remove .set_name (" remove" );
141
+ remove .set_description (" remove role from member" );
142
+ remove .add_option (member);
143
+ remove .add_option (role);
144
+ role_cmd.add_option (add);
145
+ role_cmd.add_option (remove );
146
+ create_application_command (role_cmd);
147
+
116
148
update_presence (DiscordStatus::Online, Activity (" test" , Activity::Type::Game));
117
149
}
118
150
@@ -481,6 +513,19 @@ class Client : public Discord {
481
513
+ " \n You are " + std::string (can_delete_messages ? " " : " not " ) + " allowed to delete messages" //
482
514
+ " \n You can " + std::string (can_kick_members ? " " : " not " ) + " kick members" );
483
515
}
516
+ } else if (name == " role" ) {
517
+ auto options = interaction.get_data ().value ().get_options ();
518
+ auto member = interaction.get_data ()->get_resolved_data ()->get_members ().begin ()->second ;
519
+ auto role = interaction.get_data ()->get_resolved_data ()->get_roles ().begin ()->second ;
520
+ for (auto & option : options) {
521
+ if (InteractionDataOptionHelper::get_interaction_data_option_name (option) == " add" && InteractionDataOptionHelper::get_interaction_data_option_type (option) == ApplicationCommandOption::Type::SUB_COMMAND) {
522
+ member.add_role (role);
523
+ interaction.reply (" role " + role.get_name () + " assigned to " + std::string (member));
524
+ } else if (InteractionDataOptionHelper::get_interaction_data_option_name (option) == " remove" && InteractionDataOptionHelper::get_interaction_data_option_type (option) == ApplicationCommandOption::Type::SUB_COMMAND) {
525
+ member.remove_role (role);
526
+ interaction.reply (" role " + role.get_name () + " removed from " + std::string (member));
527
+ }
528
+ }
484
529
}
485
530
}
486
531
0 commit comments