I am making a Reddit bot (pretty much irrelevant.), and I am trying to check if the text: [submission]
is in the title of any submission in a Subreddit.
Here is my code: (I have all of the tokens and secrets and things already set, along with a subreddit.)
for submission in reddit.subreddit("MinecraftCommandJam").new():
lowercaseT = str(submission.title()).lower()
if '[submission]' in lowercaseT:
print(submission.title)
But when I run the code, this error occurs (python 3)
Traceback (most recent call last):
File "c:\Users\hjdom\reddit_bot_mcj\reddit_bot.py", line 42, in <module>
lowercaseT = str(submission.title()).lower()
TypeError: 'str' object is not callable
PS C:\Users\hjdom\reddit_bot_mcj>
Please, always provide a minimal, reproducible example so that we can copy-paste-tweak your code and help you.
By googling a bit, I found that praw.models.Submission
objects have a .title
attribute, a str
. So the error TypeError: 'str' object is not callable
is not caused by calling .lower()
, but by submission.title()
instead.
Since submission.title
is already a str
, this should work:
for submission in reddit.subreddit("MinecraftCommandJam").new():
lowercaseT = submission.title.lower()
if '[submission]' in lowercaseT:
print(submission.title)