mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
feat: Guild Integrations (#2760)
* feat: Guild Integrations * feat: Guild#createIntegration * feat: Add ws event GUILD_INTEGRATIONS_UPDATE * docs: Add `GUILD_INTEGRATIONS_UPDATE` to WSEventType * misc: Fixed requested change * docs: Updated typings * typings: Sort members by name
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const Invite = require('./Invite');
|
||||
const Integration = require('./Integration');
|
||||
const GuildAuditLogs = require('./GuildAuditLogs');
|
||||
const Webhook = require('./Webhook');
|
||||
const VoiceRegion = require('./VoiceRegion');
|
||||
@@ -407,6 +408,42 @@ class Guild extends Base {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of integrations to this guild.
|
||||
* Resolves with a collection mapping integrations by their ids.
|
||||
* @returns {Promise<Collection<string, Integration>>}
|
||||
* @example
|
||||
* // Fetch integrations
|
||||
* guild.fetchIntegrations()
|
||||
* .then(integrations => console.log(`Fetched ${integrations.size} integrations`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchIntegrations() {
|
||||
return this.client.api.guilds(this.id).integrations.get().then(data =>
|
||||
data.reduce((collection, integration) =>
|
||||
collection.set(integration.id, new Integration(this.client, integration, this)),
|
||||
new Collection())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The data for creating an integration.
|
||||
* @typedef {Object} IntegrationData
|
||||
* @property {string} id The integration id
|
||||
* @property {string} type The integration type
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates an integration by attaching an integration object
|
||||
* @param {IntegrationData} data The data for thes integration
|
||||
* @param {string} reason Reason for creating the integration
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
createIntegration(data, reason) {
|
||||
return this.client.api.guilds(this.id).integrations.post({ data, reason })
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of invites to this guild.
|
||||
* Resolves with a collection mapping invites by their codes.
|
||||
|
||||
Reference in New Issue
Block a user