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:392
Represents a guild on Discord (AKA a server)
Definition: guild.h:371
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:471
snowflake id
Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID,...
Definition: managed.h:38
DPP_EXPORT class guild * find_guild(snowflake id)
Create message.
Definition: dispatcher.h:1139
message msg
message that was created (sent).
Definition: dispatcher.h:1148
Represents messages sent and received on Discord.
Definition: message.h:1023
user author
Definition: message.h:1029
snowflake guild_id
Definition: message.h:1027
std::string content
Definition: message.h:1033