diff --git a/src/Discord/Parts/Channel/Channel.php b/src/Discord/Parts/Channel/Channel.php index 507db9a41..3c262ded9 100644 --- a/src/Discord/Parts/Channel/Channel.php +++ b/src/Discord/Parts/Channel/Channel.php @@ -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 */ public function moveMember($member, ?string $reason = null): PromiseInterface { @@ -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 */ public function muteMember($member, ?string $reason = null): PromiseInterface { @@ -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 */ public function unmuteMember($member, ?string $reason = null): PromiseInterface { @@ -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 + */ + 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 + */ + 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. *