From fd6c1b57c5656accbdb774420bb052a7002557eb Mon Sep 17 00:00:00 2001
From: loicbersier <loic.bersier1@gmail.com>
Date: Tue, 24 Dec 2019 19:09:06 +0100
Subject: [PATCH] Loop until it found a threads

---
 commands/fun/4chan.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/commands/fun/4chan.js b/commands/fun/4chan.js
index e6a9d42a..c9502e81 100644
--- a/commands/fun/4chan.js
+++ b/commands/fun/4chan.js
@@ -44,6 +44,11 @@ class FourchanCommand extends Command {
 
 			i = Math.floor((Math.random() * response.threads.length) + 1);
 
+			// Loop until it found a threads
+			while(!response.threads[i]) {
+				i = Math.floor((Math.random() * response.threads.length) + 1);
+			}
+
 			// If post is sticky search again
 			while(response.threads[i].posts[0].sticky == 1 || !response.threads[i].posts) {
 				i = Math.floor((Math.random() * response.threads.length));