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.

require_owner.cs 1.0 KiB

12345678910111213141516171819202122232425
  1. // (Note: This precondition is obsolete, it is recommended to use the
  2. // RequireOwnerAttribute that is bundled with Discord.Commands)
  3. using Discord.Commands;
  4. using Discord.WebSocket;
  5. using Microsoft.Extensions.DependencyInjection;
  6. using System;
  7. using System.Threading.Tasks;
  8. // Inherit from PreconditionAttribute
  9. public class RequireOwnerAttribute : PreconditionAttribute
  10. {
  11. // Override the CheckPermissions method
  12. public async override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
  13. {
  14. // Get the ID of the bot's owner
  15. var ownerId = (await services.GetService<DiscordSocketClient>().GetApplicationInfoAsync()).Owner.Id;
  16. // If this command was executed by that user, return a success
  17. if (context.User.Id == ownerId)
  18. return PreconditionResult.FromSuccess();
  19. // Since it wasn't, fail
  20. else
  21. return PreconditionResult.FromError("You must be the owner of the bot to run this command.");
  22. }
  23. }