Exemple #1
0
        private static void ManageException(DiscordMessage message, DiscordUser author, DiscordChannel channel, Exception ex, DiscordCommand command)
        {
            _appLogArea.WriteLine($"\n --- Something's f****d up! --- \n{ex.ToString()}\n");
            TelemetryClient?.TrackException(ex, new Dictionary <string, string> {
                { "command", command.GetType().Name }
            });

            if (!(ex is TaskCanceledException) && !(ex is OperationCanceledException))
            {
                if (_ownerDm != null)
                {
                    try
                    {
                        _ownerDm.SendMessageAsync($"An {ex.GetType().Name} has occured processing command \"{command.Name}\" in {channel.Mention}{(channel.Guild != null ? $" ({channel.Guild.Name})" : "")}");
                        _ownerDm.SendMessageAsync($"```\r\n" +
                                                  $"{ex.ToString()}" +
                                                  $"```");
                        _ownerDm.SendMessageAsync($"Message content: `{message.Content}`");
                        _ownerDm.SendMessageAsync($"Message author:  {author.Mention}");
                    }
                    catch { }
                }

                new Task(async() =>
                {
                    try
                    {
                        DiscordMessage msg = await channel.SendMessageAsync(
                            $"Something's gone very wrong executing that command, and an {ex.GetType().Name} occured." +
                            $"{(_ownerDm != null ? "\r\nThis error has been reported, and should be fixed soon:tm:!" : "")}" +
                            $"\r\nThis message will be deleted in 10 seconds.");

                        await Task.Delay(10_000);
                        await msg.DeleteAsync();
                    }
                    catch { }
                }).Start();
            }
        }