DiscordPHP: Discord::updatePresence() not working

I don’t know is this a bug or I configured it wrong, but why Discord::updatePresence() is not working with my Discord bot? I want to set the status but it didn’t worked. So what’s the issue?

Any help would be appreciated!

NOTE: Code is available below. Just extract the archive to open the code. The commands() function is working. I’ve replaced the token to <TOKEN> for privacy reasons.

Code —> Code.zip

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (11 by maintainers)

Most upvoted comments

The problem seems to be in your code, you try to create two instances of your bot. That wil not work.

You must only create one bot instance and use this in your functions

//EDIT Also you must run the loop after all other stuff is loaded The PresenceUpdate works also only if the bot is “ready”

<?php

include __DIR__ . '/vendor/autoload.php';

use Discord\DiscordCommandClient as Commands;
use Discord\Parts\User\Activity;

$discordCommandClient = new Commands([
    'token' => '<TOKEN>',
    'prefix' => '&',
]);

function commands($command)
{
    $command->registerCommand('test', 'Kalau ini muncul berarti bot nya work!', [
        'description' => 'Tes bot server Discord StayWait'
    ]);
    $command->registerCommand('vote', 'Link vote: https://r.staywait.xyz/vote', [
        'aliases' => ['linkvote', 'v', 'linkv'],
        'description' => 'Link vote server StayWait'
    ]);
    $command->registerCommand('about', '**Bot Server Discord StayWait**\nDibuat oleh Kygekraqmak menggunakan bahasa pemrograman PHP.', [
        'description' => 'Tentang bot server Discord StayWait'
    ]);
}

function status($discordCommandClient)
{
    $discordCommandClient->on('ready', function ($discord) {
        $activity = $discord->factory(Activity::class, [
            'name' => '&help',
            'type' => Activity::TYPE_LISTENING
        ]);
        try {
            $discord->updatePresence($activity);
        } catch (\Exception $exception) {
            echo $exception->getMessage() . PHP_EOL;
        }
    });
}

commands($discordCommandClient);
status($discordCommandClient);

$discordCommandClient->run();

try this:

		/** @var Activity $activity */
		$activity = $this->factory(Activity::class);
		$activity->name = "&help";
		$activity->type = Activity::TYPE_LISTENING;
		$this->updatePresence($activity, false, "online", false);

@Kygekraqmak