setCommunity mode
This commit is contained in:
parent
3a96fe0f5d
commit
590a778c4a
@ -1174,60 +1174,60 @@ class Guild extends AnonymousGuild {
|
|||||||
setRulesChannel(rulesChannel, reason) {
|
setRulesChannel(rulesChannel, reason) {
|
||||||
return this.edit({ rulesChannel }, reason);
|
return this.edit({ rulesChannel }, reason);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Change Guild Position (from * to Folder or Home)
|
* Change Guild Position (from * to Folder or Home)
|
||||||
* @param {number} position Guild Position
|
* @param {number} position Guild Position
|
||||||
* * **WARNING**: Type = `FOLDER`, newPosition is the guild's index in the Folder.
|
* * **WARNING**: Type = `FOLDER`, newPosition is the guild's index in the Folder.
|
||||||
* @param {String|Number} type Move to folder or home
|
* @param {String|Number} type Move to folder or home
|
||||||
* * `FOLDER`: 1
|
* * `FOLDER`: 1
|
||||||
* * `HOME`: 2
|
* * `HOME`: 2
|
||||||
* @param {String|Number|void|null} folderID If you want to move to folder
|
* @param {String|Number|void|null} folderID If you want to move to folder
|
||||||
* @returns {Promise<Guild>}
|
* @returns {Promise<Guild>}
|
||||||
* @example
|
* @example
|
||||||
* // Move guild to folderID 123456, index 1
|
* // Move guild to folderID 123456, index 1
|
||||||
* guild.setPosition(1, 'FOLDER', 123456)
|
* guild.setPosition(1, 'FOLDER', 123456)
|
||||||
* .then(guild => console.log(`Guild moved to folderID ${guild.folder.folderId}`));
|
* .then(guild => console.log(`Guild moved to folderID ${guild.folder.folderId}`));
|
||||||
*/
|
*/
|
||||||
async setPosition(position, type, folderID) {
|
async setPosition(position, type, folderID) {
|
||||||
if (type == 1 || `${type}`.toUpperCase() === 'FOLDER') {
|
if (type == 1 || `${type}`.toUpperCase() === 'FOLDER') {
|
||||||
folderID = folderID || this.folder.folderId;
|
folderID = folderID || this.folder.folderId;
|
||||||
if (!['number', 'string'].includes(typeof folderID))
|
if (!['number', 'string'].includes(typeof folderID))
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
'INVALID_TYPE',
|
'INVALID_TYPE',
|
||||||
'folderID',
|
'folderID',
|
||||||
'String | Number',
|
'String | Number',
|
||||||
);
|
);
|
||||||
// Get Data from Folder ID
|
// Get Data from Folder ID
|
||||||
const folder = await this.client.setting.rawSetting.guild_folders.find(
|
const folder = await this.client.setting.rawSetting.guild_folders.find(
|
||||||
(obj) => obj.id == folderID,
|
(obj) => obj.id == folderID,
|
||||||
);
|
);
|
||||||
if (!folder) throw new Error('FOLDER_NOT_FOUND');
|
if (!folder) throw new Error('FOLDER_NOT_FOUND');
|
||||||
if (folder.guild_ids.length - 1 < position || position < 0)
|
if (folder.guild_ids.length - 1 < position || position < 0)
|
||||||
throw new Error('FOLDER_POSITION_INVALID');
|
throw new Error('FOLDER_POSITION_INVALID');
|
||||||
if (position !== folder.guild_ids.indexOf(this.id)) {
|
if (position !== folder.guild_ids.indexOf(this.id)) {
|
||||||
await this.client.setting.guildChangePosition(
|
await this.client.setting.guildChangePosition(
|
||||||
this.id,
|
this.id,
|
||||||
position,
|
position,
|
||||||
1,
|
1,
|
||||||
folderID,
|
folderID,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (type == 2 || `${type}`.toUpperCase() === 'HOME') {
|
} else if (type == 2 || `${type}`.toUpperCase() === 'HOME') {
|
||||||
if (this.client.setting.guild_positions - 1 < position || position < 0)
|
if (this.client.setting.guild_positions - 1 < position || position < 0)
|
||||||
throw new Error('FOLDER_POSITION_INVALID');
|
throw new Error('FOLDER_POSITION_INVALID');
|
||||||
if (position !== this.position) {
|
if (position !== this.position) {
|
||||||
await this.client.setting.guildChangePosition(
|
await this.client.setting.guildChangePosition(
|
||||||
this.id,
|
this.id,
|
||||||
position,
|
position,
|
||||||
2,
|
2,
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError('INVALID_TYPE', 'type', '`Folder`| `Home`');
|
throw new TypeError('INVALID_TYPE', 'type', '`Folder`| `Home`');
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits the community updates channel of the guild.
|
* Edits the community updates channel of the guild.
|
||||||
@ -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
1
typings/index.d.ts
vendored
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user