mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
refactor: Move me and add fetchMe() (#9029)
This commit is contained in:
@@ -75,7 +75,7 @@ class BaseGuildVoiceChannel extends GuildChannel {
|
||||
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
|
||||
|
||||
return (
|
||||
this.guild.me.communicationDisabledUntilTimestamp < Date.now() &&
|
||||
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() &&
|
||||
permissions.has(Permissions.FLAGS.CONNECT, false)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ const VoiceStateManager = require('../managers/VoiceStateManager');
|
||||
const {
|
||||
ChannelTypes,
|
||||
DefaultMessageNotificationLevels,
|
||||
PartialTypes,
|
||||
VerificationLevels,
|
||||
ExplicitContentFilterLevels,
|
||||
Status,
|
||||
@@ -39,6 +38,7 @@ const Util = require('../util/Util');
|
||||
let deprecationEmittedForSetChannelPositions = false;
|
||||
let deprecationEmittedForSetRolePositions = false;
|
||||
let deprecationEmittedForDeleted = false;
|
||||
let deprecationEmittedForMe = false;
|
||||
|
||||
/**
|
||||
* @type {WeakSet<Guild>}
|
||||
@@ -590,15 +590,16 @@ class Guild extends AnonymousGuild {
|
||||
/**
|
||||
* The client user as a GuildMember of this guild
|
||||
* @type {?GuildMember}
|
||||
* @deprecated Use {@link GuildMemberManager#me} instead.
|
||||
* @readonly
|
||||
*/
|
||||
get me() {
|
||||
return (
|
||||
this.members.resolve(this.client.user.id) ??
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
|
||||
? this.members._add({ user: { id: this.client.user.id } }, true)
|
||||
: null)
|
||||
);
|
||||
if (!deprecationEmittedForMe) {
|
||||
process.emitWarning('Guild#me is deprecated. Use Guild#members#me instead.', 'DeprecationWarning');
|
||||
deprecationEmittedForMe = true;
|
||||
}
|
||||
|
||||
return this.members.me;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -415,7 +415,7 @@ class GuildChannel extends Channel {
|
||||
|
||||
// This flag allows managing even if timed out
|
||||
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
|
||||
if (this.guild.me.communicationDisabledUntilTimestamp > Date.now()) return false;
|
||||
if (this.guild.members.me.communicationDisabledUntilTimestamp > Date.now()) return false;
|
||||
|
||||
const bitfield = VoiceBasedChannelTypes.includes(this.type)
|
||||
? Permissions.FLAGS.MANAGE_CHANNELS | Permissions.FLAGS.CONNECT
|
||||
|
||||
@@ -55,8 +55,8 @@ class GuildEmoji extends BaseGuildEmoji {
|
||||
* @readonly
|
||||
*/
|
||||
get deletable() {
|
||||
if (!this.guild.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
return !this.managed && this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS_AND_STICKERS);
|
||||
if (!this.guild.members.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
return !this.managed && this.guild.members.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS_AND_STICKERS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -272,8 +272,8 @@ class GuildMember extends Base {
|
||||
if (this.user.id === this.guild.ownerId) return false;
|
||||
if (this.user.id === this.client.user.id) return false;
|
||||
if (this.client.user.id === this.guild.ownerId) return true;
|
||||
if (!this.guild.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
return this.guild.me.roles.highest.comparePositionTo(this.roles.highest) > 0;
|
||||
if (!this.guild.members.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
return this.guild.members.me.roles.highest.comparePositionTo(this.roles.highest) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +282,7 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get kickable() {
|
||||
return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS);
|
||||
return this.manageable && this.guild.members.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,7 +291,7 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get bannable() {
|
||||
return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.BAN_MEMBERS);
|
||||
return this.manageable && this.guild.members.me.permissions.has(Permissions.FLAGS.BAN_MEMBERS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +303,7 @@ class GuildMember extends Base {
|
||||
return (
|
||||
!this.permissions.has(Permissions.FLAGS.ADMINISTRATOR) &&
|
||||
this.manageable &&
|
||||
(this.guild.me?.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS) ?? false)
|
||||
(this.guild.members.me?.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS) ?? false)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -241,10 +241,10 @@ class Invite extends Base {
|
||||
get deletable() {
|
||||
const guild = this.guild;
|
||||
if (!guild || !this.client.guilds.cache.has(guild.id)) return false;
|
||||
if (!guild.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
if (!guild.members.me) throw new Error('GUILD_UNCACHED_ME');
|
||||
return (
|
||||
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) ||
|
||||
guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD)
|
||||
guild.members.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -632,7 +632,7 @@ class Message extends Base {
|
||||
return Boolean(
|
||||
this.author.id === this.client.user.id ||
|
||||
(permissions.has(Permissions.FLAGS.MANAGE_MESSAGES, false) &&
|
||||
this.guild.me.communicationDisabledUntilTimestamp < Date.now()),
|
||||
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ class ThreadChannel extends Channel {
|
||||
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
|
||||
|
||||
return (
|
||||
this.guild.me.communicationDisabledUntilTimestamp < Date.now() &&
|
||||
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() &&
|
||||
permissions.has(Permissions.FLAGS.MANAGE_THREADS, false)
|
||||
);
|
||||
}
|
||||
@@ -553,7 +553,7 @@ class ThreadChannel extends Channel {
|
||||
!(this.archived && this.locked && !this.manageable) &&
|
||||
(this.type !== 'GUILD_PRIVATE_THREAD' || this.joined || this.manageable) &&
|
||||
permissions.has(Permissions.FLAGS.SEND_MESSAGES_IN_THREADS, false) &&
|
||||
this.guild.me.communicationDisabledUntilTimestamp < Date.now()
|
||||
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,8 @@ class VoiceChannel extends BaseGuildVoiceChannel {
|
||||
if (permissions.has(Permissions.FLAGS.ADMINISTRATOR, false)) return true;
|
||||
|
||||
return (
|
||||
this.guild.me.communicationDisabledUntilTimestamp < Date.now() && permissions.has(Permissions.FLAGS.SPEAK, false)
|
||||
this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() &&
|
||||
permissions.has(Permissions.FLAGS.SPEAK, false)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,10 +208,10 @@ class VoiceState extends Base {
|
||||
* @param {boolean} [request=true] Whether or not the client is requesting to become a speaker.
|
||||
* @example
|
||||
* // Making the client request to speak in a stage channel (raise its hand)
|
||||
* guild.me.voice.setRequestToSpeak(true);
|
||||
* guild.members.me.voice.setRequestToSpeak(true);
|
||||
* @example
|
||||
* // Making the client cancel a request to speak
|
||||
* guild.me.voice.setRequestToSpeak(false);
|
||||
* guild.members.me.voice.setRequestToSpeak(false);
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async setRequestToSpeak(request = true) {
|
||||
@@ -232,10 +232,10 @@ class VoiceState extends Base {
|
||||
* @param {boolean} [suppressed=true] Whether or not the user should be suppressed.
|
||||
* @example
|
||||
* // Making the client a speaker
|
||||
* guild.me.voice.setSuppressed(false);
|
||||
* guild.members.me.voice.setSuppressed(false);
|
||||
* @example
|
||||
* // Making the client an audience member
|
||||
* guild.me.voice.setSuppressed(true);
|
||||
* guild.members.me.voice.setSuppressed(true);
|
||||
* @example
|
||||
* // Inviting another user to speak
|
||||
* voiceState.setSuppressed(false);
|
||||
|
||||
Reference in New Issue
Block a user