mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
feat(Guild): safety alerts channel and mention raid protection (#8959)
* feat(Guild): add safety alerts channel and mention raid protection * docs: add missing tag * fix: keep other properties in triggerMetadata * docs(Guild): update example usage --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -59,6 +59,7 @@ class AutoModerationRuleManager extends CachedManager {
|
|||||||
* @property {string[]} [allowList] The substrings that will be exempt from triggering
|
* @property {string[]} [allowList] The substrings that will be exempt from triggering
|
||||||
* {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.KeywordPreset}
|
* {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.KeywordPreset}
|
||||||
* @property {?number} [mentionTotalLimit] The total number of role & user mentions allowed per message
|
* @property {?number} [mentionTotalLimit] The total number of role & user mentions allowed per message
|
||||||
|
* @property {boolean} [mentionRaidProtectionEnabled] Whether to automatically detect mention raids
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,6 +126,7 @@ class AutoModerationRuleManager extends CachedManager {
|
|||||||
presets: triggerMetadata.presets,
|
presets: triggerMetadata.presets,
|
||||||
allow_list: triggerMetadata.allowList,
|
allow_list: triggerMetadata.allowList,
|
||||||
mention_total_limit: triggerMetadata.mentionTotalLimit,
|
mention_total_limit: triggerMetadata.mentionTotalLimit,
|
||||||
|
mention_raid_protection_enabled: triggerMetadata.mentionRaidProtectionEnabled,
|
||||||
},
|
},
|
||||||
actions: actions.map(action => ({
|
actions: actions.map(action => ({
|
||||||
type: action.type,
|
type: action.type,
|
||||||
@@ -182,6 +184,7 @@ class AutoModerationRuleManager extends CachedManager {
|
|||||||
presets: triggerMetadata.presets,
|
presets: triggerMetadata.presets,
|
||||||
allow_list: triggerMetadata.allowList,
|
allow_list: triggerMetadata.allowList,
|
||||||
mention_total_limit: triggerMetadata.mentionTotalLimit,
|
mention_total_limit: triggerMetadata.mentionTotalLimit,
|
||||||
|
mention_raid_protection_enabled: triggerMetadata.mentionRaidProtectionEnabled,
|
||||||
},
|
},
|
||||||
actions: actions?.map(action => ({
|
actions: actions?.map(action => ({
|
||||||
type: action.type,
|
type: action.type,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class AutoModerationRule extends Base {
|
|||||||
* @property {string[]} allowList The substrings that will be exempt from triggering
|
* @property {string[]} allowList The substrings that will be exempt from triggering
|
||||||
* {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.KeywordPreset}
|
* {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.KeywordPreset}
|
||||||
* @property {?number} mentionTotalLimit The total number of role & user mentions allowed per message
|
* @property {?number} mentionTotalLimit The total number of role & user mentions allowed per message
|
||||||
|
* @property {boolean} mentionRaidProtectionEnabled Whether mention raid protection is enabled
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +81,7 @@ class AutoModerationRule extends Base {
|
|||||||
presets: data.trigger_metadata.presets ?? [],
|
presets: data.trigger_metadata.presets ?? [],
|
||||||
allowList: data.trigger_metadata.allow_list ?? [],
|
allowList: data.trigger_metadata.allow_list ?? [],
|
||||||
mentionTotalLimit: data.trigger_metadata.mention_total_limit ?? null,
|
mentionTotalLimit: data.trigger_metadata.mention_total_limit ?? null,
|
||||||
|
mentionRaidProtectionEnabled: data.trigger_metadata.mention_raid_protection_enabled ?? false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +227,17 @@ class AutoModerationRule extends Base {
|
|||||||
return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionTotalLimit }, reason });
|
return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionTotalLimit }, reason });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether to enable mention raid protection for this auto moderation rule.
|
||||||
|
* @param {boolean} mentionRaidProtectionEnabled
|
||||||
|
* Whether to enable mention raid protection for this auto moderation rule
|
||||||
|
* @param {string} [reason] The reason for changing the mention raid protection of this auto moderation rule
|
||||||
|
* @returns {Promise<AutoModerationRule>}
|
||||||
|
*/
|
||||||
|
setMentionRaidProtectionEnabled(mentionRaidProtectionEnabled, reason) {
|
||||||
|
return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionRaidProtectionEnabled }, reason });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the actions for this auto moderation rule.
|
* Sets the actions for this auto moderation rule.
|
||||||
* @param {AutoModerationActionOptions[]} actions The actions of this auto moderation rule
|
* @param {AutoModerationActionOptions[]} actions The actions of this auto moderation rule
|
||||||
|
|||||||
@@ -370,6 +370,16 @@ class Guild extends AnonymousGuild {
|
|||||||
this.preferredLocale = data.preferred_locale;
|
this.preferredLocale = data.preferred_locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('safety_alerts_channel_id' in data) {
|
||||||
|
/**
|
||||||
|
* The safety alerts channel's id for the guild
|
||||||
|
* @type {?Snowflake}
|
||||||
|
*/
|
||||||
|
this.safetyAlertsChannelId = data.safety_alerts_channel_id;
|
||||||
|
} else {
|
||||||
|
this.safetyAlertsChannelId ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.channels) {
|
if (data.channels) {
|
||||||
this.channels.cache.clear();
|
this.channels.cache.clear();
|
||||||
for (const rawChannel of data.channels) {
|
for (const rawChannel of data.channels) {
|
||||||
@@ -534,6 +544,15 @@ class Guild extends AnonymousGuild {
|
|||||||
return this.client.channels.resolve(this.publicUpdatesChannelId);
|
return this.client.channels.resolve(this.publicUpdatesChannelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safety alerts channel for this guild
|
||||||
|
* @type {?TextChannel}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get safetyAlertsChannel() {
|
||||||
|
return this.client.channels.resolve(this.safetyAlertsChannelId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum bitrate available for this guild
|
* The maximum bitrate available for this guild
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -760,6 +779,7 @@ class Guild extends AnonymousGuild {
|
|||||||
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
||||||
* @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
|
* @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
|
||||||
* @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
|
* @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
|
||||||
|
* @property {?TextChannelResolvable} [safetyAlertsChannel] The safety alerts channel of the guild
|
||||||
* @property {?string} [preferredLocale] The preferred locale of the guild
|
* @property {?string} [preferredLocale] The preferred locale of the guild
|
||||||
* @property {GuildFeature[]} [features] The features of the guild
|
* @property {GuildFeature[]} [features] The features of the guild
|
||||||
* @property {?string} [description] The discovery description of the guild
|
* @property {?string} [description] The discovery description of the guild
|
||||||
@@ -810,6 +830,7 @@ class Guild extends AnonymousGuild {
|
|||||||
publicUpdatesChannel,
|
publicUpdatesChannel,
|
||||||
preferredLocale,
|
preferredLocale,
|
||||||
premiumProgressBarEnabled,
|
premiumProgressBarEnabled,
|
||||||
|
safetyAlertsChannel,
|
||||||
...options
|
...options
|
||||||
}) {
|
}) {
|
||||||
const data = await this.client.rest.patch(Routes.guild(this.id), {
|
const data = await this.client.rest.patch(Routes.guild(this.id), {
|
||||||
@@ -832,6 +853,7 @@ class Guild extends AnonymousGuild {
|
|||||||
public_updates_channel_id: publicUpdatesChannel && this.client.channels.resolveId(publicUpdatesChannel),
|
public_updates_channel_id: publicUpdatesChannel && this.client.channels.resolveId(publicUpdatesChannel),
|
||||||
preferred_locale: preferredLocale,
|
preferred_locale: preferredLocale,
|
||||||
premium_progress_bar_enabled: premiumProgressBarEnabled,
|
premium_progress_bar_enabled: premiumProgressBarEnabled,
|
||||||
|
safety_alerts_channel_id: safetyAlertsChannel && this.client.channels.resolveId(safetyAlertsChannel),
|
||||||
},
|
},
|
||||||
reason: options.reason,
|
reason: options.reason,
|
||||||
});
|
});
|
||||||
@@ -1145,6 +1167,21 @@ class Guild extends AnonymousGuild {
|
|||||||
return this.edit({ premiumProgressBarEnabled: enabled, reason });
|
return this.edit({ premiumProgressBarEnabled: enabled, reason });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the safety alerts channel of the guild.
|
||||||
|
* @param {?TextChannelResolvable} safetyAlertsChannel The new safety alerts channel
|
||||||
|
* @param {string} [reason] Reason for changing the guild's safety alerts channel
|
||||||
|
* @returns {Promise<Guild>}
|
||||||
|
* @example
|
||||||
|
* // Edit the guild safety alerts channel
|
||||||
|
* guild.setSafetyAlertsChannel(channel)
|
||||||
|
* .then(updated => console.log(`Updated guild safety alerts channel to ${updated.safetyAlertsChannel.name}`))
|
||||||
|
* .catch(console.error);
|
||||||
|
*/
|
||||||
|
setSafetyAlertsChannel(safetyAlertsChannel, reason) {
|
||||||
|
return this.edit({ safetyAlertsChannel, reason });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits the guild's widget settings.
|
* Edits the guild's widget settings.
|
||||||
* @param {GuildWidgetSettingsData} settings The widget settings for the guild
|
* @param {GuildWidgetSettingsData} settings The widget settings for the guild
|
||||||
|
|||||||
9
packages/discord.js/typings/index.d.ts
vendored
9
packages/discord.js/typings/index.d.ts
vendored
@@ -378,6 +378,10 @@ export class AutoModerationRule extends Base {
|
|||||||
public setPresets(presets: AutoModerationRuleKeywordPresetType[], reason?: string): Promise<AutoModerationRule>;
|
public setPresets(presets: AutoModerationRuleKeywordPresetType[], reason?: string): Promise<AutoModerationRule>;
|
||||||
public setAllowList(allowList: string[], reason?: string): Promise<AutoModerationRule>;
|
public setAllowList(allowList: string[], reason?: string): Promise<AutoModerationRule>;
|
||||||
public setMentionTotalLimit(mentionTotalLimit: number, reason?: string): Promise<AutoModerationRule>;
|
public setMentionTotalLimit(mentionTotalLimit: number, reason?: string): Promise<AutoModerationRule>;
|
||||||
|
public setMentionRaidProtectionEnabled(
|
||||||
|
mentionRaidProtectionEnabled: boolean,
|
||||||
|
reason?: string,
|
||||||
|
): Promise<AutoModerationRule>;
|
||||||
public setActions(actions: AutoModerationActionOptions[], reason?: string): Promise<AutoModerationRule>;
|
public setActions(actions: AutoModerationActionOptions[], reason?: string): Promise<AutoModerationRule>;
|
||||||
public setEnabled(enabled?: boolean, reason?: string): Promise<AutoModerationRule>;
|
public setEnabled(enabled?: boolean, reason?: string): Promise<AutoModerationRule>;
|
||||||
public setExemptRoles(
|
public setExemptRoles(
|
||||||
@@ -1324,6 +1328,8 @@ export class Guild extends AnonymousGuild {
|
|||||||
public roles: RoleManager;
|
public roles: RoleManager;
|
||||||
public get rulesChannel(): TextChannel | null;
|
public get rulesChannel(): TextChannel | null;
|
||||||
public rulesChannelId: Snowflake | null;
|
public rulesChannelId: Snowflake | null;
|
||||||
|
public get safetyAlertsChannel(): TextChannel | null;
|
||||||
|
public safetyAlertsChannelId: Snowflake | null;
|
||||||
public scheduledEvents: GuildScheduledEventManager;
|
public scheduledEvents: GuildScheduledEventManager;
|
||||||
public get shard(): WebSocketShard;
|
public get shard(): WebSocketShard;
|
||||||
public shardId: number;
|
public shardId: number;
|
||||||
@@ -1380,6 +1386,7 @@ export class Guild extends AnonymousGuild {
|
|||||||
public setPreferredLocale(preferredLocale: Locale | null, reason?: string): Promise<Guild>;
|
public setPreferredLocale(preferredLocale: Locale | null, reason?: string): Promise<Guild>;
|
||||||
public setPublicUpdatesChannel(publicUpdatesChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
public setPublicUpdatesChannel(publicUpdatesChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||||
public setRulesChannel(rulesChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
public setRulesChannel(rulesChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||||
|
public setSafetyAlertsChannel(safetyAlertsChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||||
public setSplash(splash: BufferResolvable | Base64Resolvable | null, reason?: string): Promise<Guild>;
|
public setSplash(splash: BufferResolvable | Base64Resolvable | null, reason?: string): Promise<Guild>;
|
||||||
public setSystemChannel(systemChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
public setSystemChannel(systemChannel: TextChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||||
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
|
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
|
||||||
@@ -4570,6 +4577,7 @@ export interface AutoModerationTriggerMetadata {
|
|||||||
presets: AutoModerationRuleKeywordPresetType[];
|
presets: AutoModerationRuleKeywordPresetType[];
|
||||||
allowList: string[];
|
allowList: string[];
|
||||||
mentionTotalLimit: number | null;
|
mentionTotalLimit: number | null;
|
||||||
|
mentionRaidProtectionEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AwaitMessageComponentOptions<T extends CollectedMessageInteraction> = Omit<
|
export type AwaitMessageComponentOptions<T extends CollectedMessageInteraction> = Omit<
|
||||||
@@ -5484,6 +5492,7 @@ export interface GuildEditOptions {
|
|||||||
systemChannelFlags?: SystemChannelFlagsResolvable;
|
systemChannelFlags?: SystemChannelFlagsResolvable;
|
||||||
rulesChannel?: TextChannelResolvable | null;
|
rulesChannel?: TextChannelResolvable | null;
|
||||||
publicUpdatesChannel?: TextChannelResolvable | null;
|
publicUpdatesChannel?: TextChannelResolvable | null;
|
||||||
|
safetyAlertsChannel?: TextChannelResolvable | null;
|
||||||
preferredLocale?: Locale | null;
|
preferredLocale?: Locale | null;
|
||||||
features?: `${GuildFeature}`[];
|
features?: `${GuildFeature}`[];
|
||||||
description?: string | null;
|
description?: string | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user