Skip to content

Commit bf31159

Browse files
committed
Integration::sync()
1 parent 8903989 commit bf31159

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/Discord/Parts/Guild/Integration.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Discord\Repository\Guild\IntegrationRepository;
2222
use React\Promise\PromiseInterface;
2323

24+
use function React\Promise\reject;
25+
2426
/**
2527
* An Integration is a guild integrations for Twitch, YouTube, Bot and Apps.
2628
*
@@ -195,6 +197,41 @@ public function save(?string $reason = null): PromiseInterface
195197
return parent::save();
196198
}
197199

200+
/**
201+
* Syncs an integration for the guild.
202+
*
203+
* Requires the `MANAGE_GUILD` permission.
204+
*
205+
* Returns a 204 empty response on success.
206+
*
207+
* Fires Guild Integrations Update and Integration Update Gateway events.
208+
*
209+
* @link https://discord.com/developers/docs/resources/guild#sync-guild-integration
210+
*
211+
* @return PromiseInterface<Integration>
212+
*/
213+
public function sync(): PromiseInterface
214+
{
215+
if (! isset($this->attributes['guild_id'])) {
216+
return reject(new \Exception('Integration does not belong to a guild.'));
217+
}
218+
219+
/** @var Guild $guild */
220+
$guild = $this->guild ?? $this->factory->part(Guild::class, ['id' => $this->attributes['guild_id']], true);
221+
222+
if ($botperms = $guild->getBotPermissions()) {
223+
if (! $botperms->manageGuild) {
224+
return reject(new \Exception('The bot requires the MANAGE_GUILD permission to sync this integration.'));
225+
}
226+
}
227+
228+
return $guild->integrations->sync($this->id)->then(function ($response) {
229+
$this->fill((array) $response);
230+
231+
return $this;
232+
});
233+
}
234+
198235
/**
199236
* @inheritDoc
200237
*/

0 commit comments

Comments
 (0)