mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
feat(Guild): add systemChannelFlags (#3559)
* Add systemChannelFlags bitfield to Guild * Implement @vladfrangu's suggestions * fix: apply suggestions, reverse order of flags, reword docs * docs: add SystemCHannelFlagsResolvable typedef Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
@@ -26,6 +26,7 @@ module.exports = {
|
||||
Snowflake: require('./util/Snowflake'),
|
||||
SnowflakeUtil: require('./util/Snowflake'),
|
||||
Structures: require('./util/Structures'),
|
||||
SystemChannelFlags: require('./util/SystemChannelFlags'),
|
||||
Util: Util,
|
||||
util: Util,
|
||||
version: require('../package.json').version,
|
||||
|
||||
@@ -10,6 +10,7 @@ const Collection = require('../util/Collection');
|
||||
const Util = require('../util/Util');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||
const GuildMemberStore = require('../stores/GuildMemberStore');
|
||||
const RoleStore = require('../stores/RoleStore');
|
||||
const GuildEmojiStore = require('../stores/GuildEmojiStore');
|
||||
@@ -275,6 +276,12 @@ class Guild extends Base {
|
||||
this.defaultMessageNotifications = DefaultMessageNotifications[data.default_message_notifications] ||
|
||||
data.default_message_notifications;
|
||||
|
||||
/**
|
||||
* The value set for the guild's system channel flags
|
||||
* @type {Readonly<SystemChannelFlags>}
|
||||
*/
|
||||
this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze();
|
||||
|
||||
/**
|
||||
* The maximum amount of members the guild can have
|
||||
* <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
|
||||
@@ -773,6 +780,7 @@ class Guild extends Base {
|
||||
* @property {Base64Resolvable} [splash] The splash screen of the guild
|
||||
* @property {Base64Resolvable} [banner] The banner of the guild
|
||||
* @property {DefaultMessageNotifications|number} [defaultMessageNotifications] The default message notifications
|
||||
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -813,6 +821,9 @@ class Guild extends Base {
|
||||
DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
|
||||
Number(data.defaultMessageNotifications);
|
||||
}
|
||||
if (typeof data.systemChannelFlags !== 'undefined') {
|
||||
_data.systemChannelFlags = SystemChannelFlags.resolve(data.systemChannelFlags);
|
||||
}
|
||||
return this.client.api.guilds(this.id).patch({ data: _data, reason })
|
||||
.then(newData => this.client.actions.GuildUpdate.handle(newData).updated);
|
||||
}
|
||||
@@ -839,6 +850,16 @@ class Guild extends Base {
|
||||
}
|
||||
/* eslint-enable max-len */
|
||||
|
||||
/**
|
||||
* Edits the flags of the default message notifications of the guild.
|
||||
* @param {SystemChannelFlagsResolvable} systemChannelFlags The new flags for the default message notifications
|
||||
* @param {string} [reason] Reason for changing the flags of the default message notifications
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setSystemChannelFlags(systemChannelFlags, reason) {
|
||||
return this.edit({ systemChannelFlags }, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the name of the guild.
|
||||
* @param {string} name The new name of the guild
|
||||
|
||||
33
src/util/SystemChannelFlags.js
Normal file
33
src/util/SystemChannelFlags.js
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const BitField = require('./BitField');
|
||||
|
||||
/**
|
||||
* Data structure that makes it easy to interact with a {@link Guild#systemChannelFlags} bitfield.
|
||||
* <info>Note that all event message types are enabled by default,
|
||||
* and by setting their corresponding flags you are disabling them</info>
|
||||
* @extends {BitField}
|
||||
*/
|
||||
class SystemChannelFlags extends BitField {
|
||||
/**
|
||||
* Data that can be resolved to give a sytem channel flag bitfield. This can be:
|
||||
* * A string (see {@link SystemChannelFlags.FLAGS})
|
||||
* * A sytem channel flag
|
||||
* * An instance of SystemChannelFlags
|
||||
* * An Array of SystemChannelFlagsResolvable
|
||||
* @typedef {string|number|SystemChannelFlags|SystemChannelFlagsResolvable[]} SystemChannelFlagsResolvable
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Numeric system channel flags. All available properties:
|
||||
* * `WELCOME_MESSAGE_DISABLED`
|
||||
* * `BOOST_MESSAGE_DISABLED`
|
||||
* @type {Object}
|
||||
*/
|
||||
SystemChannelFlags.FLAGS = {
|
||||
WELCOME_MESSAGE_DISABLED: 1 << 0,
|
||||
BOOST_MESSAGE_DISABLED: 1 << 1,
|
||||
};
|
||||
|
||||
module.exports = SystemChannelFlags;
|
||||
13
typings/index.d.ts
vendored
13
typings/index.d.ts
vendored
@@ -714,6 +714,7 @@ declare module 'discord.js' {
|
||||
public shardID: number;
|
||||
public splash: string | null;
|
||||
public readonly systemChannel: TextChannel | null;
|
||||
public systemChannelFlags: Readonly<SystemChannelFlags>;
|
||||
public systemChannelID: Snowflake | null;
|
||||
public vanityURLCode: string | null;
|
||||
public verificationLevel: number;
|
||||
@@ -755,6 +756,7 @@ declare module 'discord.js' {
|
||||
public setRolePositions(rolePositions: RolePosition[]): Promise<Guild>;
|
||||
public setSplash(splash: Base64Resolvable | null, reason?: string): Promise<Guild>;
|
||||
public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
|
||||
public setVerificationLevel(verificationLevel: number, reason?: string): Promise<Guild>;
|
||||
public splashURL(options?: AvatarOptions): string | null;
|
||||
public toJSON(): object;
|
||||
@@ -1368,6 +1370,11 @@ declare module 'discord.js' {
|
||||
static extend<T extends Function>(structure: string, extender: (baseClass: typeof Function) => T): T;
|
||||
}
|
||||
|
||||
export class SystemChannelFlags extends BitField<SystemChannelFlagsString> {
|
||||
public static FLAGS: Record<SystemChannelFlagsString, number>;
|
||||
public static resolve(bit?: BitFieldResolvable<SystemChannelFlagsString>): number;
|
||||
}
|
||||
|
||||
export class TextChannel extends TextBasedChannel(GuildChannel) {
|
||||
constructor(guild: Guild, data?: object);
|
||||
public messages: MessageStore;
|
||||
@@ -2285,6 +2292,7 @@ declare module 'discord.js' {
|
||||
defaultMessageNotifications?: DefaultMessageNotifications | number;
|
||||
afkChannel?: ChannelResolvable;
|
||||
systemChannel?: ChannelResolvable;
|
||||
systemChannelFlags?: SystemChannelFlags;
|
||||
afkTimeout?: number;
|
||||
icon?: Base64Resolvable;
|
||||
owner?: GuildMemberResolvable;
|
||||
@@ -2613,6 +2621,11 @@ declare module 'discord.js' {
|
||||
|
||||
type StringResolvable = string | string[] | any;
|
||||
|
||||
type SystemChannelFlagsString = 'WELCOME_MESSAGE_DISABLED'
|
||||
| 'BOOST_MESSAGE_DISABLED';
|
||||
|
||||
type SystemChannelFlagsResolvable = BitFieldResolvable<SystemChannelFlagsString>;
|
||||
|
||||
type TargetUser = number;
|
||||
|
||||
type UserResolvable = User | Snowflake | Message | GuildMember;
|
||||
|
||||
Reference in New Issue
Block a user