mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat(Guild): add support for system channel flags (#3793)
This commit is contained in:
@@ -17,6 +17,7 @@ module.exports = {
|
|||||||
Permissions: require('./util/Permissions'),
|
Permissions: require('./util/Permissions'),
|
||||||
Snowflake: require('./util/Snowflake'),
|
Snowflake: require('./util/Snowflake'),
|
||||||
SnowflakeUtil: require('./util/Snowflake'),
|
SnowflakeUtil: require('./util/Snowflake'),
|
||||||
|
SystemChannelFlags: require('./util/SystemChannelFlags'),
|
||||||
Util: Util,
|
Util: Util,
|
||||||
util: Util,
|
util: Util,
|
||||||
version: require('../package').version,
|
version: require('../package').version,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const Constants = require('../util/Constants');
|
|||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
const Snowflake = require('../util/Snowflake');
|
const Snowflake = require('../util/Snowflake');
|
||||||
|
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a guild (or a server) on Discord.
|
* Represents a guild (or a server) on Discord.
|
||||||
@@ -185,6 +186,12 @@ class Guild {
|
|||||||
this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] ||
|
this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] ||
|
||||||
data.default_message_notifications;
|
data.default_message_notifications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value for the guild's system channel flags
|
||||||
|
* @type {Readonly<SystemChannelFlags>}
|
||||||
|
*/
|
||||||
|
this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of premium tier:
|
* The type of premium tier:
|
||||||
* * 0: NONE
|
* * 0: NONE
|
||||||
@@ -891,6 +898,7 @@ class Guild {
|
|||||||
* @property {Base64Resolvable} [banner] The banner of the guild
|
* @property {Base64Resolvable} [banner] The banner of the guild
|
||||||
* @property {GuildMemberResolvable} [owner] The owner of the guild
|
* @property {GuildMemberResolvable} [owner] The owner of the guild
|
||||||
* @property {Base64Resolvable} [splash] The splash screen of the guild
|
* @property {Base64Resolvable} [splash] The splash screen of the guild
|
||||||
|
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -931,6 +939,9 @@ class Guild {
|
|||||||
Constants.DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
|
Constants.DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
|
||||||
Number(data.defaultMessageNotifications);
|
Number(data.defaultMessageNotifications);
|
||||||
}
|
}
|
||||||
|
if (typeof data.systemChannelFlags !== 'undefined') {
|
||||||
|
_data.system_channel_flags = SystemChannelFlags.resolve(data.systemChannelFlags);
|
||||||
|
}
|
||||||
return this.client.rest.methods.updateGuild(this, _data, reason);
|
return this.client.rest.methods.updateGuild(this, _data, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,6 +976,16 @@ class Guild {
|
|||||||
return this.edit({ defaultMessageNotifications }, reason);
|
return this.edit({ defaultMessageNotifications }, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit the name of the guild.
|
* Edit the name of the guild.
|
||||||
* @param {string} name The new name of the guild
|
* @param {string} name The new name of the guild
|
||||||
|
|||||||
31
src/util/SystemChannelFlags.js
Normal file
31
src/util/SystemChannelFlags.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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;
|
||||||
12
typings/index.d.ts
vendored
12
typings/index.d.ts
vendored
@@ -556,6 +556,7 @@ declare module 'discord.js' {
|
|||||||
public readonly splashURL: string;
|
public readonly splashURL: string;
|
||||||
public readonly suppressEveryone: boolean;
|
public readonly suppressEveryone: boolean;
|
||||||
public readonly systemChannel: GuildChannel;
|
public readonly systemChannel: GuildChannel;
|
||||||
|
public systemChannelFlags: Readonly<SystemChannelFlags>;
|
||||||
public systemChannelID: Snowflake;
|
public systemChannelID: Snowflake;
|
||||||
public vanityURLCode: string;
|
public vanityURLCode: string;
|
||||||
public readonly verified: boolean;
|
public readonly verified: boolean;
|
||||||
@@ -612,6 +613,7 @@ declare module 'discord.js' {
|
|||||||
public setRolePositions(rolePositions: RolePosition[]): Promise<Guild>;
|
public setRolePositions(rolePositions: RolePosition[]): Promise<Guild>;
|
||||||
public setSplash(splash: Base64Resolvable, reason?: string): Promise<Guild>;
|
public setSplash(splash: Base64Resolvable, reason?: string): Promise<Guild>;
|
||||||
public setSystemChannel(systemChannel: ChannelResolvable, reason?: string): Promise<Guild>;
|
public setSystemChannel(systemChannel: ChannelResolvable, reason?: string): Promise<Guild>;
|
||||||
|
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
|
||||||
public setVerificationLevel(verificationLevel: number, reason?: string): Promise<Guild>;
|
public setVerificationLevel(verificationLevel: number, reason?: string): Promise<Guild>;
|
||||||
public sync(): void;
|
public sync(): void;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
@@ -1296,6 +1298,11 @@ declare module 'discord.js' {
|
|||||||
public setBitrate(bitrate: number | 'auto'): void;
|
public setBitrate(bitrate: number | 'auto'): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SystemChannelFlags extends BitField<SystemChannelFlagsString> {
|
||||||
|
public static FLAGS: Record<SystemChannelFlagsString, number>;
|
||||||
|
public static resolve(bit?: BitFieldResolvable<SystemChannelFlagsString>): number;
|
||||||
|
}
|
||||||
|
|
||||||
export class Team {
|
export class Team {
|
||||||
constructor(client: Client, data: object);
|
constructor(client: Client, data: object);
|
||||||
public readonly client: Client;
|
public readonly client: Client;
|
||||||
@@ -1967,6 +1974,7 @@ declare module 'discord.js' {
|
|||||||
explicitContentFilter?: number;
|
explicitContentFilter?: number;
|
||||||
afkChannel?: ChannelResolvable;
|
afkChannel?: ChannelResolvable;
|
||||||
systemChannel?: ChannelResolvable;
|
systemChannel?: ChannelResolvable;
|
||||||
|
systemChannelFlags?: SystemChannelFlagsResolvable;
|
||||||
afkTimeout?: number;
|
afkTimeout?: number;
|
||||||
banner?: Base64Resolvable;
|
banner?: Base64Resolvable;
|
||||||
icon?: Base64Resolvable;
|
icon?: Base64Resolvable;
|
||||||
@@ -2305,6 +2313,10 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
type StringResolvable = string | string[] | any;
|
type StringResolvable = string | string[] | any;
|
||||||
|
|
||||||
|
type SystemChannelFlagsString = 'WELCOME_MESSAGE_DISABLED' | 'BOOST_MESSAGE_DISABLED';
|
||||||
|
|
||||||
|
type SystemChannelFlagsResolvable = BitFieldResolvable<SystemChannelFlagsString>;
|
||||||
|
|
||||||
type UserResolvable = User | Snowflake | Message | Guild | GuildMember;
|
type UserResolvable = User | Snowflake | Message | Guild | GuildMember;
|
||||||
|
|
||||||
type VoiceStatus = number;
|
type VoiceStatus = number;
|
||||||
|
|||||||
Reference in New Issue
Block a user