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);
                }
            }
        }
Example #2
0
 /// <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);
Example #3
0
 /// <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);
Example #4
0
 /// <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);
Example #5
0
 /// <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);
 }
Example #6
0
 /// <summary>
 /// Allows the specific role to be mentioned
 /// </summary>
 /// <param name="role"></param>
 public RoleMention(DiscordRole role) : this(role.Id)
 {
 }
Example #7
0
 /// <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;
 }
Example #8
0
 /// <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;
 }