Skip to content

Conversation

@izexi
Copy link
Contributor

@izexi izexi commented Oct 15, 2020

  • Ref: Document Server Templates discord/discord-api-docs#1712
  • Adds DataResolver#resolveGuildTemplateCode() to resolve template URLs
  • Along with DataResolver#resolveCode() to reuse code for the above and the resolveInviteCode method
  • Creates a GuildTemplate structure with a createGuild method to add support for the POST /guilds/templates/:template_code endpoint
  • Adds Client#fetchGuildTemplate() to support for the GET /guilds/templates/:template_code endpoint
  • Resolves Idea: Server templates #4651
Here's a snippet of how I tested these changes
import { once } from 'events';
import { Client, DataResolver, GuildTemplate } from 'discord.js';
import { TEST_TEMPLATE_CODE, TOKEN } from './constants';

const client = new Client();
let createdGuild;

client.login(TOKEN);

test('DataResolver#resolveGuildTemplateCode()', () => {
  expect(
    DataResolver.resolveGuildTemplateCode(
      'https://discord.com/template/FKvmczH2HyUf'
    )
  ).toBe('FKvmczH2HyUf');

  expect(
    DataResolver.resolveGuildTemplateCode('https://discord.new/FKvmczH2HyUf')
  ).toBe('FKvmczH2HyUf');

  expect(
    DataResolver.resolveGuildTemplateCode('https://discord.invalid/code')
  ).toBe('https://discord.invalid/code');
});


test('Client#fetchGuildTemplate() & GuildTempalte#createGuild()', async () => {
  await once(client, 'ready');

  const template = await client.fetchGuildTemplate(TEST_TEMPLATE_CODE);
  expect(template).toBeInstanceOf(GuildTemplate);

  const createdGuildName = 'foo';
  createdGuild = await template.createGuild(createdGuildName);
  expect(createdGuild.name).toBe(createdGuildName);
});

afterAll(() => createdGuild.delete());

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@izexi izexi mentioned this pull request Oct 15, 2020
5 tasks
@izexi izexi force-pushed the merged-guild-template branch from bc176b5 to 183080e Compare October 16, 2020 11:36
Copy link
Contributor

@NotSugden NotSugden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json error code 10057 unknown guild template could be added to this PR https://discord.com/developers/docs/topics/opcodes-and-status-codes#json

@izexi
Copy link
Contributor Author

izexi commented Nov 20, 2020

Closing this PR since its being superseded by #4907 and the referenced API docs PR on there has been merged

@izexi izexi closed this Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idea: Server templates

2 participants