File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 2121use Discord \Repository \Guild \IntegrationRepository ;
2222use 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 */
You can’t perform that action at this time.
0 commit comments