How to return a different message from a selection (Reddit PY)
I'm making a Reddit bot. I want it to reply to a comment mentioning it's username with a random fact for a band I like, but it always returns the same one. See for yourself (here)[https://www.reddit.com/r/test/comments/p85e72/test_for_bot/].
Voters
KarmaIsADick
Oof, markdown fail. I didn't know how to a hyperlink!
SixBeeps
@bennyrobert Markdown syntax has brackets then parentheses. If you'd like you can edit the post to fix it ^^
You're only choosing a random number at the beginning of your code. From there on out, it doesn't pick another. There are a few ways of fixing this:
You could copy line 11 and lines 14-19 into the if statement between lines 24 and 25, which will pick a new fact with your current method.
A better solution would be to make a list of facts, then call the random class' choice() method on that list so that you don't have to make a bunch of if statements.
Thanks! Your second solution did the trick. Here is 5 cycles for you. @SixBeeps
@bennyrobert Neat, glad to hear I could help :)
Hey, I'm having the same issue again. In the console it does, but on Reddit it is the same fact every time.

@SixBeeps
@bennyrobert This one's easier to explain.
Here, you're saying
fact
is a list of all the facts contained in thefacts
file.Then, when you get to sending a message, you're sending the whole list.
Instead of sending
fact
, you should instead sendrandom.choice(fact)
.Thanks, but now I have this error:
I tried making it a global variable, but that didn't fix it.
@SixBeeps