def render(url, width=1024, max_height=4096, trim_image=False):
with DefaultClientSession(connector=TCPConnector()) as session:
async with session.request(method="post", url=render_url(), data=json.dumps({
"url": url,
"key": api_key(),
"width": str(width),
"max_height": str(max_height),
"trim": "true" if trim_image else "false",
})) as r:
if r.status == 200:
buffer = io.BytesIO()
buffer.write(await r.read())
return Response("", attachments=[MemoryAttachment(buffer, "screenshot.jpg", "image/jpeg")])
else:
try:
data = await r.json()
raise CommandError("error occurred: {}".format(data['error']))
except JSONDecodeError:
raise CommandError("error occurred with status code {}".format(r.status))
评论列表
文章目录