-
Notifications
You must be signed in to change notification settings - Fork 237
Guild
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.
name | type | notes |
---|---|---|
roles | Role | |
emojis | Emoji | |
members | Member | May not contain offline members, see the loadAllMembers option
|
channels | Channel | |
stage_instances | StageInstance | |
guild_scheduled_events | ScheduledEvent | |
stickers | Sticker | |
invites | Invite | Not initially loaded |
bans | Ban | Not initially loaded without retrieveBans option
|
commands | Command | Not initially loaded |
templates | GuildTemplate | Not initially loaded |
integrations | Integration | Not initially loaded |
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.
Shortcut for $guild->roles->save($role);
Returns the created role in a promise.
https://discord.com/developers/docs/resources/guild#create-guild-role
name | type | description | default |
---|---|---|---|
name | string | Role name | new role |
permissions | string | Bitwise value of permissions | @everyone permissions |
color | integer | RGB color value | 0 |
hoist | bool | Hoisted role? | false |
icon | string | image data for Role icon | null |
unicode_emoji | string | unicode emoji for Role icon | null |
mentionable | bool | Mentionable role? | false |
Example
$guild->createRole([
// All options are optional
'name' => 'PHP',
'hoist' => true,
'mentionable' => false,
// more options in Docs
])
->then(function (Role $role) {
echo "Created role {$role->name}";
})
->done();
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 in Docs
])->then(function (AuditLog $auditLog) {
var_dump($auditLog);
})->done();
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()->then(function (Collection $invites) {
foreach ($invites as $invite) {
echo "Invite code {$invite->code} on {$invite->channel->name}";
}
})->done();
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. Takes a member object or a member ID. Returns a promise with no data.
name | type | description |
---|---|---|
member | Member or member ID | The member to get ownership |
reason | string | Reason for Audit Log |
Example
$guild->transferOwnership($member)->then(...)->done();
// or
$guild->transferOwnership('member_id')->then(...)->done();
Unbans a member when passed a User
object or a user ID. Alias for $guild->bans->unban($user)
. If you have the ban object, you can do $guild->bans->delete($ban);
https://discord.com/developers/docs/resources/guild#remove-guild-ban
function unban(User|string $user) : ExtendedPromiseInterface
name | type | description |
---|---|---|
user_id |
User or user ID |
The user to unban |
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.
-
BanRepository
$guild->bans
-
ChannelRepository
$guild->channels
-
EmojiRepository
$guild->emojis
-
InviteRepository
$guild->invites
-
MemberRepository
$guild->members
-
RoleRepository
$guild->roles
Requires GUILD
intent
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')->then(function (Guild $guild) {
// ...
})->done();
Note: This wiki is currently Work In Progress. Consider reading the docs instead.
- Application Command (Slash based)
Command Client (Message based)
- Activity
- Application
- Guild
- Private Channel
- User
Components
-
ActionRow
- Buttons
- Option (commands)
- SelectMenu
- TextInput
Builders