Skip to content

Commit 3d2cba9

Browse files
committed
Guild::fetchVanityUrl()
1 parent 2577cb2 commit 3d2cba9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Discord/Parts/Channel/Channel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ public function sendSoundboardSound(string $sound_id, ?string $source_guild_id =
684684
*
685685
* @param string $webhookChannelId ID of the channel to receive crossposted messages.
686686
*
687-
* @return PromiseInterface<array{channel: Channel|int, webhook: int}>
687+
* @return PromiseInterface<array{channel: Channel|int, webhook: int}>
688688
*
689689
* @since 10.46.0
690690
*/

src/Discord/Parts/Guild/Guild.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,42 @@ public function getCurrentUserVoiceState(): PromiseInterface
655655
return $this->voice_states->getCurrentUserVoiceState($this->id);
656656
}
657657

658+
/**
659+
* Returns a partial invite object for guilds with that feature enabled.
660+
*
661+
* Requires the `MANAGE_GUILD` permission. `code` will be null if a vanity url for the guild is not set.
662+
*
663+
* @link https://docs.discord.com/developers/resources/guild#get-guild-vanity-url
664+
*
665+
* @return PromiseInterface<string|null> Vanity URL code or null if no vanity URL is set.
666+
*/
667+
public function fetchVanityUrl(): PromiseInterface
668+
{
669+
if ($botperms = $this->getBotPermissions()) {
670+
if (! $botperms->manage_guild) {
671+
return reject(new NoPermissionsException("You do not have permission to get the vanity URL for the guild {$this->id}."));
672+
}
673+
}
674+
675+
return $this->http->get(Endpoint::bind(Endpoint::GUILD_VANITY_URL, $this->id))
676+
->then(function ($response) {
677+
$response = (array) $response;
678+
679+
if (! isset($response['code'])) {
680+
return null;
681+
}
682+
683+
if ($invite = $this->invites->get('code', $response['code'])) {
684+
return (string) $invite;
685+
}
686+
687+
$invite = new Invite($this->discord, $response, true);
688+
$this->invites->pushItem($invite);
689+
690+
return (string) $invite;
691+
});
692+
}
693+
658694
/**
659695
* Modify the current user's voice state in the guild.
660696
*

0 commit comments

Comments
 (0)