Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deafen and Undeafen members #1272

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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