setting_status

# 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.

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>

    intmain(){
    /*Createthebot*/
    dpp::clusterbot("token");

    bot.on_log(dpp::utility::cout_logger());

    bot.on_ready([&bot](constdpp::ready_t&event){
    /*Wedon'tneedtherun_oncehereaswe'renotregisteringcommands!*/

    /*Setthebotpresenceasonlineand"Playing..."!*/
    bot.set_presence(dpp::presence(dpp::ps_online,dpp::at_game,"games!"));
    });

    bot.start(dpp::st_wait);

    return0;
    }

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.

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>

    intmain(){
    /*Createthebot*/
    dpp::clusterbot("token");

    bot.on_log(dpp::utility::cout_logger());

    bot.on_ready([&bot](constdpp::ready_t&event){
    /*Weputourstatusupdatinginside"run_once"sothatmultipleshardsdon'ttrydothisas"set_presence"updatesalltheshards.*/
    if(dpp::run_once<struct register_bot_commands>()){
    /*Weupdatethepresencenowasthetimerwilldothefirstexecutionafterthexamountofsecondswespecify*/
    bot.set_presence(dpp::presence(dpp::presence_status::ps_online,dpp::activity_type::at_game,"with"+std::to_string(event.guild_count)+"guilds!"));

    /*Createatimerthatrunsevery120seconds,thatsetsthestatus*/
    bot.start_timer([&bot](constdpp::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);

    return0;
    }

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: