Skip to content

Commit

Permalink
Support welcome screen endpoints (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 authored Apr 18, 2021
1 parent 2a840a0 commit fba1f7c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ declare namespace Eris {
description: string;
welcomeChannels: WelcomeChannel[];
}
interface WelcomeScreenOptions extends WelcomeScreen {
enabled: boolean;
}
interface Widget {
channel_id?: string;
enabled: boolean;
Expand Down Expand Up @@ -1553,7 +1556,8 @@ declare namespace Eris {
editGuildTemplate(guildID: string, code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
editGuildVanity(guildID: string, code: string): Promise<GuildVanity>;
editGuildVoiceState(guildID: string, options: VoiceStateOptions, userID?: string): Promise<void>;
editGuildWidget(guildID: string, options: Widget): Promise<Widget>
editGuildWelcomeScreen(guildID: string, options: WelcomeScreenOptions): Promise<WelcomeScreen>;
editGuildWidget(guildID: string, options: Widget): Promise<Widget>;
editMessage(channelID: string, messageID: string, content: MessageContent): Promise<Message>;
editNickname(guildID: string, nick: string, reason?: string): Promise<void>;
editRole(guildID: string, roleID: string, options: RoleOptions, reason?: string): Promise<Role>; // TODO not all options are available?
Expand Down Expand Up @@ -1608,6 +1612,7 @@ declare namespace Eris {
getGuildTemplates(guildID: string): Promise<GuildTemplate[]>;
getGuildVanity(guildID: string): Promise<GuildVanity>;
getGuildWebhooks(guildID: string): Promise<Webhook[]>;
getGuildWelcomeScreen(guildID: string): Promise<WelcomeScreen>;
getGuildWidget(guildID: string): Promise<Widget>;
getInvite(inviteID: string, withCounts?: false): Promise<Invite<"withoutCount">>;
getInvite(inviteID: string, withCounts: true): Promise<Invite<"withCount">>;
Expand Down Expand Up @@ -1933,8 +1938,9 @@ declare namespace Eris {
editRole(roleID: string, options: RoleOptions): Promise<Role>;
editTemplate(code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
editVanity(code: string): Promise<GuildVanity>;
editVoiceState(options: VoiceStateOptions, userID?: string): Promise<void>;
editWelcomeScreen(options: WelcomeScreenOptions): Promise<WelcomeScreen>;
editWidget(options: Widget): Promise<Widget>;
editVoiceState(options: VoiceStateOptions, userID?: string): Promise<void>;
fetchAllMembers(timeout?: number): Promise<number>;
fetchMembers(options?: FetchMembersOptions): Promise<Member[]>;
getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
Expand All @@ -1956,6 +1962,7 @@ declare namespace Eris {
getVanity(): Promise<GuildVanity>;
getVoiceRegions(): Promise<VoiceRegion[]>;
getWebhooks(): Promise<Webhook[]>;
getWelcomeScreen(): Promise<WelcomeScreen>;
getWidget(): Promise<Widget>;
kickMember(userID: string, reason?: string): Promise<void>;
leave(): Promise<void>;
Expand Down
37 changes: 37 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,34 @@ class Client extends EventEmitter {
});
}

/**
* Edit a guild welcome screen
* @arg {String} guildID The ID of the guild
* @arg {Object} [options] The properties to edit
* @arg {String?} [options.description] The description in the welcome screen
* @arg {Boolean} [options.enabled] Whether the welcome screen is enabled
* @arg {Array<Object>} [options.welcomeChannels] The list of channels in the welcome screen as an array
* @arg {String} options.welcomeChannels[].channelID The channel ID of the welcome channel
* @arg {String} options.welcomeChannels[].description The description of the welcome channel
* @arg {String?} options.welcomeChannels[].emojiID The emoji ID of the welcome channel
* @arg {String?} options.welcomeChannels[].emojiName The emoji name of the welcome channel
* @returns {Promise<Object>}
*/
editGuildWelcomeScreen(guildID, options) {
return this.requestHandler.request("PATCH", Endpoints.GUILD_WELCOME_SCREEN(guildID), true, {
description: options.description,
enabled: options.enabled,
welcome_channels: options.welcomeChannels.map((c) => {
return {
channel_id: c.channelID,
description: c.description,
emoji_id: c.emojiID,
emoji_name: c.emojiName
};
})
});
}

/**
* Modify a guild's widget
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -1734,6 +1762,15 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.GUILD_WEBHOOKS(guildID), true);
}

/**
* Get the welcome screen of a Community guild, shown to new members
* @param {String} guildID The ID of the guild to get the welcome screen for
* @returns {Promise<Object>}
*/
getGuildWelcomeScreen(guildID) {
return this.requestHandler.request("GET", Endpoints.GUILD_WELCOME_SCREEN(guildID), true);
}

/**
* Get a guild's widget object
* @arg {String} guildID The ID of the guild
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports.GUILD_TEMPLATES = (guildID)
module.exports.GUILD_TEMPLATE_GUILD = (guildID, code) => `/guilds/${guildID}/templates/${code}`;
module.exports.GUILD_VOICE_REGIONS = (guildID) => `/guilds/${guildID}/regions`;
module.exports.GUILD_WEBHOOKS = (guildID) => `/guilds/${guildID}/webhooks`;
module.exports.GUILD_WELCOME_SCREEN = (guildID) => `/guilds/${guildID}/welcome-screen`;
module.exports.GUILD_WIDGET = (guildID) => `/guilds/${guildID}/widget`;
module.exports.GUILD_VOICE_STATE = (guildID, user) => `/guilds/${guildID}/voice-states/${user}`;
module.exports.GUILDS = "/guilds";
Expand Down
25 changes: 25 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,23 @@ class Guild extends Base {
return this._client.editGuildVoiceState.call(this._client, this.id, options, userID);
}

/**
* Edit the guild welcome screen
* @arg {String} guildID The ID of the guild
* @arg {Object} [options] The properties to edit
* @arg {String?} [options.description] The description in the welcome screen
* @arg {Boolean} [options.enabled] Whether the welcome screen is enabled
* @arg {Array<Object>} [options.welcomeChannels] The list of channels in the welcome screen as an array
* @arg {String} options.welcomeChannels[].channelID The channel ID of the welcome channel
* @arg {String} options.welcomeChannels[].description The description of the welcome channel
* @arg {String?} options.welcomeChannels[].emojiID The emoji ID of the welcome channel
* @arg {String?} options.welcomeChannels[].emojiName The emoji name of the welcome channel
* @returns {Promise<Object>}
*/
editWelcomeScreen(options) {
return this._client.editGuildWelcomeScreen.call(this._client, this.id, options);
}

/**
* Modify a guild's widget
* @arg {Object} options The widget object to modify (https://discord.com/developers/docs/resources/guild#modify-guild-widget)
Expand Down Expand Up @@ -820,6 +837,14 @@ class Guild extends Base {
return this._client.getGuildWebhooks.call(this._client, this.id);
}

/**
* Get the welcome screen of the Community guild, shown to new members
* @returns {Promise<Object>}
*/
getWelcomeScreen() {
return this._client.getGuildWelcomeScreen.call(this._client, this.id);
}

/**
* Get a guild's widget object
* @returns {Promise<Object>} A guild widget object
Expand Down

0 comments on commit fba1f7c

Please sign in to comment.