You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

RequireOwnerAttribute.cs 962 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using Discord;
  6. namespace Discord.Commands
  7. {
  8. /// <summary>
  9. /// Require that the command is invoked by the owner of the bot.
  10. /// </summary>
  11. /// <remarks>This precondition will only work if the bot is a bot account.</remarks>
  12. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  13. public class RequireOwnerAttribute : PreconditionAttribute
  14. {
  15. public override async Task<PreconditionResult> CheckPermissions(CommandContext context, CommandInfo command, IDependencyMap map)
  16. {
  17. var application = await context.Client.GetApplicationInfoAsync();
  18. if (context.User.Id == application.Owner.Id) return PreconditionResult.FromSuccess();
  19. return PreconditionResult.FromError("Command can only be run by the owner of the bot");
  20. }
  21. }
  22. }