Skip to content
SQKo edited this page Jul 24, 2022 · 30 revisions

Guilds are part of discord. Guilds are known as 'Discord Servers' in the Discord application.

use Discord\Parts\Guild\Guild;

A Guild is Discord's equivalent of a server. It contains all the Members, Channels, Roles, Bans etc.

Return

  • float the timestamp of when the guild was created.

Example

echo $guild->createdTimestamp();
function createRole([array<string|int, mixed> $data = [] ]) : ExtendedPromiseInterface

Creates a role in the guild with a given array of attributes. Returns the created role in a promise.

https://discord.com/developers/docs/resources/guild#create-guild-role

Example

$guild->createRole([
    // All options are optional
    'name' => 'PHP',
    'hoist' => true,
    'mentionable' => false,
    // more options in Docs
])->done(function (Role $role) {
    echo "Created role {$role->name}";
});

Returns an audit log object for the query.

https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log

Example

$guild->getAuditLog([
    'user_id' => '123123123123123123'
    'action_type' => Entry::MEMBER_KICK,
    // more options from Docs
])->done(function (AuditLog $auditLog) {
    var_dump($auditLog);
});

Returns the channels invites.

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

function getInvites() : ExtendedPromiseInterface

Retrieves a list of invites in the guild. Returns a collection of invites in a promise.

Example

$guild->getInvites()->done(function (Collection $invites) {
    foreach ($invites as $invite) {
        echo "Invite code {$invite->code} on {$invite->channel->name}";
    }
});
function getVoiceRegions() : ExtendedPromiseInterface

Retrieves a list of valid voice regions. Returns a collection of objects describing voice regions in a promise.

https://discord.com/developers/docs/resources/voice#list-voice-regions

Leaves the guild. Alias for $discord->guilds->leave($guild->id).

https://discord.com/developers/docs/resources/user#leave-guild

Example

$guild->leave();
function transferOwnership(Member|int $member) : ExtendedPromiseInterface

Transfers the ownership of the guild to another member. The bot must be the owner of the guild. Returns a promise with no data.

Unbans a member. Alias for $guild->bans->unban($user).

https://discord.com/developers/docs/resources/guild#remove-guild-ban

function unban(User|string $user) : ExtendedPromiseInterface

Example

$guild->unban('123123123123123123');

Updates the positions of a list of given roles.

https://discord.com/developers/docs/resources/guild#modify-guild-role-positions

Validates the specified region.

Requires GUILD intent

GUILD_CREATE

GUILD_DELETE

GUILD_UPDATE


Get a Specific Guild

Your BOT must be member of the guild

Change 123123123123123123 below with the Guild ID you want to retrieve

Cached, synchronous:

$guild = $discord->guilds->get('id', '123123123123123123');
// Or using offsetGet
$guild = $discord->guilds['123123123123123123'];

Cached Guild can be also retrieved from related objects:

  • AuditLog $guild = $auditLog->guild; guild where the Audit Log is part of
  • Ban $guild = $ban->guild; guild where the ban is part of
  • Channel $guild = $channel->guild; guild where the channel is part of
  • Emoji $guild = $emoji->guild; guild where the emoji is part of
  • Invite $guild = $invite->guild; guild where the invite is for
  • Member $guild = $member->guild; guild where the member is part of
  • Message $guild = $message->guild; guild where the message is on
  • Role $guild = $role->guild; guild where the role is part of
  • Webhook $guild = $webhook->guild; guild where the webhook is part of

If the code above returns null (which most likely won't since guilds are always cached), you may need to fetch it first (Promise, asynchronous):

$discord->guilds->fetch('123123123123123123')->done(function (Guild $guild) {
    // ...
});
Clone this wiki locally