There is no need for you to iterate over anything. Praw provides a method which allows you to grab a random submission from a subreddit.
Documentation: random()
Code:
@nd.listen()
async def on_message(message):
if message.author == nd.user:
return
def findCoindences(w):
return re.compile(r'\b({0})\b'.format(w)).search
content = message.content
reaction = "👍"
if findCoindences('meme')(content.lower()):
random_submission = reddit.subreddit('memes').random()
await message.reply(random_submission.url)
await message.add_reaction(f"<{reaction}>")
Note: I have move the random_submission inside the
If-statement
because there is no need for you to look up a submission if the message doesn’t say “meme”. It would just waste rate limit.