Skip to content

Commit 4841917

Browse files
committed
fix: implement requested changes from @SpaceEEC
1 parent 4817df1 commit 4841917

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/client/Client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class Client extends BaseClient {
260260
* @param {GuildTemplateResolvable} template Template code or URL
261261
* @returns {Promise<GuildTemplate>}
262262
* @example
263-
* client.fetchGuildTemplate('https://discord.com/template/FKvmczH2HyUf')
263+
* client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
264264
* .then(template => console.log(`Obtained template with code: ${template.code}`))
265265
* .catch(console.error);
266266
*/

src/structures/GuildTemplate.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GuildTemplate extends Base {
5151

5252
/**
5353
* The ID of the user that created this template
54-
* @type {string}
54+
* @type {Snowflake}
5555
*/
5656
this.creatorID = data.creator_id;
5757

@@ -75,15 +75,16 @@ class GuildTemplate extends Base {
7575

7676
/**
7777
* The ID of the guild that this template belongs to
78-
* @type {string}
78+
* @type {Snowflake}
7979
*/
8080
this.guildID = data.source_guild_id;
8181

8282
/**
83-
* The guild that this template belongs to
84-
* @type {Guild}
83+
* The data of the guild that this template would create
84+
* @type {Object}
85+
* @see {@link https://discord.com/developers/docs/resources/guild#guild-resource}
8586
*/
86-
this.guild = this.client.guilds.add(data.serialized_source_guild, false);
87+
this.serializedGuild = data.serialized_source_guild;
8788

8889
/**
8990
* Whether this template has unsynced changes
@@ -173,6 +174,32 @@ class GuildTemplate extends Base {
173174
.then(data => this._patch(data));
174175
}
175176

177+
/**
178+
* The timestamp of when this template was created at
179+
* @type {number}
180+
* @readonly
181+
*/
182+
get createdTimestamp() {
183+
return this.createdAt.getTime();
184+
}
185+
186+
/**
187+
* The timestamp of when this template was last synced to the guild
188+
* @type {number}
189+
* @readonly
190+
*/
191+
get updatedTimestamp() {
192+
return this.updatedAt.getTime();
193+
}
194+
195+
/**
196+
* The guild that this template belongs to
197+
* @type {?Guild}
198+
* @readonly
199+
*/
200+
get guild() {
201+
return this.client.guilds.get(this.guildID) || null;
202+
}
176203
/**
177204
* The URL of this template
178205
* @type {string}

src/util/Constants.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ exports.DefaultOptions = {
8181
* @property {string} [api='https://discord.com/api'] Base url of the API
8282
* @property {string} [cdn='https://cdn.discordapp.com'] Base url of the CDN
8383
* @property {string} [invite='https://discord.gg'] Base url of invites
84-
* @property {string} [template='https://discord.com/template'] Base url of templates
84+
* @property {string} [template='https://discord.new'] Base url of templates
8585
*/
8686
http: {
8787
version: 7,
8888
api: 'https://discord.com/api',
8989
cdn: 'https://cdn.discordapp.com',
9090
invite: 'https://discord.gg',
91-
template: 'https://discord.com/template',
91+
template: 'https://discord.new',
9292
},
9393
};
9494

@@ -535,6 +535,7 @@ exports.VerificationLevels = ['NONE', 'LOW', 'MEDIUM', 'HIGH', 'VERY_HIGH'];
535535
* * MAXIMUM_CHANNELS
536536
* * MAXIMUM_ATTACHMENTS
537537
* * MAXIMUM_INVITES
538+
* * GUILD_ALREADY_HAS_TEMPLATE
538539
* * UNAUTHORIZED
539540
* * ACCOUNT_VERIFICATION_REQUIRED
540541
* * REQUEST_ENTITY_TOO_LARGE
@@ -600,6 +601,7 @@ exports.APIErrors = {
600601
MAXIMUM_CHANNELS: 30013,
601602
MAXIMUM_ATTACHMENTS: 30015,
602603
MAXIMUM_INVITES: 30016,
604+
GUILD_ALREADY_HAS_TEMPLATE: 30031,
603605
UNAUTHORIZED: 40001,
604606
ACCOUNT_VERIFICATION_REQUIRED: 40002,
605607
REQUEST_ENTITY_TOO_LARGE: 40005,

typings/index.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,17 +859,20 @@ declare module 'discord.js' {
859859

860860
export class GuildTemplate extends Base {
861861
constructor(client: Client, data: object);
862+
public readonly createdTimestamp: number;
863+
public readonly updatedTimestamp: number;
862864
public readonly url: string;
863865
public code: string;
864866
public name: string;
865867
public description: string | null;
866868
public usageCount: number;
867-
public creatorID: string;
868869
public creator: User;
870+
public creatorID: Snowflake;
869871
public createdAt: Date;
870872
public updatedAt: Date;
871-
public guildID: string;
872-
public guild: Guild;
873+
public guild: Guild | null;
874+
public guildID: Snowflake;
875+
public serializedGuild: object;
873876
public unSynced: boolean | null;
874877
public createGuild(name: string, icon?: BufferResolvable | Base64Resolvable): Promise<Guild>;
875878
public delete(): Promise<GuildTemplate>;
@@ -2139,6 +2142,7 @@ declare module 'discord.js' {
21392142
MAXIMUM_CHANNELS: 30013;
21402143
MAXIMUM_ATTACHMENTS: 30015;
21412144
MAXIMUM_INVITES: 30016;
2145+
GUILD_ALREADY_HAS_TEMPLATE: 30031;
21422146
UNAUTHORIZED: 40001;
21432147
ACCOUNT_VERIFICATION_REQUIRED: 40002;
21442148
REQUEST_ENTITY_TOO_LARGE: 40005;

0 commit comments

Comments
 (0)