Reputation: 55
I want to make my bot send a random image from a subreddit (r/memes). Here's what I have:
@client.event
async def on_message(message):
if message.content.startswith('.meme'):
memes_submissions = reddit.subreddit('memes').hot()
post_to_pick = random.randint(1, 50)
for i in range(0, post_to_pick):
submission = next(x for x in memes_submissions if not x.stickied)
await bot.say(submission.url)
It doesn't seem to be working, any tips?
Upvotes: 0
Views: 97
Reputation: 1173
bot.say
was removed in discord.py 1.0 and replaced with .send
.
So the line await bot.say(submission.url)
should be replaced with
await message.channel.send(submission.url)
https://discordpy.readthedocs.io/en/latest/migrating.html?highlight=say#removed-helpers
In your for loop you recreate the list of non-sticked post each time and then call next but because you recreate it will always return first element of recreated list. You should move the x for x in memes_submissions if not x.stickied
out of the loop into a varible. You could then user next
but easier would be just to index that variable like it is a list with the random number.
Upvotes: 1