mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-21 10:54:44 +12:00
fix(DataResolver): fix circular dependency error with GuildTemplate (#5622)
This commit is contained in:
parent
14c6802438
commit
b376f31af9
4 changed files with 41 additions and 2 deletions
|
@ -5,7 +5,6 @@ const path = require('path');
|
|||
const stream = require('stream');
|
||||
const fetch = require('node-fetch');
|
||||
const { Error: DiscordError, TypeError } = require('../errors');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
|
||||
/**
|
||||
|
@ -56,6 +55,7 @@ class DataResolver {
|
|||
* @returns {string}
|
||||
*/
|
||||
static resolveGuildTemplateCode(data) {
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
return this.resolveCode(data, GuildTemplate.GUILD_TEMPLATES_PATTERN);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
/* eslint-disable max-len, no-undef */
|
||||
/* eslint-env jest */
|
||||
/* eslint-disable max-len */
|
||||
|
||||
const Util = require('../src/util/Util');
|
||||
const testString = "`_Behold!_`\n||___~~***```js\n`use strict`;\nrequire('discord.js');```***~~___||";
|
||||
|
|
11
test/resolveGuildTemplateCode.test.js
Normal file
11
test/resolveGuildTemplateCode.test.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
/* eslint-env jest */
|
||||
|
||||
const { DataResolver } = require('../src');
|
||||
|
||||
describe('resolveGuildTemplateCode', () => {
|
||||
test('basic', () => {
|
||||
expect(DataResolver.resolveGuildTemplateCode('https://discord.new/abc')).toBe('abc');
|
||||
});
|
||||
});
|
27
test/templateCreateGuild.js
Normal file
27
test/templateCreateGuild.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const { token } = require('./auth');
|
||||
const { Client } = require('../src');
|
||||
|
||||
const client = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] });
|
||||
client
|
||||
.on('ready', () => console.log('ready'))
|
||||
.on('message', async message => {
|
||||
try {
|
||||
const templates = await message.guild.fetchTemplates();
|
||||
if (!templates.size) {
|
||||
console.log('no templates');
|
||||
} else {
|
||||
const guild = await templates.first().createGuild('guild name');
|
||||
console.log(`created guild with ID ${guild.id}`);
|
||||
await guild.delete();
|
||||
console.log('deleted guild');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
client.destroy();
|
||||
}
|
||||
})
|
||||
.login(token)
|
||||
.catch(console.error);
|
Loading…
Reference in a new issue