|
14 | 14 | namespace Discord\Repository\Guild; |
15 | 15 |
|
16 | 16 | use Discord\Http\Endpoint; |
| 17 | +use Discord\Http\Exceptions\NoPermissionsException; |
17 | 18 | use Discord\Parts\User\Member; |
18 | 19 | use Discord\Repository\AbstractRepository; |
19 | 20 | use React\Promise\Deferred; |
20 | 21 | use React\Promise\PromiseInterface; |
21 | 22 |
|
| 23 | +use function React\Promise\reject; |
| 24 | + |
22 | 25 | /** |
23 | 26 | * Contains members of a guild. |
24 | 27 | * |
@@ -46,6 +49,44 @@ class MemberRepository extends AbstractRepository |
46 | 49 | ]; |
47 | 50 |
|
48 | 51 | /** |
| 52 | + * Modifies the current member (no validation). |
| 53 | + * |
| 54 | + * @link https://discord.com/developers/docs/resources/guild#modify-current-member-json-params |
| 55 | + * |
| 56 | + * @since 10.20.0 |
| 57 | + * |
| 58 | + * @param array $params The parameters to modify. |
| 59 | + * @param ?string|null $params['nick'] Value to set user's nickname to. |
| 60 | + * @param ?string|null $params['banner'] Data URI base64 encoded banner image. |
| 61 | + * @param ?string|null $params['avatar'] Data URL base64 encoded avatar image. |
| 62 | + * @param ?string|null $params['bio'] Guild member bio. |
| 63 | + * @param string|null $reason Reason for Audit Log. |
| 64 | + * |
| 65 | + * @return PromiseInterface<self> |
| 66 | + */ |
| 67 | + public function modifyCurrentMember(array $params, ?string $reason = null): PromiseInterface |
| 68 | + { |
| 69 | + $allowed = ['nick', 'banner', 'avatar', 'bio']; |
| 70 | + $params = array_filter( |
| 71 | + $params, |
| 72 | + fn ($key) => in_array($key, $allowed, true), |
| 73 | + ARRAY_FILTER_USE_KEY |
| 74 | + ); |
| 75 | + |
| 76 | + if (empty($params)) { |
| 77 | + return reject(new \InvalidArgumentException('No valid parameters to modify.')); |
| 78 | + } |
| 79 | + |
| 80 | + $headers = []; |
| 81 | + if (isset($reason)) { |
| 82 | + $headers['X-Audit-Log-Reason'] = $reason; |
| 83 | + } |
| 84 | + |
| 85 | + return $this->http->patch(Endpoint::bind(Endpoint::GUILD_MEMBER_SELF, $this->guild_id), $params, $headers); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * {@inheritDoc} |
49 | 90 | * @inheritDoc |
50 | 91 | */ |
51 | 92 | protected $class = Member::class; |
|
0 commit comments