diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 972f7b889..0150d6483 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -74,6 +74,7 @@ class Guild { } } + /* eslint-disable complexity */ /** * Sets up the guild. * @param {*} data The raw data of the guild @@ -176,6 +177,13 @@ class Guild { */ this.joinedTimestamp = data.joined_at ? new Date(data.joined_at).getTime() : this.joinedTimestamp; + /** + * The value set for a guild's default message notifications + * @type {DefaultMessageNotifications|number} + */ + this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] || + data.default_message_notifications; + this.id = data.id; this.available = !data.unavailable; this.features = data.features || this.features || []; @@ -688,6 +696,11 @@ class Guild { if (typeof data.explicitContentFilter !== 'undefined') { _data.explicit_content_filter = Number(data.explicitContentFilter); } + if (typeof data.defaultMessageNotifications !== 'undefined') { + _data.default_message_notifications = typeof data.defaultMessageNotifications === 'string' ? + Constants.DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) : + Number(data.defaultMessageNotifications); + } return this.client.rest.methods.updateGuild(this, _data, reason); } @@ -701,6 +714,17 @@ class Guild { return this.edit({ explicitContentFilter }, reason); } + /* eslint-disable max-len */ + /** + * Edits the setting of the default message notifications of the guild. + * @param {DefaultMessageNotifications|number} defaultMessageNotifications The new setting for the default message notifications + * @param {string} [reason] Reason for changing the setting of the default message notifications + * @returns {Promise} + */ + setDefaultMessageNotifications(defaultMessageNotifications, reason) { + return this.edit({ defaultMessageNotifications }, reason); + } + /** * Edit the name of the guild. * @param {string} name The new name of the guild diff --git a/src/util/Constants.js b/src/util/Constants.js index 48001df86..58760ec3c 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -815,3 +815,14 @@ exports.APIErrors = { INVITE_ACCEPTED_TO_GUILD_NOT_CONTANING_BOT: 50036, REACTION_BLOCKED: 90001, }; + +/** + * The value set for a guild's default message notifications, e.g. `ALL`. Here are the available types: + * * ALL + * * MENTIONS + * @typedef {string} DefaultMessageNotifications + */ +exports.DefaultMessageNotifications = [ + 'ALL', + 'MENTIONS', +];