Downgrade to v13
[vi] cảm giác đau khổ
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
|
||||
const process = require('node:process');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const CachedManager = require('./CachedManager');
|
||||
const { TypeError } = require('../errors');
|
||||
const { Role } = require('../structures/Role');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const PermissionsBitField = require('../util/PermissionsBitField');
|
||||
const { resolveColor } = require('../util/Util');
|
||||
const Util = require('../util/Util');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const { resolveColor, setPosition } = require('../util/Util');
|
||||
|
||||
let cacheWarningEmitted = false;
|
||||
|
||||
@@ -129,7 +127,7 @@ class RoleManager extends CachedManager {
|
||||
* // Create a new role with data and a reason
|
||||
* guild.roles.create({
|
||||
* name: 'Super Cool Blue People',
|
||||
* color: Colors.Blue,
|
||||
* color: 'BLUE',
|
||||
* reason: 'we needed a role for Super Cool People',
|
||||
* })
|
||||
* .then(console.log)
|
||||
@@ -138,7 +136,7 @@ class RoleManager extends CachedManager {
|
||||
async create(options = {}) {
|
||||
let { name, color, hoist, permissions, position, mentionable, reason, icon, unicodeEmoji } = options;
|
||||
color &&= resolveColor(color);
|
||||
if (typeof permissions !== 'undefined') permissions = new PermissionsBitField(permissions);
|
||||
if (typeof permissions !== 'undefined') permissions = new Permissions(permissions);
|
||||
if (icon) {
|
||||
const guildEmojiURL = this.guild.emojis.resolve(icon)?.url;
|
||||
icon = guildEmojiURL ? await DataResolver.resolveImage(guildEmojiURL) : await DataResolver.resolveImage(icon);
|
||||
@@ -146,7 +144,7 @@ class RoleManager extends CachedManager {
|
||||
}
|
||||
|
||||
const data = await this.client.api.guilds(this.guild.id).roles.post({
|
||||
body: {
|
||||
data: {
|
||||
name,
|
||||
color,
|
||||
hoist,
|
||||
@@ -156,12 +154,12 @@ class RoleManager extends CachedManager {
|
||||
unicode_emoji: unicodeEmoji,
|
||||
},
|
||||
reason,
|
||||
})
|
||||
});
|
||||
const { role } = this.client.actions.GuildRoleCreate.handle({
|
||||
guild_id: this.guild.id,
|
||||
role: data,
|
||||
});
|
||||
if (position) return this.setPosition(role, position, { reason });
|
||||
if (position) return role.setPosition(position, reason);
|
||||
return role;
|
||||
}
|
||||
|
||||
@@ -182,7 +180,19 @@ class RoleManager extends CachedManager {
|
||||
if (!role) throw new TypeError('INVALID_TYPE', 'role', 'RoleResolvable');
|
||||
|
||||
if (typeof data.position === 'number') {
|
||||
await this.setPosition(role, data.position, { reason });
|
||||
const updatedRoles = await setPosition(
|
||||
role,
|
||||
data.position,
|
||||
false,
|
||||
this.guild._sortedRoles(),
|
||||
this.client.api.guilds(this.guild.id).roles,
|
||||
reason,
|
||||
);
|
||||
|
||||
this.client.actions.GuildRolesPositionUpdate.handle({
|
||||
guild_id: this.guild.id,
|
||||
roles: updatedRoles,
|
||||
});
|
||||
}
|
||||
|
||||
let icon = data.icon;
|
||||
@@ -192,17 +202,17 @@ class RoleManager extends CachedManager {
|
||||
if (typeof icon !== 'string') icon = undefined;
|
||||
}
|
||||
|
||||
const body = {
|
||||
const _data = {
|
||||
name: data.name,
|
||||
color: typeof data.color === 'undefined' ? undefined : resolveColor(data.color),
|
||||
hoist: data.hoist,
|
||||
permissions: typeof data.permissions === 'undefined' ? undefined : new PermissionsBitField(data.permissions),
|
||||
permissions: typeof data.permissions === 'undefined' ? undefined : new Permissions(data.permissions),
|
||||
mentionable: data.mentionable,
|
||||
icon,
|
||||
unicode_emoji: data.unicodeEmoji,
|
||||
};
|
||||
|
||||
const d = await this.client.api.guilds(this.guild.id).roles(role.id).patch({ body, reason });
|
||||
const d = await this.client.api.guilds(this.guild.id).roles(role.id).patch({ data: _data, reason });
|
||||
|
||||
const clone = role._clone();
|
||||
clone._patch(d);
|
||||
@@ -217,54 +227,15 @@ class RoleManager extends CachedManager {
|
||||
* @example
|
||||
* // Delete a role
|
||||
* guild.roles.delete('222079219327434752', 'The role needed to go')
|
||||
* .then(() => console.log('Deleted the role'))
|
||||
* .then(deleted => console.log(`Deleted role ${deleted.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async delete(role, reason) {
|
||||
const id = this.resolveId(role);
|
||||
await this.client.api.guilds(this.guild.id).roles(id).delete({ reason });
|
||||
await this.client.api.guilds[this.guild.id].roles[id].delete({ reason });
|
||||
this.client.actions.GuildRoleDelete.handle({ guild_id: this.guild.id, role_id: id });
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new position of the role.
|
||||
* @param {RoleResolvable} role The role to change the position of
|
||||
* @param {number} position The new position for the role
|
||||
* @param {SetRolePositionOptions} [options] Options for setting the position
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // Set the position of the role
|
||||
* guild.roles.setPosition('222197033908436994', 1)
|
||||
* .then(updated => console.log(`Role position: ${updated.position}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async setPosition(role, position, { relative, reason } = {}) {
|
||||
role = this.resolve(role);
|
||||
if (!role) throw new TypeError('INVALID_TYPE', 'role', 'RoleResolvable');
|
||||
const updatedRoles = await Util.setPosition(
|
||||
role,
|
||||
position,
|
||||
relative,
|
||||
this.guild._sortedRoles(),
|
||||
this.client,
|
||||
Routes.guildRoles(this.guild.id),
|
||||
reason,
|
||||
);
|
||||
|
||||
this.client.actions.GuildRolesPositionUpdate.handle({
|
||||
guild_id: this.guild.id,
|
||||
roles: updatedRoles,
|
||||
});
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* The data needed for updating a guild role's position
|
||||
* @typedef {Object} GuildRolePosition
|
||||
* @property {RoleResolvable} role The role's id
|
||||
* @property {number} position The position to update
|
||||
*/
|
||||
|
||||
/**
|
||||
* Batch-updates the guild's role positions
|
||||
* @param {GuildRolePosition[]} rolePositions Role positions to update
|
||||
@@ -282,7 +253,9 @@ class RoleManager extends CachedManager {
|
||||
}));
|
||||
|
||||
// Call the API to update role positions
|
||||
await this.client.api.guilds(this.guild.id).roles.patch({ body: rolePositions });
|
||||
await this.client.api.guilds(this.guild.id).roles.patch({
|
||||
data: rolePositions,
|
||||
});
|
||||
return this.client.actions.GuildRolesPositionUpdate.handle({
|
||||
guild_id: this.guild.id,
|
||||
roles: rolePositions,
|
||||
|
||||
Reference in New Issue
Block a user