Skip to content

Commit

Permalink
docs: made the setting_status page use the latest ready_t feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Dec 7, 2023
1 parent 7408958 commit 0f6ec14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions docpages/example_code/setting_status2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ int main() {
/* 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(dpp::get_guild_cache()->count()) + " guilds!"));
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!"));
/*
* Because we need to get an up-to-date count, we can't use what was provided in the ready event.
* So, we get the application from the bot and get the approximate guild count from there.
*/
bot.current_application_get([&bot](const dpp::confirmation_callback_t& callback) {
auto app = callback.get<dpp::application>();

bot.set_presence(dpp::presence(dpp::presence_status::ps_online, dpp::activity_type::at_game, "with " + std::to_string(app.approximate_guild_count) + " guilds!"));
});
}, 120);
}
});
Expand Down
5 changes: 3 additions & 2 deletions docpages/example_programs/misc/setting_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

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{cpp} setting_status1.cpp
Expand All @@ -12,6 +10,9 @@ If all went well, your bot should now be online and say this on members list!

\image html botonlinestatus.png

If you wanted 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.

\include{cpp} setting_status2.cpp
Expand Down

0 comments on commit 0f6ec14

Please sign in to comment.