Skip to content

Commit

Permalink
docs: Fix of #771 where final push was missed. (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Aug 13, 2023
1 parent 656bfb8 commit 6dc6f5d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Context menus are application commands that appear on the context menu (right cl

\image html context_menu_user_command.png

\note This example sets the command as the type dpp::ctxm_user which can only be used by right clicking on a user. To make it appear on a message, you'll want to switch the type to dpp::ctxm_message.
\note This example sets the command as the type dpp::ctxm_user which can only be used by right clicking on a user. To make it appear on a message, you'll want to switch the type to dpp::ctxm_message and listen for the on_message_context_menu (dpp::message_context_menu_t) event.

The following example shows how to create and handle **user context menus** for message context menus, read the notice above.

Expand All @@ -22,12 +22,13 @@ int main()
if (dpp::run_once<struct register_bot_commands>()) {
/* Create the command */
dpp::slashcommand command("High Five", "Send a High Five!", bot.me.id);
dpp::slashcommand command;
command.set_name("High Five");
command.set_application_id(bot.me.id);
command.set_type(dpp::ctxm_user);
/* Register the command */
bot.guild_command_create(command, guild_id);
bot.guild_command_create(command, 857692897221033129); /* Replace this with the guild id you want */
}
});
Expand All @@ -50,4 +51,4 @@ int main()

It registers a guild command that can be called by right-click a user and click on the created menu.

\image html context_menu_user_command_showcase.png
\image html context_menu_user_command_showcase.png
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int main()
/* Add a parameter option. */
newcommand.add_option(dpp::command_option(dpp::co_attachment, "file", "Select an image"));
/* Register the command */
bot.global_command_create(newcommand);
}
});
Expand All @@ -50,4 +51,4 @@ int main()
return 0;
}
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~
16 changes: 11 additions & 5 deletions docpages/example_programs/music_and_audio/join_voice.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ int main(int argc, char const *argv[])
bot.on_log(dpp::utility::cout_logger());
/* The event is fired when someone issues your commands */
bot.on_slashcommand([&bot, &fd](const dpp::slashcommand_t& event) {
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "join") {
/* Get the guild */
dpp::guild* g = dpp::find_guild(event.command.guild_id);
/* Get the voice channel that the bot is currently in from this server (will return nullptr if we're not in a voice channel!) */
auto current_vc = event.from->get_voice(event.command.guild_id);
bool join_vc = true;
if (!current_vc) {
/* Are we in a voice channel? If so, let's see if we're in the right channel. */
if (current_vc) {
/* Find the channel id that the user is currently in */
auto users_vc = g->voice_members.find(event.command.get_issuing_user().id);
if (users_vc != g->voice_members.end() && current_vc->channel_id == users_vc->second.channel_id) {
Expand All @@ -39,10 +43,10 @@ int main(int argc, char const *argv[])
* current_vc->send_audio_raw(...)
*/
} else {
/* We are on a different voice channel. Leave it, then join the new one
/* We are on a different voice channel. We should leave it, then join the new one
* by falling through to the join_vc branch below.
*/
event.from->disconnect_voice(event.channel.guild_id);
event.from->disconnect_voice(event.command.guild_id);
join_vc = true;
}
Expand All @@ -51,6 +55,8 @@ int main(int argc, char const *argv[])
/* If we need to join a vc at all, join it here if join_vc == true */
if(join_vc) {
/* Attempt to connect to a voice channel, returns false if we fail to connect. */
/* The user issuing the command is not on any voice channel, we can't do anything */
if (!g->connect_member_voice(event.command.get_issuing_user().id)) {
event.reply("You don't seem to be in a voice channel!");
return;
Expand Down Expand Up @@ -87,4 +93,4 @@ int main(int argc, char const *argv[])
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~

0 comments on commit 6dc6f5d

Please sign in to comment.