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
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')->done(function (Ban $ban) {
// ...
});
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')->done(function () {
// ...
});
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
$member->moveMember($channel)->done(function () {
// ...
});
// or
$member->moveMember('123451231231')->done(function () {
// ...
});
Add member to role
Adds the member to a role. Takes a role or role ID and returns nothing in a promise.
Parameters
$member->addRole($role)->done(function () {
// ...
});
// or
$member->addRole('1231231231')->done(function () {
// ...
});
Remove member from role
Removes the member from a role. Takes a role or role ID and returns nothing in a promise.
Parameters
$member->removeRole($role)->done(function () {
// ...
});
// or
$member->removeRole('1231231231')->done(function () {
// ...
});
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 |
---|---|---|
communicationdisableduntil | Carbon or null |
the time for timeout to lasts on |
$member->timeoutMember(new Carbon('6 hours'))->done(function () {
// ...
});
// to remove
$member->timeoutMember()->done(function () {
// ...
});
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
$member->getPermissions($channel)->done(function (RolePermission $permission) {
// ...
});
// or
$member->getPermissions()->done(function (RolePermission $permission) {
// ...
});
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