chore(RoleManager): change parameter of create to be one unnamed object (#5026)

* chore(RoleManager): change parameter of create to be one unnamed object

* chore(RoleManager): update src/managers/RoleManager.js

* chore(RoleManager): update typings/index.d.ts

* chore(RoleManager): update src/managers/RoleManager.js

Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
ManEatingTapir
2020-12-26 03:59:16 -06:00
committed by GitHub
parent 2aea7dd921
commit 6a77453532
2 changed files with 24 additions and 11 deletions

View File

@@ -89,7 +89,12 @@ class RoleManager extends BaseManager {
* Creates a new role in the guild with given information. * Creates a new role in the guild with given information.
* <warn>The position will silently reset to 1 if an invalid one is provided, or none.</warn> * <warn>The position will silently reset to 1 if an invalid one is provided, or none.</warn>
* @param {Object} [options] Options * @param {Object} [options] Options
* @param {RoleData} [options.data] The data to create the role with * @param {string} [options.name] The name of the new role
* @param {ColorResolvable} [options.color] The data to create the role with
* @param {boolean} [options.hoist] Whether or not the new role should be hoisted.
* @param {PermissionResolvable} [options.permissions] The permissions for the new role
* @param {number} [options.position] The position of the new role
* @param {boolean} [options.mentionable] Whether or not the new role should be mentionable.
* @param {string} [options.reason] Reason for creating this role * @param {string} [options.reason] Reason for creating this role
* @returns {Promise<Role>} * @returns {Promise<Role>}
* @example * @example
@@ -100,28 +105,36 @@ class RoleManager extends BaseManager {
* @example * @example
* // Create a new role with data and a reason * // Create a new role with data and a reason
* guild.roles.create({ * guild.roles.create({
* data: { * name: 'Super Cool Blue People',
* name: 'Super Cool People', * color: 'BLUE',
* color: 'BLUE',
* },
* reason: 'we needed a role for Super Cool People', * reason: 'we needed a role for Super Cool People',
* }) * })
* .then(console.log) * .then(console.log)
* .catch(console.error); * .catch(console.error);
*/ */
create({ data = {}, reason } = {}) { create(options = {}) {
if (data.color) data.color = resolveColor(data.color); let { name, color, hoist, permissions, position, mentionable, reason } = options;
if (data.permissions) data.permissions = Permissions.resolve(data.permissions); if (color) color = resolveColor(color);
if (permissions) permissions = Permissions.resolve(permissions);
return this.client.api return this.client.api
.guilds(this.guild.id) .guilds(this.guild.id)
.roles.post({ data, reason }) .roles.post({
data: {
name,
color,
hoist,
permissions,
mentionable,
},
reason,
})
.then(r => { .then(r => {
const { role } = this.client.actions.GuildRoleCreate.handle({ const { role } = this.client.actions.GuildRoleCreate.handle({
guild_id: this.guild.id, guild_id: this.guild.id,
role: r, role: r,
}); });
if (data.position) return role.setPosition(data.position, reason); if (position) return role.setPosition(position, reason);
return role; return role;
}); });
} }

2
typings/index.d.ts vendored
View File

@@ -2021,7 +2021,7 @@ declare module 'discord.js' {
public guild: Guild; public guild: Guild;
public readonly premiumSubscriberRole: Role | null; public readonly premiumSubscriberRole: Role | null;
public botRoleFor(user: UserResolvable): Role | null; public botRoleFor(user: UserResolvable): Role | null;
public create(options?: { data?: RoleData; reason?: string }): Promise<Role>; public create(options?: RoleData & { reason?: string }): Promise<Role>;
public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Role | null>; public fetch(id: Snowflake, cache?: boolean, force?: boolean): Promise<Role | null>;
public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, Role>>; public fetch(id?: Snowflake, cache?: boolean, force?: boolean): Promise<Collection<Snowflake, Role>>;
} }