mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat: add support for guild templates (#4907)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -4,6 +4,7 @@ const { deprecate } = require('util');
|
||||
const Base = require('./Base');
|
||||
const GuildAuditLogs = require('./GuildAuditLogs');
|
||||
const GuildPreview = require('./GuildPreview');
|
||||
const GuildTemplate = require('./GuildTemplate');
|
||||
const Integration = require('./Integration');
|
||||
const Invite = require('./Invite');
|
||||
const VoiceRegion = require('./VoiceRegion');
|
||||
@@ -733,6 +734,20 @@ class Guild extends Base {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of templates from this guild.
|
||||
* Resolves with a collection mapping templates by their codes.
|
||||
* @returns {Promise<Collection<string, GuildTemplate>>}
|
||||
*/
|
||||
fetchTemplates() {
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.templates.get()
|
||||
.then(templates =>
|
||||
templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The data for creating an integration.
|
||||
* @typedef {Object} IntegrationData
|
||||
@@ -753,6 +768,19 @@ class Guild extends Base {
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a template for the guild.
|
||||
* @param {string} name The name for the template
|
||||
* @param {string} [description] The description for the template
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
*/
|
||||
createTemplate(name, description) {
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.templates.post({ data: { name, description } })
|
||||
.then(data => new GuildTemplate(this.client, data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a collection of invites to this guild.
|
||||
* Resolves with a collection mapping invites by their codes.
|
||||
|
||||
Reference in New Issue
Block a user