When a user issues a command you may want to join their voice channel, e.g. in a music bot. If you are already on the same voice channel, the bot should do nothing (but be ready to instantly play audio) and if the user is on a different voice channel, the bot should switch to it. If the user is on no voice channel at all, this should be considered an error. This example shows how to do this.
- Note
- Please be aware this example sends no audio, but indicates clearly in the comments where and how you should do so.
#include <dpp/dpp.h>
#include <iomanip>
#include <sstream>
int main(int argc, char const *argv[])
{
std::string command;
ss >> command;
if (command == ".join") {
auto current_vc =
event.from->get_voice(event.
msg->
guild_id);
bool join_vc = true;
if (current_vc) {
if (users_vc != g->
voice_members.end() && current_vc->channel_id == users_vc->second.channel_id) {
join_vc = false;
} else {
join_vc = true;
}
}
if (join_vc) {
bot.message_create(
dpp::message(channel_id,
"You don't seem to be on a voice channel! :("));
} else {
}
}
}
});
bot.start(false);
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:221
Represents a guild on Discord (AKA a server)
Definition: guild.h:163
std::map< snowflake, voicestate > voice_members
Definition: guild.h:261
bool connect_member_voice(snowflake user_id)
Connect to a voice channel another guild member is in.
snowflake id
Definition: discord.h:44
CoreExport guild * find_guild(snowflake id)
Create message.
Definition: dispatcher.h:667
message * msg
Definition: dispatcher.h:673
Represents messages sent and received on Discord.
Definition: message.h:835
user * author
Definition: message.h:843
snowflake guild_id
Definition: message.h:841
std::string content
Definition: message.h:847