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.
#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) {
} else {
}
}
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:84
Represents a guild on Discord (AKA a server)
Definition: guild.h:464
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:495
snowflake id
Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID,...
Definition: managed.h:38
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ i_message_content
Intent for receipt of message content.
Definition: intents.h:64
@ i_default_intents
Default D++ intents (all non-privileged intents)
Definition: intents.h:72
DPP_EXPORT class guild * find_guild(snowflake id)
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:67
Create message.
Definition: dispatcher.h:1341
message msg
message that was created (sent).
Definition: dispatcher.h:1350
Represents messages sent and received on Discord.
Definition: message.h:1143
user author
Definition: message.h:1149
snowflake guild_id
Definition: message.h:1147
std::string content
Definition: message.h:1153
snowflake channel_id
Definition: message.h:1145