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.

logging.cs 617 B

123456789101112131415161718192021222324
  1. using Discord;
  2. using Discord.WebSocket;
  3. public class LoggingService
  4. {
  5. public LoggingService(DiscordSocketClient client, CommandService command)
  6. {
  7. client.Log += LogAsync;
  8. command.Log += LogAsync;
  9. }
  10. private Task LogAsync(LogMessage message)
  11. {
  12. if (message.Exception is CommandException cmdException)
  13. {
  14. Console.WriteLine($"[Command/{message.Severity}] {cmdException.Command.Aliases.First()}"
  15. + $" failed to execute in {cmdException.Context.Channel}.");
  16. Console.WriteLine(cmdException);
  17. }
  18. else
  19. Console.WriteLine($"[General/{message.Severity}] {message}");
  20. return Task.CompletedTask;
  21. }
  22. }