mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(WelcomeScreen): welcome screens (#5490)
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com> Co-authored-by: izexi <43889168+izexi@users.noreply.github.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const BaseGuild = require('./BaseGuild');
|
||||
const AnonymousGuild = require('./AnonymousGuild');
|
||||
const GuildAuditLogs = require('./GuildAuditLogs');
|
||||
const GuildPreview = require('./GuildPreview');
|
||||
const GuildTemplate = require('./GuildTemplate');
|
||||
const Integration = require('./Integration');
|
||||
const Invite = require('./Invite');
|
||||
const Webhook = require('./Webhook');
|
||||
const WelcomeScreen = require('./WelcomeScreen');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
const GuildApplicationCommandManager = require('../managers/GuildApplicationCommandManager');
|
||||
const GuildBanManager = require('../managers/GuildBanManager');
|
||||
@@ -24,7 +25,6 @@ const {
|
||||
PartialTypes,
|
||||
VerificationLevels,
|
||||
ExplicitContentFilterLevels,
|
||||
NSFWLevels,
|
||||
Status,
|
||||
MFALevels,
|
||||
PremiumTiers,
|
||||
@@ -37,9 +37,9 @@ const Util = require('../util/Util');
|
||||
* Represents a guild (or a server) on Discord.
|
||||
* <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
|
||||
* check this with `guild.available`.</info>
|
||||
* @extends {BaseGuild}
|
||||
* @extends {AnonymousGuild}
|
||||
*/
|
||||
class Guild extends BaseGuild {
|
||||
class Guild extends AnonymousGuild {
|
||||
constructor(client, data) {
|
||||
super(client, data);
|
||||
|
||||
@@ -131,18 +131,12 @@ class Guild extends BaseGuild {
|
||||
* @private
|
||||
*/
|
||||
_patch(data) {
|
||||
super._patch(data);
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.icon = data.icon;
|
||||
this.features = data.features;
|
||||
this.available = !data.unavailable;
|
||||
|
||||
/**
|
||||
* The hash of the guild invite splash image
|
||||
* @type {?string}
|
||||
*/
|
||||
this.splash = data.splash;
|
||||
|
||||
/**
|
||||
* The hash of the guild discovery splash image
|
||||
* @type {?string}
|
||||
@@ -155,14 +149,6 @@ class Guild extends BaseGuild {
|
||||
*/
|
||||
this.memberCount = data.member_count || this.memberCount;
|
||||
|
||||
if ('nsfw_level' in data) {
|
||||
/**
|
||||
* The NSFW level of this guild
|
||||
* @type {NSFWLevel}
|
||||
*/
|
||||
this.nsfwLevel = NSFWLevels[data.nsfw_level];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the guild is "large" (has more than large_threshold members, 50 by default)
|
||||
* @type {boolean}
|
||||
@@ -247,12 +233,6 @@ class Guild extends BaseGuild {
|
||||
this.widgetChannelID = data.widget_channel_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* The verification level of the guild
|
||||
* @type {VerificationLevel}
|
||||
*/
|
||||
this.verificationLevel = VerificationLevels[data.verification_level];
|
||||
|
||||
/**
|
||||
* The explicit content filter level of the guild
|
||||
* @type {ExplicitContentFilterLevel}
|
||||
@@ -326,12 +306,6 @@ class Guild extends BaseGuild {
|
||||
this.approximatePresenceCount = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The vanity invite code of the guild, if any
|
||||
* @type {?string}
|
||||
*/
|
||||
this.vanityURLCode = data.vanity_url_code;
|
||||
|
||||
/**
|
||||
* The use count of the vanity URL code of the guild, if any
|
||||
* <info>You will need to fetch this parameter using {@link Guild#fetchVanityData} if you want to receive it</info>
|
||||
@@ -339,18 +313,6 @@ class Guild extends BaseGuild {
|
||||
*/
|
||||
this.vanityURLUses = null;
|
||||
|
||||
/**
|
||||
* The description of the guild, if any
|
||||
* @type {?string}
|
||||
*/
|
||||
this.description = data.description;
|
||||
|
||||
/**
|
||||
* The hash of the guild banner
|
||||
* @type {?string}
|
||||
*/
|
||||
this.banner = data.banner;
|
||||
|
||||
/**
|
||||
* The ID of the rules channel for the guild
|
||||
* @type {?Snowflake}
|
||||
@@ -576,6 +538,15 @@ class Guild extends BaseGuild {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the welcome screen for this guild.
|
||||
* @returns {Promise<WelcomeScreen>}
|
||||
*/
|
||||
async fetchWelcomeScreen() {
|
||||
const data = await this.client.api.guilds(this.id, 'welcome-screen').get();
|
||||
return new WelcomeScreen(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The data for creating an integration.
|
||||
* @typedef {Object} IntegrationData
|
||||
@@ -900,6 +871,60 @@ class Guild extends BaseGuild {
|
||||
.then(newData => this.client.actions.GuildUpdate.handle(newData).updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Welcome channel data
|
||||
* @typedef {Object} WelcomeChannelData
|
||||
* @property {string} description The description to show for this welcome channel
|
||||
* @property {GuildTextChannelResolvable} channel The channel to link for this welcome channel
|
||||
* @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Welcome screen edit data
|
||||
* @typedef {Object} WelcomeScreenEditData
|
||||
* @property {boolean} [enabled] Whether the welcome screen is enabled
|
||||
* @property {string} [description] The description for the welcome screen
|
||||
* @property {WelcomeChannelData[]} [welcomeChannels] The welcome channel data for the welcome screen
|
||||
*/
|
||||
|
||||
/**
|
||||
* Updates the guild's welcome screen
|
||||
* @param {WelcomeScreenEditData} data Data to edit the welcome screen with
|
||||
* @returns {Promise<WelcomeScreen>}
|
||||
* @example
|
||||
* guild.editWelcomeScreen({
|
||||
* description: 'Hello World',
|
||||
* enabled: true,
|
||||
* welcomeChannels: [
|
||||
* {
|
||||
* description: 'foobar',
|
||||
* channel: '222197033908436994',
|
||||
* }
|
||||
* ],
|
||||
* })
|
||||
*/
|
||||
async editWelcomeScreen(data) {
|
||||
const { enabled, description, welcomeChannels } = data;
|
||||
const welcome_channels = welcomeChannels?.map(welcomeChannelData => {
|
||||
const emoji = this.emojis.resolve(welcomeChannelData.emoji);
|
||||
return {
|
||||
emoji_id: emoji?.id ?? null,
|
||||
emoji_name: emoji?.name ?? welcomeChannelData.emoji,
|
||||
channel_id: this.channels.resolveID(welcomeChannelData.channel),
|
||||
description: welcomeChannelData.description,
|
||||
};
|
||||
});
|
||||
|
||||
const patchData = await this.client.api.guilds(this.id, 'welcome-screen').patch({
|
||||
data: {
|
||||
welcome_channels,
|
||||
description,
|
||||
enabled,
|
||||
},
|
||||
});
|
||||
return new WelcomeScreen(this, patchData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the level of the explicit content filter.
|
||||
* @param {ExplicitContentFilterLevel|number} explicitContentFilter The new level of the explicit content filter
|
||||
|
||||
Reference in New Issue
Block a user