mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
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:
@@ -89,7 +89,12 @@ class RoleManager extends BaseManager {
|
||||
* 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>
|
||||
* @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
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
@@ -100,28 +105,36 @@ class RoleManager extends BaseManager {
|
||||
* @example
|
||||
* // Create a new role with data and a reason
|
||||
* guild.roles.create({
|
||||
* data: {
|
||||
* name: 'Super Cool People',
|
||||
* color: 'BLUE',
|
||||
* },
|
||||
* name: 'Super Cool Blue People',
|
||||
* color: 'BLUE',
|
||||
* reason: 'we needed a role for Super Cool People',
|
||||
* })
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
create({ data = {}, reason } = {}) {
|
||||
if (data.color) data.color = resolveColor(data.color);
|
||||
if (data.permissions) data.permissions = Permissions.resolve(data.permissions);
|
||||
create(options = {}) {
|
||||
let { name, color, hoist, permissions, position, mentionable, reason } = options;
|
||||
if (color) color = resolveColor(color);
|
||||
if (permissions) permissions = Permissions.resolve(permissions);
|
||||
|
||||
return this.client.api
|
||||
.guilds(this.guild.id)
|
||||
.roles.post({ data, reason })
|
||||
.roles.post({
|
||||
data: {
|
||||
name,
|
||||
color,
|
||||
hoist,
|
||||
permissions,
|
||||
mentionable,
|
||||
},
|
||||
reason,
|
||||
})
|
||||
.then(r => {
|
||||
const { role } = this.client.actions.GuildRoleCreate.handle({
|
||||
guild_id: this.guild.id,
|
||||
role: r,
|
||||
});
|
||||
if (data.position) return role.setPosition(data.position, reason);
|
||||
if (position) return role.setPosition(position, reason);
|
||||
return role;
|
||||
});
|
||||
}
|
||||
|
||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -2021,7 +2021,7 @@ declare module 'discord.js' {
|
||||
public guild: Guild;
|
||||
public readonly premiumSubscriberRole: 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<Collection<Snowflake, Role>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user