Skip to content
Sign upLog in
← Back to Community
Jokes!
Profile icon
brynisaweeb

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

Voters
Profile icon
NedBrindley
Profile icon
IdhantOMG
Profile icon
Nettakrim
Profile icon
intriguing-
Profile icon
brynisaweeb
Comments
hotnewtop
Profile icon
adl212

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

import requests import json page = requests.get('https://official-joke-api.appspot.com/random_joke') jokesource = json.loads(page.content) joke = jokesource['setup'] print(joke) answer = jokesource['punchline'] print(answer)

Since this is a discord bot and you are using client, you are going to replace the print functions with await message.channel.send(#content). Upvote and choose this as the correct answer if it is!

Profile icon
rediar

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.

Profile icon
brynisaweeb

@rediar
Thanks ill do that c:

Profile icon
Coder100
Profile icon
ParthRangarajan

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