function has no attribute

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'

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

If you look at the traceback you’ll see where the error is coming from.
On line 12 in the function get_quote you have a problem with

json_data = json.loads(response.text)

The problem is that response is a function and functions do not have an attribute called text, so response.text is invalid.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.