I was watching the tutorial about developing a discord bot with python. At the 27th minute I started to get an error. I searched a lot but I couldn’t find a solution. Please help me to understand the situation here.
My Code is:
import discord
import os
import json
import requests
client = discord.Client()
def get_quote():
response = requests.get
("https://zenquotes.io/api/random")
json_data = json.loads(response.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))
get_quote()
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$inspire'):
quote = get_quote()
await message.channel.send(quote)
@client.event
async def on_member_joined(member):
print(f'{member} has joined to the server')
@client.event
async def on_member_removed(member):
print(f'{member} has left the server')
client.run(os.getenv('TOKEN'))
And the error code is:
We have logged in as Oath Keeper#5185
Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 20, in on_ready
get_quote()
File "main.py", line 12, in get_quote
json_data = json.loads(response.text)
AttributeError: 'function' object has no attribute 'text'