简体   繁体   中英

Why do I get this following error in python(discord bot): TypeError: 'str' object is not callable

I'm currently writing a discord bot and I can't seem to understand why the str object is not callable. response.text is grabbing the content provided from an api

answer=response.text()
print("user balance"+answer)
msg=answer.format(message)

Error I get

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Boss\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "c:/Users/Boss/Desktop/python/lol.py", line 28, in on_message
    answer=response.text()
TypeError: 'str' object is not callable

string object is not callable means text is a string and thus not callable.

So just remove the brackets:

answer = response.text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM