mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
chore: Emit deprecation messages (#6994)
This commit is contained in:
@@ -34,6 +34,9 @@ const DataResolver = require('../util/DataResolver');
|
||||
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
let deprecationEmittedForSetChannelPositions = false;
|
||||
let deprecationEmittedForSetRolePositions = false;
|
||||
|
||||
/**
|
||||
* Represents a guild (or a server) on Discord.
|
||||
* <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
|
||||
@@ -1195,6 +1198,15 @@ class Guild extends AnonymousGuild {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setChannelPositions(channelPositions) {
|
||||
if (!deprecationEmittedForSetChannelPositions) {
|
||||
process.emitWarning(
|
||||
'The Guild#setChannelPositions method is deprecated. Use GuildChannelManager#setPositions instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForSetChannelPositions = true;
|
||||
}
|
||||
|
||||
return this.channels.setPositions(channelPositions);
|
||||
}
|
||||
|
||||
@@ -1216,6 +1228,15 @@ class Guild extends AnonymousGuild {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setRolePositions(rolePositions) {
|
||||
if (!deprecationEmittedForSetRolePositions) {
|
||||
process.emitWarning(
|
||||
'The Guild#setRolePositions method is deprecated. Use RoleManager#setPositions instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForSetRolePositions = true;
|
||||
}
|
||||
|
||||
return this.roles.setPositions(rolePositions);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
const { RangeError } = require('../errors');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
let deprecationEmittedForSetAuthor = false;
|
||||
|
||||
/**
|
||||
* Represents an embed in a message (image/video preview, rich embed, etc.)
|
||||
*/
|
||||
@@ -372,6 +374,19 @@ class MessageEmbed {
|
||||
}
|
||||
|
||||
if (typeof options === 'string') {
|
||||
if (
|
||||
!deprecationEmittedForSetAuthor &&
|
||||
(typeof deprecatedIconURL !== 'undefined' || typeof deprecatedURL !== 'undefined')
|
||||
) {
|
||||
process.emitWarning(
|
||||
// eslint-disable-next-line max-len
|
||||
"Passing strings for the URL or the icon's URL for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.",
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForSetAuthor = true;
|
||||
}
|
||||
|
||||
options = { name: options, url: deprecatedURL, iconURL: deprecatedIconURL };
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel');
|
||||
const Permissions = require('../util/Permissions');
|
||||
|
||||
let deprecationEmittedForEditable = false;
|
||||
|
||||
/**
|
||||
* Represents a guild voice channel on Discord.
|
||||
* @extends {BaseGuildVoiceChannel}
|
||||
@@ -15,6 +17,15 @@ class VoiceChannel extends BaseGuildVoiceChannel {
|
||||
* @deprecated Use {@link VoiceChannel#manageable} instead
|
||||
*/
|
||||
get editable() {
|
||||
if (!deprecationEmittedForEditable) {
|
||||
process.emitWarning(
|
||||
'The VoiceChannel#editable getter is deprecated. Use VoiceChannel#manageable instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForEditable = true;
|
||||
}
|
||||
|
||||
return this.manageable;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ const { WebhookTypes } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||
|
||||
let deprecationEmittedForFetchMessage = false;
|
||||
|
||||
/**
|
||||
* Represents a webhook.
|
||||
*/
|
||||
@@ -270,12 +272,21 @@ class Webhook {
|
||||
* Gets a message that was sent by this webhook.
|
||||
* @param {Snowflake|'@original'} message The id of the message to fetch
|
||||
* @param {WebhookFetchMessageOptions|boolean} [cacheOrOptions={}] The options to provide to fetch the message.
|
||||
* A **deprecated** boolean may be passed instead to specify whether to cache the message.
|
||||
* <warn>A **deprecated** boolean may be passed instead to specify whether to cache the message.</warn>
|
||||
* @returns {Promise<Message|APIMessage>} Returns the raw message data if the webhook was instantiated as a
|
||||
* {@link WebhookClient} or if the channel is uncached, otherwise a {@link Message} will be returned
|
||||
*/
|
||||
async fetchMessage(message, cacheOrOptions = { cache: true }) {
|
||||
if (typeof cacheOrOptions === 'boolean') {
|
||||
if (!deprecationEmittedForFetchMessage) {
|
||||
process.emitWarning(
|
||||
'Passing a boolean to cache the message in Webhook#fetchMessage is deprecated. Pass an object instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForFetchMessage = true;
|
||||
}
|
||||
|
||||
cacheOrOptions = { cache: cacheOrOptions };
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
||||
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
||||
const isObject = d => typeof d === 'object' && d !== null;
|
||||
|
||||
let deprecationEmittedForRemoveMentions = false;
|
||||
|
||||
/**
|
||||
* Contains various general-purpose utility methods.
|
||||
*/
|
||||
@@ -578,6 +580,15 @@ class Util extends null {
|
||||
* @deprecated Use {@link BaseMessageOptions#allowedMentions} instead.
|
||||
*/
|
||||
static removeMentions(str) {
|
||||
if (!deprecationEmittedForRemoveMentions) {
|
||||
process.emitWarning(
|
||||
'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
|
||||
deprecationEmittedForRemoveMentions = true;
|
||||
}
|
||||
|
||||
return str.replaceAll('@', '@\u200b');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user