D++ (DPP)
C++ Discord API Bot Library
Setting the Bot's Status

A bot status is pretty cool, and it'd be cooler if you knew how to do it! This tutorial will cover how to set the bot status to say Playing games!, as well as covering how to set the status to the amount of guilds every two minutes.

Note
dpp::get_guild_cache requires the bot to have the guild cache enabled, if your bot has this disabled then you can't use that. Instead, you should look to use dpp::cluster::current_application_get and get the approximate_guild_count from dpp::application in the callback.

First, we'll cover setting the bot status to Playing games!.

#include <dpp/dpp.h>
int main() {
/* Create the bot */
dpp::cluster bot("token");
bot.on_ready([&bot](const dpp::ready_t& event) {
/* We don't need the run_once here as we're not registering commands! */
/* Set the bot presence as online and "Playing..."! */
bot.set_presence(dpp::presence(dpp::ps_online, dpp::at_game, "games!"));
});
bot.start(dpp::st_wait);
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:80
Represents user presence, e.g. what game they are playing and if they are online.
Definition: presence.h:489
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ ps_online
Online.
Definition: presence.h:109
@ at_game
"Playing ..."
Definition: presence.h:179
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:63
Session ready.
Definition: dispatcher.h:961

If all went well, your bot should now be online and say this on members list!

If you want to make your bot show as Do Not Disturb, then you could change dpp::ps_online to dpp::ps_dnd. You can also play around with dpp::at_game, changing it to something like dpp::at_custom or dpp::at_listening!

Now, let's cover setting the bot status to say Playing with x guilds! every two minutes.

Note
This example uses timers to update the status every 2 minutes. If you aren't familiar with D++'s own timers, please read this page on timers before you continue.
#include <dpp/dpp.h>
int main() {
/* Create the bot */
dpp::cluster bot("token");
bot.on_ready([&bot](const dpp::ready_t& event) {
/* We put our status updating inside "run_once" so that multiple shards don't try do this as "set_presence" updates all the shards. */
if (dpp::run_once<struct register_bot_commands>()) {
/* We update the presence now as the timer will do the first execution after the x amount of seconds we specify */
bot.set_presence(dpp::presence(dpp::presence_status::ps_online, dpp::activity_type::at_game, "with " + std::to_string(event.guild_count) + " guilds!"));
/* Create a timer that runs every 120 seconds, that sets the status */
bot.start_timer([&bot](const dpp::timer& timer) {
bot.set_presence(dpp::presence(dpp::presence_status::ps_online, dpp::activity_type::at_game, "with " + std::to_string(dpp::get_guild_cache()->count()) + " guilds!"));
}, 120);
}
});
bot.start(dpp::st_wait);
return 0;
}
size_t timer
Represents a timer handle. Returned from cluster::start_timer and used by cluster::stop_timer....
Definition: timer.h:39
uint32_t guild_count
The number of guilds the bot is in, at the time of this event.
Definition: dispatcher.h:983

If you followed that well, your bot should now say this on members list!

If we then add our bot to another server and wait a bit, we'll see it updates like so:

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