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:233
Represents a guild on Discord (AKA a server)
Definition: guild.h:203
bool connect_member_voice(snowflake user_id, bool self_mute=false, bool self_deaf=false)
Connect to a voice channel another guild member is in.
std::map< snowflake, voicestate > voice_members
Definition: guild.h:301
snowflake id
Definition: discord.h:44
DPP_EXPORT guild * find_guild(snowflake id)
Create message.
Definition: dispatcher.h:1017
message * msg
message that was created (sent). If you use any parts of this in another thread, take a copy!...
Definition: dispatcher.h:1027
Represents messages sent and received on Discord.
Definition: message.h:944
user * author
Definition: message.h:952
snowflake guild_id
Definition: message.h:950
std::string content
Definition: message.h:956