Discord PHP Create Invite link From Channel ID

Viewed 340

I am developing a discord bot with php. I want to create invite link via DiscordPHP package.

Here what I write

include __DIR__.'/vendor/autoload.php';
use Discord\Discord;
$discord = new Discord([
    'token' => 'MY_TOKKEN',
]);
$discord->on('ready', function ($discord) {
    echo "Bot is ready!", PHP_EOL;
    $discord->on('message', function ($message, $discord) {
        $channel = $message->channel;
        $channel->createInvite([
            'max_age' => 60,
            'max_uses' => 5,
        ])->done(function (Invite $invite) {
            echo $invite->code;
        });
    });
});
$discord->run();

From echo $invite->code; I didn't getting any response string which I acn use to share.

1 Answers

I do not know discord lib , but you can debug by make var_dump($invite) and check result if you getting anything My update run this

include __DIR__.'/vendor/autoload.php';
use Discord\Discord;
$discord = new Discord([
    "token" => "your token",
]);
$discord->on('ready', function ($discord) {
    echo "Bot is ready!", PHP_EOL;
    $discord->on('message', function ($message, $discord) {
        $channel = $message->channel;
        $channel->createInvite([
            'max_age' => 60,
            'max_uses' => 5,
        ])->done(function (Invite $invite) {
            echo $invite->code;
        });
    });
}); $discord->run();

and check permissions on your discord that bot allowed to make invite

Related