Discord.py - ASYNCPRAW 优化
有什么办法可以优化这段代码吗?只是响应时间太长:
@bot.command()
async def picture(ctx, name=None):
pic_submission = await reddit.subreddit("Genshin_Impact")
if name is None:
submission = random.choice([i async for i in pic_submission.hot(params={'include_over_18': 'on'},
limit=100)])
else:
submission = random.choice([i async for i in nsfw_submission.search(f"{name}", sort="hot",
params={'include_over_18': 'on'},
limit=100)])
url = submission.url
title = submission.title
embed = discord.Embed(title=f'__{title}__', colour=discord.Colour.light_gray(),
timestamp=ctx.message.created_at, url=url)
embed.set_image(url=url)
await ctx.send(embed=embed)
Is there any way to optimize this code? It just takes tooo long to response:
@bot.command()
async def picture(ctx, name=None):
pic_submission = await reddit.subreddit("Genshin_Impact")
if name is None:
submission = random.choice([i async for i in pic_submission.hot(params={'include_over_18': 'on'},
limit=100)])
else:
submission = random.choice([i async for i in nsfw_submission.search(f"{name}", sort="hot",
params={'include_over_18': 'on'},
limit=100)])
url = submission.url
title = submission.title
embed = discord.Embed(title=f'__{title}__', colour=discord.Colour.light_gray(),
timestamp=ctx.message.created_at, url=url)
embed.set_image(url=url)
await ctx.send(embed=embed)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我注意到限制是100!由于您的程序会迭代 100 个帖子,因此需要很长时间才能回复,因此请尝试降低限制!
I noticed that the limit is 100! It takes long to respond because your program iterates through 100 posts so try lowering the limit!