Skip to content
SQKo edited this page Dec 9, 2023 · 3 revisions

Invites are part of Channel.

use Discord\Parts\Channel\Invite;

An invite to a Channel and Guild.

Requires GUILD_INVITES intent

INVITE_CREATE

INVITE_DELETE


Create an Invite in the Channel

Your BOT must have create_instant_invite permission

You must first get the Channel object to use the code below

Create an $invite to $channel with topic 60 seconds expiry and 5 limits:

$channel->createInvite([
    // All options are optional
    'max_age' => 60, // 1 minute
    'max_uses' => 5, // 5 uses
    // more options in Docs
])->then(function (Invite $invite) {
    echo "Here is the invite link: {$invite->invite_url}";
})->done();

https://discord.com/developers/docs/resources/channel#create-channel-invite

Get Invites of a Channel

You must first get the Channel object to use the code below.

Get all $invites to $channel:

$channel->getInvites()->then(function (Collection $invites) {
    foreach ($invites as $invite) {
        // ...
    }
})->done();

https://discord.com/developers/docs/resources/channel#get-channel-invites

Get a Specific Invite in a Guild

You must first get the Guild object to use the code below. Change abc123 below with the Invite code you want to retrieve

Cached, synchronous:

$invite = $guild->invites->get('code', 'abc123');

If the code above returns null, you may need to fetch it first (Promise, asynchronous):

$guild->invites->fetch('abc123')->then(function (Invite $invite) {
    // ...
})->done();

https://discord.com/developers/docs/resources/invite#get-invite

Clone this wiki locally