I'm asking like 500 600 years ago there must be some kind of comedy book or I don't know something that tells us how the comedy was in that period of time
This is a great question (or would be if it could be a bit more specific about date/place/people!) because humor is a notoriously tricky historical topic. Jokes are so deeply culturally and contextually defined that it can be near impossible to unravel them without "being there" yourself. Think of all the inside jokes your friends/family have that "you just had to be there for" but multiply the distance by centuries and continents and entire cultures.
Mary Beard opens her book Laughter in Ancient Rome: On Joking, Tickling, and Cracking Up, by exploring the question "can we ever really *get* jokes from the past?" She states baldly in her preface:
I have little patience with approaches that think they can explain and control the slippery phenomenon of laughter.
I'm inclined to agree. Therefore, this might not be a totally appropriate Ask Historians response, but since I'm not a specialist in historical humor, I think the best way for you to get the answer to your question is to simply read comedy from history.
Arguably the first collected book of "jokes" was The Facetiae from 1470 by Poggio Bracciolini (partial english translation in PDF form online here). It features fart jokes, which just goes to show that potty-humor and slapstick have seemingly always been sources of amusement.
Another book from roughly the time period you gesture toward that is deeply funny is Canterbury Tales by Chaucer. The tale of the Wife of Bath might be a good place to start looking for the humor until you start getting it.
Indeed, lots of books from the past are comedic; people are usually just afraid to laugh at them. Or they assume all works from the past are serious? I dare you to read the Satyricon by Petronius without laughing once you realize that it is pretty literally just the "Harold and Kumar Go To White Castle" of Roman literature.