setCommunity mode

This commit is contained in:
March 7th 2022-04-08 12:02:46 +07:00
parent 3a96fe0f5d
commit 590a778c4a
2 changed files with 95 additions and 54 deletions

View File

@ -1412,6 +1412,46 @@ class Guild extends AnonymousGuild {
); );
} }
/**
* Set Community Feature
* @param {Boolean} stats True / False to enable / disable Community Feature
* @param {TextChannelResolvable} publicUpdatesChannel
* @param {TextChannelResolvable} rulesChannel
* @param {String} reason
*/
async setCommunity(stats = true, publicUpdatesChannel = '1', rulesChannel = '1', reason) {
if (stats) {
// Check everyone role
const everyoneRole = this.roles.everyone;
if (everyoneRole.mentionable) {
await everyoneRole.setMentionable(false, reason);
}
// Setting
this.edit(
{
defaultMessageNotifications: 'ONLY_MENTIONS',
explicitContentFilter: 'ALL_MEMBERS',
features: [...this.features, 'COMMUNITY'],
publicUpdatesChannel,
rulesChannel,
verificationLevel:
VerificationLevels[this.verificationLevel] < 1
? 'LOW'
: this.verificationLevel, // Email
},
reason,
);
} else {
this.edit({
publicUpdatesChannel: null,
rulesChannel: null,
features: this.features.filter(f => f !== 'COMMUNITY'),
preferredLocale: this.preferredLocale,
description: this.description,
}, reason);
}
}
toJSON() { toJSON() {
const json = super.toJSON({ const json = super.toJSON({
available: false, available: false,

1
typings/index.d.ts vendored
View File

@ -1012,6 +1012,7 @@ export class Guild extends AnonymousGuild {
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>; public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
public setVerificationLevel(verificationLevel: VerificationLevel | number, reason?: string): Promise<Guild>; public setVerificationLevel(verificationLevel: VerificationLevel | number, reason?: string): Promise<Guild>;
public setPremiumProgressBarEnabled(enabled?: boolean, reason?: string): Promise<Guild>; public setPremiumProgressBarEnabled(enabled?: boolean, reason?: string): Promise<Guild>;
public setCommunity(stats: boolean, publicUpdatesChannel: TextChannelResolvable, rulesChannel: TextChannelResolvable, reason?: string): Promise<Guild>;
public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise<Guild>; public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise<Guild>;
public toJSON(): unknown; public toJSON(): unknown;
} }