Skip to content

Commit

Permalink
Deafen and Undeafen members (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming authored Jan 17, 2025
1 parent 229597f commit 9ddea44
Showing 1 changed file with 75 additions and 5 deletions.
80 changes: 75 additions & 5 deletions src/Discord/Parts/Channel/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public function setCategory($category, ?int $position = null, ?string $reason =
* @throws \RuntimeException
* @throws NoPermissionsException Missing move_members permission.
*
* @return PromiseInterface
* @return PromiseInterface<Member>
*/
public function moveMember($member, ?string $reason = null): PromiseInterface
{
Expand Down Expand Up @@ -506,10 +506,10 @@ public function moveMember($member, ?string $reason = null): PromiseInterface
* @param Member|string $member The member to mute. (either a Member part or the member ID)
* @param string|null $reason Reason for Audit Log.
*
* @throws \RuntimeException
* @throws \RuntimeException Channel is not voice-based.
* @throws NoPermissionsException Missing mute_members permission.
*
* @return PromiseInterface
* @return PromiseInterface<Member>
*/
public function muteMember($member, ?string $reason = null): PromiseInterface
{
Expand Down Expand Up @@ -541,10 +541,10 @@ public function muteMember($member, ?string $reason = null): PromiseInterface
* @param Member|string $member The member to unmute. (either a Member part or the member ID)
* @param string|null $reason Reason for Audit Log.
*
* @throws \RuntimeException
* @throws \RuntimeException Channel is not voice-based.
* @throws NoPermissionsException Missing mute_members permission.
*
* @return PromiseInterface
* @return PromiseInterface<Member>
*/
public function unmuteMember($member, ?string $reason = null): PromiseInterface
{
Expand All @@ -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 in the 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 Channel is not voice-based.
* @throws NoPermissionsException Missing deafen_members permission.
*
* @return PromiseInterface<Member>
*/
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 in the 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 Channel is not voice-based.
* @throws NoPermissionsException Missing deafen_members permission.
*
* @return PromiseInterface<Member>
*/
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 9ddea44

Please sign in to comment.