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

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