D++ (DPP)
C++ Discord API Bot Library
Record yourself in a VC

DPP supports receiving audio. This examples show how to use it to record some user in a VC.

Note
Voice receiving by bots is not officially supported by the Discord API. We cannot guarantee that this feature will work in the future.
#include <dpp/dpp.h>
#include <iomanip>
#include <sstream>
int main(int argc, char const *argv[])
{
/* Example to record a user in a VC
*
* Recording is output as './me.pcm' and you can play it via the soundboard example
* or use ffmpeg 'ffplay -f s16le -ar 48000 -ac 2 -i ./me.pcm'
*/
/* Replace with the user's id you wish to record */
dpp::snowflake user_id = 407877550216314882;
dpp::cluster bot("token");
FILE *fd;
fd = fopen("./me.pcm", "wb");
/* Use the on_message_create event to look for commands */
bot.on_message_create([&bot, &fd](const dpp::message_create_t & event) {
std::stringstream ss(event.msg->content);
std::string command;
ss >> command;
/* Tell the bot to record */
if (command == ".record") {
if (!g->connect_member_voice(event.msg->author->id)) {
bot.message_create(dpp::message(
event.msg->channel_id,
"You don't seem to be on a voice channel! :("
));
}
}
/* Tell the bot to stop recording */
if (command == ".stop") {
event.from->disconnect_voice(event.msg->guild_id);
fclose(fd);
}
});
bot.on_voice_receive([&bot, &fd, &user_id](const dpp::voice_receive_t &event) {
if (event.user_id == user_id) {
fwrite((char *)event.audio, 1, event.audio_size, fd);
}
});
/* Start bot */
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:371
Represents a guild on Discord (AKA a server)
Definition: guild.h:350
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.
snowflake id
Definition: discord.h:44
uint64_t snowflake
A 64 bit unsigned value representing many things on discord. Discord calls the value a 'snowflake' va...
Definition: discord.h:36
DPP_EXPORT guild * find_guild(snowflake id)
Create message.
Definition: dispatcher.h:1097
message * msg
message that was created (sent). If you use any parts of this in another thread, take a copy!...
Definition: dispatcher.h:1107
Represents messages sent and received on Discord.
Definition: message.h:959
user * author
Definition: message.h:967
snowflake guild_id
Definition: message.h:965
std::string content
Definition: message.h:971
snowflake channel_id
Definition: message.h:963
voice receive packet
Definition: dispatcher.h:1418
size_t audio_size
Size of audio buffer.
Definition: dispatcher.h:1434
uint8_t * audio
Audio data, encoded as 48kHz stereo PCM or Opus.
Definition: dispatcher.h:1430
snowflake user_id
User ID of speaker (zero if unknown)
Definition: dispatcher.h:1438
D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0