Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for guild templates #4907

Merged
merged 19 commits into from
Nov 21, 2020

Conversation

izexi
Copy link
Contributor

@izexi izexi commented Oct 15, 2020

Here's a snippet of how I tested these changes
import { once } from 'events';
import { Client, GuildTemplate } from 'discord.js';
import { TEST_GUILD_ID, TOKEN } from './constants';

const client = new Client();
let createdChannel;

client.login(TOKEN);

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

  const guild = client.guilds.cache.get(TEST_GUILD_ID);

  const template = await guild.createTemplate('bar');
  expect(template).toBeInstanceOf(GuildTemplate);

  await guild
    .fetchTemplates()
    .then((templates) =>
      expect(templates.size === 1 && templates.has(template.code)).toBe(true)
    );

  await template
    .edit({ description: 'baz' })
    .then((t) => expect(t.description).toBe('baz'));

  const createdChannelName = 'qux';
  createdChannel = await guild.channels.create(createdChannelName);
  await template
    .sync()
    .then((t) =>
      expect(
        t.serializedGuild.channels.some(
          ({ name }) => name === createdChannelName
        )
      ).toBe(true)
    );

  await template.delete();
  await expect(
    client.fetchGuildTemplate(template.code).catch(() => null)
  ).resolves.toBe(null);
});

afterAll(() => createdChannel.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.

@advaith1
Copy link
Contributor

docs PR has been merged

Copy link
Member

@SpaceEEC SpaceEEC left a comment

Choose a reason for hiding this comment

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

You could also add the error 30031 (A server can only have a single template.).
See: discord/discord-api-docs#2143 (comment)

src/structures/GuildTemplate.js Outdated Show resolved Hide resolved
src/util/Constants.js Outdated Show resolved Hide resolved
src/structures/GuildTemplate.js Outdated Show resolved Hide resolved
src/structures/GuildTemplate.js Outdated Show resolved Hide resolved
src/structures/GuildTemplate.js Outdated Show resolved Hide resolved
src/structures/GuildTemplate.js Show resolved Hide resolved
src/util/Constants.js Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
src/structures/GuildTemplate.js Show resolved Hide resolved
@izexi izexi changed the title feat: add 'GuildTemplate#edit/delete/sync()' & 'Guild#createTemplate/fetchTemplates()' feat: add support for guild templates 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.

None yet

7 participants