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.

DiscordBotClient.Events.cs 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Discord.Commands;
  2. using System;
  3. namespace Discord
  4. {
  5. public partial class DiscordBotClient : DiscordClient
  6. {
  7. public class PermissionException : Exception { public PermissionException() : base("User does not have permission to run this command.") { } }
  8. public class CommandEventArgs
  9. {
  10. public Message Message { get; }
  11. public Command Command { get; }
  12. public string CommandText { get; }
  13. public int? Permissions { get; }
  14. public string[] Args { get; }
  15. public User User => Message.User;
  16. public string UserId => Message.UserId;
  17. public Channel Channel => Message.Channel;
  18. public string ChannelId => Message.ChannelId;
  19. public Server Server => Message.Channel.Server;
  20. public string ServerId => Message.Channel.ServerId;
  21. public CommandEventArgs(Message message, Command command, string commandText, int? permissions, string[] args)
  22. {
  23. Message = message;
  24. Command = command;
  25. CommandText = commandText;
  26. Permissions = permissions;
  27. Args = args;
  28. }
  29. }
  30. public class CommandErrorEventArgs : CommandEventArgs
  31. {
  32. public Exception Exception { get; }
  33. public CommandErrorEventArgs(CommandEventArgs baseArgs, Exception ex)
  34. : base(baseArgs.Message, baseArgs.Command, baseArgs.CommandText, baseArgs.Permissions, baseArgs.Args)
  35. {
  36. Exception = ex;
  37. }
  38. }
  39. public event EventHandler<CommandEventArgs> RanCommand;
  40. private void RaiseRanCommand(CommandEventArgs args)
  41. {
  42. if (RanCommand != null)
  43. RanCommand(this, args);
  44. }
  45. public event EventHandler<CommandEventArgs> UnknownCommand;
  46. private void RaiseUnknownCommand(CommandEventArgs args)
  47. {
  48. if (UnknownCommand != null)
  49. UnknownCommand(this, args);
  50. }
  51. public event EventHandler<CommandErrorEventArgs> CommandError;
  52. private void RaiseCommandError(CommandEventArgs args, Exception ex)
  53. {
  54. if (CommandError != null)
  55. CommandError(this, new CommandErrorEventArgs(args, ex));
  56. }
  57. }
  58. }