Skip to content

Commit

Permalink
fix: Remove deprecation warning on Message#cleanContent (#7143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Dec 26, 2021
1 parent f1d35e3 commit 7e5f16b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/util/Util.js
Expand Up @@ -538,6 +538,10 @@ class Util extends null {
deprecationEmittedForRemoveMentions = true;
}

return Util._removeMentions(str);
}

static _removeMentions(str) {
return str.replaceAll('@', '@\u200b');
}

Expand All @@ -555,15 +559,15 @@ class Util extends null {
const id = input.replace(/<|!|>|@/g, '');
if (channel.type === 'DM') {
const user = channel.client.users.cache.get(id);
return user ? Util.removeMentions(`@${user.username}`) : input;
return user ? Util._removeMentions(`@${user.username}`) : input;
}

const member = channel.guild.members.cache.get(id);
if (member) {
return Util.removeMentions(`@${member.displayName}`);
return Util._removeMentions(`@${member.displayName}`);
} else {
const user = channel.client.users.cache.get(id);
return user ? Util.removeMentions(`@${user.username}`) : input;
return user ? Util._removeMentions(`@${user.username}`) : input;
}
})
.replace(/<#[0-9]+>/g, input => {
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -2416,6 +2416,7 @@ export class Util extends null {
public static cleanContent(str: string, channel: TextBasedChannel): string;
/** @deprecated Use {@link MessageOptions.allowedMentions} to control mentions in a message instead. */
public static removeMentions(str: string): string;
private static _removeMentions(str: string): string;
public static cloneObject(obj: unknown): unknown;
public static discordSort<K, V extends { rawPosition: number; id: Snowflake }>(
collection: Collection<K, V>,
Expand Down

0 comments on commit 7e5f16b

Please sign in to comment.