【发布时间】:2021-09-06 16:57:59
【问题描述】:
我正在尝试向 discord bot 发出命令,该命令从该脚本中获取列表并从中随机发送一个。我大约一个月前在 Python 中启动了程序,所以这对我来说实际上很难。
问题是当我运行此脚本时出现错误:未关闭的客户端会话
client_session:
import asyncpraw
import asyncio
from aiohttp import ClientSession
async def get_meme(posses=100):
posts = []
async with ClientSession() as session:
async for subreddit in subreddits:
sub = await reddit.subreddit(subreddit).top(limit=posses, time_filter="week")
for post in sub:
await posts.append(post.url)
await session.close()
return posts
async def main():
task = asyncio.create_task(get_meme())
reddit_memes = await task
print(reddit_memes)
【问题讨论】:
标签: python python-3.x discord.py python-asyncio