setActivity

Sets Bot Status - Offline, DND, Online, Streaming, Playing etc.

Cannot be used outside of bot listener event

Requires

  • activity

  • status

  • type

<?php
require('vendor/autoload.php');

use \HobsRkm\SDK\PHPDiscordSDK\PHPDiscordSDKFactory;

PHPDiscordSDKFactory::getInstance()
    ->botConnect("<<<<BOT TOKEN><<<<")
    ->then( 
        function ($bot) {
            $bot->on('message', function ($event) {
                PHPDiscordSDKFactory::getInstance()
                ->formatEvent($event)
                ->then(function($message){
                 //All events sent from client will be available here
                /**
                call Presence API
                discord has a delay to update your status not to often
                status - dnd | offline |online | afk
                type - one of PLAYING,STREAMING,
                LISTENING,WATCHING,COMPETING
                **/
                PHPDiscordSDKFactory::getInstance('Presence')
                ->setActivity(
                    array(
                        "activity"=>"Playing CS:GO",
                        "status"=>"dnd",
                        "type"=>'PLAYING'
                        )
                    );                        
                }, function ($reason) {
                    //message event errors
                    print_r($reason->getMessage());
                    //echo $reason->getMessage();
                });
            });
        },
        function ($reason) {
            print_r($reason);
            //other errors, bot startup, authentication
        }
    );

Last updated