Member
Members represent a user in a guild. There is a member object for every guild-user relationship, meaning that there will be multiple member objects in the Discord client with the same user ID, but they will belong to different guilds.
A member object can also be serialised into a mention string. For example:
$discord->on(Event::MESSAGE_CREATE, function (Message $message) {
// Hello <@member_id>!
// Note: `$message->member` will be `null` if the message originated from
// a private message, or if the member object was not cached.
$message->channel->sendMessage('Hello '.$message->member.'!');
});
Properties
name | type | description |
---|---|---|
user | User | the user part of the member | | |
nick | string | the nickname of the member |
avatar | ?string | The guild avatar URL of the member |
avatar_hash | ?string | The guild avatar hash of the member |
roles | Collection of Roles | roles the member is a part of | | |
joined_at | Carbon
timestamp |
when the member joined the guild |
deaf | bool | whether the member is deafened |
mute | bool | whether the member is muted |
pending | ?string | whether the user has not yet passed the guild’s Membership Screening requirements |
communication_disabled_until | ?Carbon
|
when the user’s timeout will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out |
id | string | the user ID of the member |
username | string | the username of the member |
discriminator | string | the four digit discriminator of the member |
displayname | string | nick/username#discriminator |
guild | Guild | the guild the member is a part of | | |
guild_id | string | the id of the guild the member is a part of |
string | status | the status of the member |
game | Activity | the current activity of the member | | |
premium_since | Carbon
timestamp |
when the member started boosting the guild |
activities | Collection of Activities | the current activities of the member | |
Ban the member
Bans the member from the guild. Returns a Ban part in a promise.
Parameters
name | type | description |
---|---|---|
daysToDelete | int | number of days back to delete messages, default none |
reason | string | reason for the ban |
$member->ban(5, 'bad person')->then(function (Ban $ban) {
// ...
})->done();
Set the nickname of the member
Sets the nickname of the member. Requires the MANAGE_NICKNAMES
permission or CHANGE_NICKNAME
if changing self nickname. Returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
nick | string | nickname of the member, null to clear, default null |
$member->setNickname('newnick')->then(function () {
// ...
})->done();
Move member to channel
Moves the member to another voice channel. Member must already be in a voice channel. Takes a channel or channel ID and returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
channel | Channel or string | the channel to move the member to | |
$member->moveMember($channel)->then(function () {
// ...
})->done();
// or
$member->moveMember('123451231231')->then(function () {
// ...
})->done();
Add member to role
Adds the member to a role. Takes a role or role ID and returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
role | Role or string | he role to add the member to |
$member->addRole($role)->then(function () {
// ...
})->done();
// or
$member->addRole('1231231231')->then(function () {
// ...
})->done();
Remove member from role
Removes the member from a role. Takes a role or role ID and returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
role | Role or string | he role to remove the member from |
$member->removeRole($role)->then(function () {
// ...
})->done();
// or
$member->removeRole('1231231231')->then(function () {
// ...
})->done();
Timeout member
Times out the member in the server. Takes a carbon or null to remove. Returns nothing in a promise.
Parameters
name | type | description |
---|---|---|
communication_disabled_until | Carbon
or null
|
the time for timeout to lasts on |
$member->timeoutMember(new Carbon('6 hours'))->then(function () {
// ...
})->done();
// to remove
$member->timeoutMember()->then(function () {
// ...
})->done();
Get permissions of member
Gets the effective permissions of the member: - When given a channel, returns the effective permissions of a member in a channel. - Otherwise, returns the effective permissions of a member in a guild.
Returns a role permission in a promise.
Parameters
name | type | description |
---|---|---|
channel | Channel or null | the channel to get the effective permissions for | |
$member->getPermissions($channel)->then(function (RolePermission $permission) {
// ...
})->done();
// or
$member->getPermissions()->then(function (RolePermission $permission) {
// ...
})->done();
Get guild specific avatar URL
Gets the server-specific avatar URL for the member. Only call this function if you need to change the format or size of the image, otherwise use $member->avatar
. Returns a string.
Parameters
name | type | description |
---|---|---|
format | string | format of the image, one of png, jpg or webp, default webp and gif if animated |
size | int | size of the image, default 1024 |
$url = $member->getAvatarAttribute('png', 2048);
echo $url; // https://cdn.discordapp.com/guilds/:guild_id/users/:id/avatars/:avatar_hash.png?size=2048