I followed the FreeCodeCamp Code a Discord Bot with Python but the bot doesn’t seem to be working and as a beginner I didn’t understand about the API and what to do if we want to use something else like facts.
MY CODE
import os
import discord
import requests
import json
client = discord.Client()
def get_quote():
responce = requests.get ("https://zenquotes.io/api/random")
json_data = json.load(responce.text)
quote = json_data[0]["q"] + " -" + json_data[0]["a"]
return(quote)
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$quote'):
quote = get_quote()
await message.channel.send(quote)
client.run(os.getenv('TOKEN'))
And if we want the bot to respond to some other command do we make a new file for it because it doesn’t seem to work in the same file for me. @jwilkins.oboe Can you help me out?
What did beau name it in the tutorial?
What error messages are you getting?
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.