mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat(Managers): ✨ Add GuildInviteManager (#5889)
Co-authored-by: iShibi <shubhamparihar391@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: SpaceEEC <SpaceEEC@users.noreply.github.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: iCrawl <icrawltogo@gmail.com>
This commit is contained in:
@@ -5,7 +5,6 @@ const GuildAuditLogs = require('./GuildAuditLogs');
|
||||
const GuildPreview = require('./GuildPreview');
|
||||
const GuildTemplate = require('./GuildTemplate');
|
||||
const Integration = require('./Integration');
|
||||
const Invite = require('./Invite');
|
||||
const Webhook = require('./Webhook');
|
||||
const WelcomeScreen = require('./WelcomeScreen');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
@@ -586,35 +585,6 @@ class Guild extends AnonymousGuild {
|
||||
.then(data => new GuildTemplate(this.client, data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of invites to this guild.
|
||||
* Resolves with a collection mapping invites by their codes.
|
||||
* @returns {Promise<Collection<string, Invite>>}
|
||||
* @example
|
||||
* // Fetch invites
|
||||
* guild.fetchInvites()
|
||||
* .then(invites => console.log(`Fetched ${invites.size} invites`))
|
||||
* .catch(console.error);
|
||||
* @example
|
||||
* // Fetch invite creator by their id
|
||||
* guild.fetchInvites()
|
||||
* .then(invites => console.log(invites.find(invite => invite.inviter.id === '84484653687267328')))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchInvites() {
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.invites.get()
|
||||
.then(inviteItems => {
|
||||
const invites = new Collection();
|
||||
for (const inviteItem of inviteItems) {
|
||||
const invite = new Invite(this.client, inviteItem);
|
||||
invites.set(invite.code, invite);
|
||||
}
|
||||
return invites;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a guild preview for this guild from Discord.
|
||||
* @returns {Promise<GuildPreview>}
|
||||
|
||||
@@ -475,7 +475,7 @@ class GuildAuditLogsEntry {
|
||||
if (me.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
let change = this.changes.find(c => c.key === 'code');
|
||||
change = change.new ?? change.old;
|
||||
return guild.fetchInvites().then(invites => {
|
||||
return guild.invites.fetch().then(invites => {
|
||||
this.target = invites.find(i => i.code === change);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const Channel = require('./Channel');
|
||||
const Invite = require('./Invite');
|
||||
const PermissionOverwrites = require('./PermissionOverwrites');
|
||||
const { Error } = require('../errors');
|
||||
const PermissionOverwriteManager = require('../managers/PermissionOverwriteManager');
|
||||
@@ -470,46 +469,18 @@ class GuildChannel extends Channel {
|
||||
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
createInvite({
|
||||
temporary = false,
|
||||
maxAge = 86400,
|
||||
maxUses = 0,
|
||||
unique,
|
||||
targetUser,
|
||||
targetApplication,
|
||||
targetType,
|
||||
reason,
|
||||
} = {}) {
|
||||
return this.client.api
|
||||
.channels(this.id)
|
||||
.invites.post({
|
||||
data: {
|
||||
temporary,
|
||||
max_age: maxAge,
|
||||
max_uses: maxUses,
|
||||
unique,
|
||||
target_user_id: this.client.users.resolveId(targetUser),
|
||||
target_application_id: targetApplication?.id ?? targetApplication?.applicationId ?? targetApplication,
|
||||
target_type: targetType,
|
||||
},
|
||||
reason,
|
||||
})
|
||||
.then(invite => new Invite(this.client, invite));
|
||||
createInvite(options) {
|
||||
return this.guild.invites.create(this.id, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of invites to this guild channel.
|
||||
* Resolves with a collection mapping invites by their codes.
|
||||
* @param {boolean} [cache=true] Whether or not to cache the fetched invites
|
||||
* @returns {Promise<Collection<string, Invite>>}
|
||||
*/
|
||||
async fetchInvites() {
|
||||
const inviteItems = await this.client.api.channels(this.id).invites.get();
|
||||
const invites = new Collection();
|
||||
for (const inviteItem of inviteItems) {
|
||||
const invite = new Invite(this.client, inviteItem);
|
||||
invites.set(invite.code, invite);
|
||||
}
|
||||
return invites;
|
||||
fetchInvites(cache = true) {
|
||||
return this.guild.invites.fetch({ channelID: this.id, cache });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user