Skip to content

Commit

Permalink
Deafen and Undeafen members
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Dec 30, 2024
1 parent 784f9ef commit 6bba767
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/Discord/Parts/Channel/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,76 @@ public function unmuteMember($member, ?string $reason = null): PromiseInterface
return $this->http->patch(Endpoint::bind(Endpoint::GUILD_MEMBER, $this->guild_id, $member), ['mute' => false], $headers);
}

/**
* Deafens a member on a voice channel.
*
* @param Member|string $member The member to deafen. (either a Member part or the member ID)
* @param string|null $reason Reason for Audit Log.
*
* @throws \RuntimeException
* @throws NoPermissionsException Missing deafen_members permission.
*
* @return PromiseInterface
*/
public function deafenMember($member, ?string $reason = null): PromiseInterface
{
if (! $this->isVoiceBased()) {
return reject(new \RuntimeException('You cannot deafen a member in a text channel.'));
}

if ($botperms = $this->getBotPermissions()) {
if (! $botperms->deafen_members) {
return reject(new NoPermissionsException("You do not have permission to deafen members in the channel {$this->id}."));
}
}

if ($member instanceof Member) {
$member = $member->id;
}

$headers = [];
if (isset($reason)) {
$headers['X-Audit-Log-Reason'] = $reason;
}

return $this->http->patch(Endpoint::bind(Endpoint::GUILD_MEMBER, $this->guild_id, $member), ['deaf' => true], $headers);
}

/**
* Undeafens a member on a voice channel.
*
* @param Member|string $member The member to undeafen. (either a Member part or the member ID)
* @param string|null $reason Reason for Audit Log.
*
* @throws \RuntimeException
* @throws NoPermissionsException Missing deafen_members permission.
*
* @return PromiseInterface
*/
public function undeafenMember($member, ?string $reason = null): PromiseInterface
{
if (! $this->isVoiceBased()) {
return reject(new \RuntimeException('You cannot deafen a member in a text channel.'));
}

if ($botperms = $this->getBotPermissions()) {
if (! $botperms->deafen_members) {
return reject(new NoPermissionsException("You do not have permission to deafen members in the channel {$this->id}."));
}
}

if ($member instanceof Member) {
$member = $member->id;
}

$headers = [];
if (isset($reason)) {
$headers['X-Audit-Log-Reason'] = $reason;
}

return $this->http->patch(Endpoint::bind(Endpoint::GUILD_MEMBER, $this->guild_id, $member), ['deaf' => false], $headers);
}

/**
* Creates an invite for the channel.
*
Expand Down

0 comments on commit 6bba767

Please sign in to comment.