public async Task PlayKonon([Remainder] double minutes = 5) { await _service.LeaveAudio(Context.Guild); try { await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState)?.VoiceChannel); } catch (NullReferenceException) { await Context.Channel.SendMessageAsync("You have to join the channel first!"); return; } catch { await Context.Channel.SendMessageAsync("There was a problem handling your request"); return; } //Debug version takes the parent folder, while release will take folder defined in dockerfile //TODO Move to service instead of cast each time #if DEBUG var kononDir = new DirectoryInfo(@"konon"); #else var kononDir = new DirectoryInfo(@"/app/konon"); #endif var files = kononDir.GetFiles(@"*.mp3"); await Context.Channel.SendMessageAsync("Mayor bot activated!"); while (true) { if (minutes >= 2 && minutes <= 15) { if (await _service.CheckIfConnectedToChannelAsync(Context.Channel, (Context.User as IVoiceState)?.VoiceChannel)) { var filename = files[_random.GetRandomValueFromZero(files.Length)].FullName; await _service.SendAudioAsync(Context.Guild, Context.Channel, $@"{filename}"); Thread.Sleep(_random.GetRangeValue(minutes * 60000)); } else { await _service.LeaveAudio(Context.Guild); break; } } } }