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

Members can be either part of Guild or Voice Channel. See User for Discord User object.

use Discord\Parts\User\Member;

This requires SERVER MEMBERS INTENT && configure in Discord call.

$discord = new Discord([
        'token' => 'YOURTOKEN',
	'intents' => Intents::getDefaultIntents() | Intents::GUILD_MEMBERS,
]);

https://discord.com/developers/applications/yourapp/bot

A member is a relationship between a user and a guild. It contains user-to-guild specific data like roles.

function addRole(Role|string $role) : ExtendedPromiseInterface
function ban([int|null $daysToDeleteMessages = null ][, string|null $reason = null ]) : ExtendedPromiseInterface
function getPermissions([Channel|null $channel = null ]) : RolePermission
function moveMember(Channel|string $channel) : ExtendedPromiseInterface
function removeRole(Role|string $role) : ExtendedPromiseInterface
function setNickname([string|null $nick = null ]) : ExtendedPromiseInterface
function sendMessage(MessageBuilder $message) : ExtendedPromiseInterface

Requires GUILD_MEMBERS intent

GUILD_MEMBER_ADD

GUILD_MEMBER_REMOVE

GUILD_MEMBER_UPDATE


Get a Specific Member

Retrieving a Guild Member requires GUILD_MEMBERS intent

You must first get the Guild object to use the code below. Change 123123123123123123 below with the User ID you want to retrieve

Cached, synchrounous (i.e. loadAllMembers option is true):

$member = $guild->members->get('id', '123123123123123123');

Cached Member can be also retrieved from related objects:

  • Message $member = $message->member; member who sent the message (only in a guild)

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

$guild->members->fetch('123123123123123123')->then(function (Member $member) {
    // ...
})->done();

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

Set a Nickname of a Member

Your BOT must have manage_nicknames permission

Set $member nick name to "newnick":

$member->setNickname('newnick')->then(function () {
    // ...
})->done();

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

Clone this wiki locally