I recently created a meme bot, similar to DankMemer. When I run this:
@client.event
async def on_message(message):
if message.author.bot:
return
if '!meme' in message.content:
await message.channel.purge(limit=1)
memes_submissions = reddit.subreddit('memes').hot()
post_to_pick = random.randint(1, 10)
for i in range(0, post_to_pick):
submission = next(x for x in memes_submissions if not x.stickied)
embed = discord.Embed(title=submission.title)
embed.set_image(url=submission.url)
await message.channel.send(embed=embed)
This error appears:
C:/Users/HP/PycharmProjects/Nudity/main.py:28: RuntimeWarning: coroutine 'SubredditHelper.__call__' was never awaited
memes_submissions = reddit.subreddit('memes').hot()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\HP\PycharmProjects\Nudity\venv\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:/Users/HP/PycharmProjects/Nudity/main.py", line 28, in on_message
memes_submissions = reddit.subreddit('memes').hot()
AttributeError: 'coroutine' object has no attribute 'hot'
How can I fix this? (Also, I know I could use @client.command but I prefer the Event one)
I'm going to assume you Async PRAW, since PRAW does not use coroutines.
All of Async PRAW's methods are coroutines, and you need to await
each one.
Since .subreddit()
is a coroutine, you need to await .subreddit()
, and then call .hot()
once it's resolved.
Here is what should be a working example:
meme_subreddit = await reddit.subreddit('memes')
memes_submissions = meme_subreddit.hot()