mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
chore: Miscellaneous fixes (#9271)
* fix(Message#editable): update editable check in threads locked (#9216) * fix(Message#editable): update editable check in threads locked * fix(Message#editable): add check in archived threads * fix: check manage threads permission only if thread is locked * fix: adding a full stop at the end of a sentence Co-authored-by: Jaworek <jaworekwiadomosci@gmail.com> --------- Co-authored-by: Jaworek <jaworekwiadomosci@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> * fix(ThreadManager): Respect `cache` and `force` in fetching (#9239) * fix(ThreadManager): Respect `cache` and `force` in fetching * refactor: remove defaults These are already defaulted down the line. --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * refactor(FetchThreadsOptions): Remove `active` (#9241) * refactor(FetchThreadsOptions): remove `active` * docs(FetchThreadsOptions): update description --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * docs: add more examples (#9252) * docs: add more examples * fix: fix grammar and syntax Co-authored-by: Jaw0r3k <jaworekwiadomosci@gmail.com> * chore: fine-tune examples * chore: replace double quotes with singles * fix: remove redundant example tag * fix: fix timeout logging * Update packages/discord.js/src/structures/GuildMember.js Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --------- Co-authored-by: Jaw0r3k <jaworekwiadomosci@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * docs(Role): Fix example for `comparePositionTo()` * docs(FetchArchivedThreadOptions): `before` respects `archive_timestamp`, not creation timestamp (#9240) docs(FetchArchivedThreadOptions): correct `before` description Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * fix(snowflake): snowflakes length (#9144) * fix(snowflake): fix snowflakes length * fix(snowflake): fix length * fix(Message): `bulkDeletable` permissions should be retrieved later for DMs (#9146) * fix(Message): permissions check should be done later the getter will error if used on a message originating from a DM * refactor: remove unessercary chaining * fix: invalid backport Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> * docs(Role): fix comparison example * fix(ClientUser): no mutation on edit * refactor: call bans.create directly * fix(AutocompleteInteraction): Send `name_localizations` correctly (#9238) fix(AutocompleteInteraction): send locale correctly Co-authored-by: space <spaceeec@yahoo.com> * fix: resolving string bitfield (#9262) fix: resolving bitfield Co-authored-by: space <spaceeec@yahoo.com> * fix: Keep symbols in actions manager (#9293) fix: keep symbols in actions manager * fix: add support for new guild feature `GUILD_WEB_PAGE_VANITY_URL` (#9219) Co-authored-by: space <spaceeec@yahoo.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * docs: differ `User#send` (#9251) * docs: differate user#send * chore: format * chore: remove some examples * docs: add GuildMember#send example --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * docs: describe private properties (#8879) * feat: describe private properties * Update packages/discord.js/src/structures/GuildMember.js Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> * Apply suggestions from code review --------- Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --------- Co-authored-by: Erwan <erwan977@gmail.com> Co-authored-by: Jaworek <jaworekwiadomosci@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Tetie <tjvssr@gmail.com> Co-authored-by: DraftMan <contact@draftman.fr> Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: Jaw0r3k <jaw0r3k.g@gmail.com> Co-authored-by: space <spaceeec@yahoo.com> Co-authored-by: pkdev08 <54294685+pkdev08@users.noreply.github.com> Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com>
This commit is contained in:
@@ -96,9 +96,7 @@ class AutocompleteInteraction extends Interaction {
|
||||
await this.client.api.interactions(this.id, this.token).callback.post({
|
||||
data: {
|
||||
type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT,
|
||||
data: {
|
||||
choices: options,
|
||||
},
|
||||
data: { choices: { ...options, name_localizations: options.nameLocalizations } },
|
||||
},
|
||||
auth: false,
|
||||
});
|
||||
|
||||
@@ -53,11 +53,13 @@ class ClientUser extends User {
|
||||
* @param {ClientUserEditData} data The new data
|
||||
* @returns {Promise<ClientUser>}
|
||||
*/
|
||||
async edit(data) {
|
||||
if (typeof data.avatar !== 'undefined') data.avatar = await DataResolver.resolveImage(data.avatar);
|
||||
const newData = await this.client.api.users('@me').patch({ data });
|
||||
this.client.token = newData.token;
|
||||
const { updated } = this.client.actions.UserUpdate.handle(newData);
|
||||
async edit({ username, avatar }) {
|
||||
const data = await this.client.api
|
||||
.users('@me')
|
||||
.patch({ username, avatar: avatar && (await DataResolver.resolveImage(avatar)) });
|
||||
|
||||
this.client.token = data.token;
|
||||
const { updated } = this.client.actions.UserUpdate.handle(data);
|
||||
return updated ?? this;
|
||||
}
|
||||
|
||||
|
||||
@@ -716,9 +716,6 @@ class Guild extends AnonymousGuild {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchVanityData() {
|
||||
if (!this.features.includes('VANITY_URL')) {
|
||||
throw new Error('VANITY_URL');
|
||||
}
|
||||
const data = await this.client.api.guilds(this.id, 'vanity-url').get();
|
||||
this.vanityURLCode = data.code;
|
||||
this.vanityURLUses = data.uses;
|
||||
@@ -1341,7 +1338,7 @@ class Guild extends AnonymousGuild {
|
||||
* @example
|
||||
* // Leave a guild
|
||||
* guild.leave()
|
||||
* .then(g => console.log(`Left the guild ${g}`))
|
||||
* .then(guild => console.log(`Left the guild: ${guild.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async leave() {
|
||||
|
||||
@@ -62,6 +62,11 @@ class GuildMember extends Base {
|
||||
*/
|
||||
this.communicationDisabledUntilTimestamp = null;
|
||||
|
||||
/**
|
||||
* The role ids of the member
|
||||
* @type {Snowflake[]}
|
||||
* @private
|
||||
*/
|
||||
this._roles = [];
|
||||
if (data) this._patch(data);
|
||||
}
|
||||
@@ -352,6 +357,16 @@ class GuildMember extends Base {
|
||||
* @param {?string} nick The nickname for the guild member, or `null` if you want to reset their nickname
|
||||
* @param {string} [reason] Reason for setting the nickname
|
||||
* @returns {Promise<GuildMember>}
|
||||
* @example
|
||||
* // Set a nickname for a guild member
|
||||
* guildMember.setNickname('cool nickname', 'Needed a new nickname')
|
||||
* .then(member => console.log(`Set nickname of ${member.user.username}`))
|
||||
* .catch(console.error);
|
||||
* @example
|
||||
* // Remove a nickname for a guild member
|
||||
* guildMember.setNickname(null, 'No nicknames allowed!')
|
||||
* .then(member => console.log(`Removed nickname for ${member.user.username}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setNickname(nick, reason) {
|
||||
return this.edit({ nick }, reason);
|
||||
@@ -404,7 +419,7 @@ class GuildMember extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
ban(options) {
|
||||
return this.guild.members.ban(this, options);
|
||||
return this.guild.bans.create(this, options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,6 +433,11 @@ class GuildMember extends Base {
|
||||
* guildMember.disableCommunicationUntil(Date.now() + (5 * 60 * 1000), 'They deserved it')
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
* @example
|
||||
* // Remove the timeout of a guild member
|
||||
* guildMember.disableCommunicationUntil(null)
|
||||
* .then(member => console.log(`Removed timeout for ${member.displayName}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
disableCommunicationUntil(communicationDisabledUntil, reason) {
|
||||
return this.edit({ communicationDisabledUntil }, reason);
|
||||
@@ -494,12 +514,22 @@ class GuildMember extends Base {
|
||||
json.displayAvatarURL = this.displayAvatarURL();
|
||||
return json;
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to this user.
|
||||
* @method send
|
||||
* @memberof GuildMember
|
||||
* @instance
|
||||
* @param {string|MessagePayload|MessageOptions} options The options to provide
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Send a direct message
|
||||
* guildMember.send('Hello!')
|
||||
* .then(message => console.log(`Sent message: ${message.content} to ${guildMember.displayName}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
|
||||
TextBasedChannel.applyToClass(GuildMember);
|
||||
|
||||
exports.GuildMember = GuildMember;
|
||||
|
||||
@@ -599,11 +599,17 @@ class Message extends Base {
|
||||
const precheck = Boolean(
|
||||
this.author.id === this.client.user.id && !deletedMessages.has(this) && (!this.guild || this.channel?.viewable),
|
||||
);
|
||||
|
||||
// Regardless of permissions thread messages cannot be edited if
|
||||
// the thread is locked.
|
||||
// the thread is archived or the thread is locked and the bot does not have permission to manage threads.
|
||||
if (this.channel?.isThread()) {
|
||||
return precheck && !this.channel.locked;
|
||||
if (this.channel.archived) return false;
|
||||
if (this.channel.locked) {
|
||||
const permissions = this.permissionsFor(this.client.user);
|
||||
if (!permissions?.has(Permissions.FLAGS.MANAGE_THREADS, true)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return precheck;
|
||||
}
|
||||
|
||||
@@ -645,12 +651,11 @@ class Message extends Base {
|
||||
* channel.bulkDelete(messages.filter(message => message.bulkDeletable));
|
||||
*/
|
||||
get bulkDeletable() {
|
||||
const permissions = this.channel?.permissionsFor(this.client.user);
|
||||
return (
|
||||
(this.inGuild() &&
|
||||
Date.now() - this.createdTimestamp < MaxBulkDeletableMessageAge &&
|
||||
this.deletable &&
|
||||
permissions?.has(Permissions.FLAGS.MANAGE_MESSAGES, false)) ??
|
||||
this.channel?.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES, false)) ??
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -155,6 +155,12 @@ class Presence extends Base {
|
||||
*/
|
||||
class Activity {
|
||||
constructor(presence, data) {
|
||||
/**
|
||||
* The presence of the Activity
|
||||
* @type {Presence}
|
||||
* @readonly
|
||||
* @name Activity#presence
|
||||
*/
|
||||
Object.defineProperty(this, 'presence', { value: presence });
|
||||
|
||||
/**
|
||||
@@ -325,6 +331,12 @@ class Activity {
|
||||
*/
|
||||
class RichPresenceAssets {
|
||||
constructor(activity, assets) {
|
||||
/**
|
||||
* The activity of the RichPresenceAssets
|
||||
* @type {Activity}
|
||||
* @readonly
|
||||
* @name RichPresenceAssets#activity
|
||||
*/
|
||||
Object.defineProperty(this, 'activity', { value: activity });
|
||||
|
||||
/**
|
||||
|
||||
@@ -233,6 +233,10 @@ class Role extends Base {
|
||||
* @param {RoleResolvable} role Role to compare to this one
|
||||
* @returns {number} Negative number if this role's position is lower (other role's is higher),
|
||||
* positive number if this one is higher (other's is lower), 0 if equal
|
||||
* @example
|
||||
* // Compare the position of a role to another
|
||||
* const roleCompare = role.comparePositionTo(otherRole);
|
||||
* if (roleCompare >= 1) console.log(`${role.name} is higher than ${otherRole.name}`);
|
||||
*/
|
||||
comparePositionTo(role) {
|
||||
return this.guild.roles.comparePositions(this, role);
|
||||
|
||||
@@ -310,12 +310,22 @@ class User extends Base {
|
||||
json.bannerURL = this.banner ? this.bannerURL() : this.banner;
|
||||
return json;
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to this user.
|
||||
* @method send
|
||||
* @memberof User
|
||||
* @instance
|
||||
* @param {string|MessagePayload|MessageOptions} options The options to provide
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Send a direct message
|
||||
* user.send('Hello!')
|
||||
* .then(message => console.log(`Sent message: ${message.content} to ${user.tag}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
|
||||
TextBasedChannel.applyToClass(User);
|
||||
|
||||
module.exports = User;
|
||||
|
||||
@@ -136,25 +136,6 @@ class TextBasedChannel {
|
||||
* })
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
* @example
|
||||
* // Send an embed with a local image inside
|
||||
* channel.send({
|
||||
* content: 'This is an embed',
|
||||
* embeds: [
|
||||
* {
|
||||
* thumbnail: {
|
||||
* url: 'attachment://file.jpg'
|
||||
* }
|
||||
* }
|
||||
* ],
|
||||
* files: [{
|
||||
* attachment: 'entire/path/to/file.jpg',
|
||||
* name: 'file.jpg',
|
||||
* description: 'A description of the file'
|
||||
* }]
|
||||
* })
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async send(options) {
|
||||
const User = require('../User');
|
||||
|
||||
Reference in New Issue
Block a user