Skip to content

Instantly share code, notes, and snippets.

@Joe4evr
Created May 25, 2017 09:30
Show Gist options
  • Save Joe4evr/275fdadc4848ba9755ae0e8d1e022920 to your computer and use it in GitHub Desktop.
Save Joe4evr/275fdadc4848ba9755ae0e8d1e022920 to your computer and use it in GitHub Desktop.
Example of how to make a logical OR of multiple preconditions
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class RequireAdminOrOwnerAttribute : PreconditionAttribute
{
private readonly RequireOwnerAttribute _owner = new RequireOwnerAttribute();
private readonly RequireUserPermissionAttribute _admins = new RequireUserPermissionAttribute(GuildPermission.Administrator);
public override async Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
{
var isAdmin = await _admins.CheckPermissions(context, command, services);
var isOwner = await _owner.CheckPermissions(context, command, services);
return (isAdmin.IsSuccess || isOwner.IsSuccess)
? PreconditionResult.FromSuccess()
: PreconditionResult.FromError("Need to be admin or bot owner");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment