Python discord.py/PRAW:AttributeError:&x27;协同程序';对象没有属性';热的';

Python discord.py/PRAW:AttributeError:&x27;协同程序';对象没有属性';热的';,python,discord,discord.py,reddit,praw,Python,Discord,Discord.py,Reddit,Praw,我最近创建了一个模因机器人,类似于DankMemer。当我运行此命令时: @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.subredd

我最近创建了一个模因机器人,类似于DankMemer。当我运行此命令时:

    @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)
出现以下错误:

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'
我怎样才能解决这个问题?
(另外,我知道我可以使用@client.command,但我更喜欢事件一)

您需要等待函数:

subreddit=wait reddit.subreddit('memes'))
memes_submissions=subreddit.hot()
你可能需要用括号把右边的东西括起来,我不记得了


编辑-抱歉,我没有测试它…

我假设您是异步PRAW,因为PRAW不使用协同路由

所有的方法都是协程,您需要等待每个方法

由于
.subreddit()
是一个协同程序,您需要等待
.subreddit()
,然后在解析后调用
.hot()

以下是一个工作示例:

meme\u subreddit=等待reddit.subreddit('memes'))
memes_submissions=meme_subreddit.hot()

他需要等待
.subreddit()
,而不是
.hot()
这成功了,谢谢!