diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs
index 0e12318ab..3f6b50e67 100644
--- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs
+++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs
@@ -569,13 +569,17 @@ namespace Discord
///
/// Creates a new role with the provided name.
///
- /// The delegate containing the properties to be applied to the role upon creation.
+ /// The new name for the role.
+ /// The guild permission that the role should possess.
+ /// The color of the role.
+ /// Whether the role is separated from others on the sidebar.
+ /// Whether the role is mentionable or not.
/// The options to be used when sending the request.
///
/// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role.
///
- Task CreateRoleAsync(Action func, RequestOptions options = null);
+ Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, bool isMentionable = false, RequestOptions options = null);
///
/// Adds a user to this guild.
diff --git a/src/Discord.Net.Core/Extensions/GuildExtensions.cs b/src/Discord.Net.Core/Extensions/GuildExtensions.cs
index 58b749cc4..d1b79521c 100644
--- a/src/Discord.Net.Core/Extensions/GuildExtensions.cs
+++ b/src/Discord.Net.Core/Extensions/GuildExtensions.cs
@@ -1,3 +1,6 @@
+using System;
+using System.Threading.Tasks;
+
namespace Discord
{
///
@@ -20,5 +23,33 @@ namespace Discord
/// A bool indicating if the guild boost messages are enabled in the system channel.
public static bool GetGuildBoostMessagesEnabled(this IGuild guild)
=> !guild.SystemChannelFlags.HasFlag(SystemChannelMessageDeny.GuildBoost);
+
+ ///
+ /// Creates a new role with the provided name.
+ ///
+ /// The guild you want to create the role for.
+ /// The delegate to modify the properties of the role with.
+ /// The options to be used when sending the request.
+ /// is null.
+ ///
+ /// A task that represents the asynchronous creation operation. The task result contains the newly created
+ /// role.
+ ///
+ public static async Task CreateRoleAsync(this IGuild guild, Action func, RequestOptions options = null)
+ {
+ if (func is null)
+ throw new ArgumentNullException(nameof(func));
+
+ var args = new RoleProperties();
+ func(args);
+
+ return await guild.CreateRoleAsync(
+ args.Name.GetValueOrDefault(),
+ args.Permissions.GetValueOrDefault(),
+ args.Color.GetValueOrDefault(),
+ args.Hoist.GetValueOrDefault(),
+ args.Mentionable.GetValueOrDefault(),
+ options);
+ }
}
}
diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
index b56f50f40..3ab8870cd 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
@@ -250,17 +250,16 @@ namespace Discord.Rest
//Roles
/// is null.
- public static async Task CreateRoleAsync(IGuild guild, BaseDiscordClient client, Action func, RequestOptions options)
+ public static async Task CreateRoleAsync(IGuild guild, BaseDiscordClient client,
+ string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options)
{
- var args = new RoleProperties();
- func(args);
var apiArgs = new API.Rest.GuildRoleParams
{
- Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create(),
- Hoist = args.Hoist,
- Mentionable = args.Mentionable,
- Name = args.Name,
- Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create()
+ Color = color?.RawValue ?? Optional.Create(),
+ Hoist = isHoisted,
+ Mentionable = isMentionable,
+ Name = name,
+ Permissions = permissions?.RawValue ?? Optional.Create()
};
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
@@ -431,7 +430,7 @@ namespace Discord.Rest
var emote = await client.ApiClient.GetGuildEmoteAsync(guild.Id, id, options).ConfigureAwait(false);
return emote.ToEntity();
}
- public static async Task CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional> roles,
+ public static async Task CreateEmoteAsync(IGuild guild, BaseDiscordClient client, string name, Image image, Optional> roles,
RequestOptions options)
{
var apiargs = new CreateGuildEmoteParams
@@ -446,7 +445,7 @@ namespace Discord.Rest
return emote.ToEntity();
}
/// is null.
- public static async Task ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action func,
+ public static async Task ModifyEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, Action func,
RequestOptions options)
{
if (func == null) throw new ArgumentNullException(paramName: nameof(func));
@@ -464,7 +463,7 @@ namespace Discord.Rest
var emote = await client.ApiClient.ModifyGuildEmoteAsync(guild.Id, id, apiargs, options).ConfigureAwait(false);
return emote.ToEntity();
}
- public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
+ public static Task DeleteEmoteAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options)
=> client.ApiClient.DeleteGuildEmoteAsync(guild.Id, id, options);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
index d3f9cb9ba..7a07e3785 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
@@ -197,7 +197,7 @@ namespace Discord.Rest
role?.Update(model);
}
}
-
+
///
public Task LeaveAsync(RequestOptions options = null)
=> GuildHelper.LeaveAsync(this, Discord, options);
@@ -525,15 +525,20 @@ namespace Discord.Rest
///
/// Creates a new role with the provided name.
///
- /// The delegate containing the properties to be applied to the role upon creation.
+ /// The new name for the role.
+ /// The guild permission that the role should possess.
+ /// The color of the role.
+ /// Whether the role is separated from others on the sidebar.
+ /// Whether the role is mentionable or not.
/// The options to be used when sending the request.
///
/// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role.
///
- public async Task CreateRoleAsync(Action func, RequestOptions options = null)
+ public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
+ bool isHoisted = false, bool isMentionable = false, RequestOptions options = null)
{
- var role = await GuildHelper.CreateRoleAsync(this, Discord, func, options).ConfigureAwait(false);
+ var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false);
_roles = _roles.Add(role.Id, role);
return role;
}
@@ -820,8 +825,8 @@ namespace Discord.Rest
IRole IGuild.GetRole(ulong id)
=> GetRole(id);
///
- async Task IGuild.CreateRoleAsync(Action func, RequestOptions options)
- => await CreateRoleAsync(func, options).ConfigureAwait(false);
+ async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options)
+ => await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false);
///
async Task IGuild.AddGuildUserAsync(ulong userId, string accessToken, Action func, RequestOptions options)
diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
index 9efff5b28..1c9a2aca9 100644
--- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
+++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
@@ -674,15 +674,22 @@ namespace Discord.WebSocket
///
/// Creates a new role with the provided name.
///
- /// The delegate containing the properties to be applied to the role upon creation.
+ /// The new name for the role.
+ /// The guild permission that the role should possess.
+ /// The color of the role.
+ /// Whether the role is separated from others on the sidebar.
+ /// Whether the role is mentionable or not.
/// The options to be used when sending the request.
/// is null.
///
/// A task that represents the asynchronous creation operation. The task result contains the newly created
/// role.
///
- public Task CreateRoleAsync(Action func, RequestOptions options = null)
- => GuildHelper.CreateRoleAsync(this, Discord, func, options);
+ public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
+ bool isHoisted = false, bool isMentionable = false, RequestOptions options = null)
+ {
+ return await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false);
+ }
internal SocketRole AddRole(RoleModel model)
{
var role = SocketRole.Create(this, Discord.State, model);
@@ -1138,8 +1145,8 @@ namespace Discord.WebSocket
IRole IGuild.GetRole(ulong id)
=> GetRole(id);
///
- async Task IGuild.CreateRoleAsync(Action func, RequestOptions options)
- => await CreateRoleAsync(func, options).ConfigureAwait(false);
+ async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, bool isMentionable, RequestOptions options)
+ => await CreateRoleAsync(name, permissions, color, isHoisted, isMentionable, options).ConfigureAwait(false);
///
Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)