Ask coding questions

← Back to all posts
8ryn8ryn (2)

Does anyone know how to add a API or something so it can print a random joke. c:

adl212 (166)

@8ryn8ryn you can use this code to get random jokes and their answers.

import requests
import json
page = requests.get('')
jokesource = json.loads(page.content)
joke = jokesource['setup']
answer = jokesource['punchline']

Since this is a discord bot and you are using client, you are going to replace the print functions with await Upvote and choose this as the correct answer if it is!

rediar (499)

search up "joke api" if there isnt one, you can consider webscraping, however if thats too advanced just put your own jokes in an array, and write a function to randomly select one.

8ryn8ryn (2)

@rediar Thanks ill do that c:

ParthRangarajan (0)

Hey could you help with that?
I'm having a tough time navigate through the json although the documentation is pretty [email protected]