Updated meme to no longer use requests when saving images.

This commit is contained in:
phixxy 2023-07-25 17:07:53 -07:00
parent 2568d67c5f
commit f2419c5501

View file

@ -3,7 +3,6 @@ from discord.ext import commands, tasks
from discord.utils import get from discord.utils import get
import shutil import shutil
import json import json
import requests
import random import random
import time import time
import os import os
@ -674,13 +673,16 @@ async def meme(ctx):
try: try:
#------------------------------------Saving Image Using Requests---------------------------------# #------------------------------------Saving Image Using Requests---------------------------------#
filename = memepics[id-1]['name'] filename = memepics[id-1]['name']
response = requests.get(f"{response['data']['url']}") async with bot.http_session.get(image_link) as response:
folder = "tmp/" folder = "tmp/"
filename = folder + topic + str(len(os.listdir(folder))) + ".jpg" filename = folder + topic + str(len(os.listdir(folder))) + ".jpg"
file = open(filename, "wb")
file.write(response.content) with open(filename, "wb") as file:
file.close() while True:
print("Meme was Saved Successfuly") chunk = await response.content.read(1024) # Read the response in chunks
if not chunk:
break
file.write(chunk)
except Exception as error: except Exception as error:
await handle_error(error) await handle_error(error)
print("Something's Wrong with the urllib So try again") print("Something's Wrong with the urllib So try again")