public async Task RevokeHostRolesAsync(ulong userId) { DiscordGuild guild = await _guildProvider.GetCurrentGuildAsync(); DiscordMember member = await guild.GetMemberAsync(userId); // TODO: somehow merge with Revoke part later. foreach (ulong roleId in _roleConfig.HostRoleIds) { try { DRole role = guild.GetRole(roleId); await member.RevokeRoleAsync(role); } catch (Exception e) { _logger.LogError(e, "Revoking host role '{RoleId}' failed", roleId); } } }
/// <summary> /// Adds a channel permission overwrite for specified role. /// </summary> /// <param name="role"></param> /// <param name="allow"></param> /// <param name="deny"></param> /// <param name="reason">Reason for audit logs.</param> /// <returns></returns> public Task AddOverwriteAsync(DiscordRole role, Permissions allow = Permissions.None, Permissions deny = Permissions.None, string reason = null) => this.Discord.ApiClient.EditChannelPermissionsAsync(this.Id, role.Id, allow, deny, "role", reason);
/// <summary> /// Revokes a role from a member. /// </summary> /// <param name="role">Role to revoke.</param> /// <param name="reason">Reason for audit logs.</param> /// <returns></returns> public Task RevokeRoleAsync(DiscordRole role, string reason = null) => this.Discord.ApiClient.RemoveGuildMemberRoleAsync(this.Guild.Id, this.Id, role.Id, reason);
/// <summary> /// Grants a role to the member. /// </summary> /// <param name="role">Role to grant.</param> /// <param name="reason">Reason for audit logs.</param> /// <returns></returns> public Task GrantRoleAsync(DiscordRole role, string reason = null) => this.Discord.ApiClient.AddGuildMemberRoleAsync(this.Guild.Id, this.Id, role.Id, reason);
/// <summary> /// Sets the role to which this overwrite applies. /// </summary> /// <param name="role">Role to which apply this overwrite's permissions.</param> /// <returns>This builder.</returns> public DiscordOverwriteBuilder For(DiscordRole role) { this.Target = role; this.Type = OverwriteType.Role; return(this); }
/// <summary> /// Allows the specific role to be mentioned /// </summary> /// <param name="role"></param> public RoleMention(DiscordRole role) : this(role.Id) { }
/// <summary> /// Creates a new Discord permission overwrite builder for a role. This class can be used to construct permission overwrites for guild channels, used when creating channels. /// </summary> public DiscordOverwriteBuilder(DiscordRole role) { this.Target = role; this.Type = OverwriteType.Role; }
/// <summary> /// Represents a permission for a application command. /// </summary> /// <param name="role">The role to contruct the permission for.</param> /// <param name="permission">Whether the command should be enabled for the role.</param> public DiscordApplicationCommandPermission(DiscordRole role, bool permission) { this.Id = role.Id; this.Type = ApplicationCommandPermissionType.Role; this.Permission = permission; }