From my understanding I can use this example from the GIPHY docs (https://gyazo.com/1b6c0094162a54fe49029f665badf8df) to open a url but I don't understand it too much. To add onto that, when I run this code I get the error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'urllib' has no attribute 'urlopen'
My question is how can I randomly import a GIF from certain tags once the user types #giphy in a text channel
Here is my current code: (Code got updated)
@bot.command(pass_context = True)
@commands.cooldown(1, 3, commands.BucketType.user)
async def gif(ctx, *, search):
channel = ctx.message.channel
session = aiohttp.ClientSession()
msg = await bot.send_message(channel, "**searching for " + search + "..**")
randomMessage = await bot.send_message(channel, "**showing a random image due to no images found from your search or you just didn't search anything**")
if search == "":
randomImage = True
print("random")
randomMessage
response = await session.get("https://api.giphy.com/v1/gif/random?api_keyY=4hnrG09EqYcNnv63Sj2gJvmy9ilDPx5&limit=10")
else:
msg
print("searching")
correct_search = search.replace(" ", "+")
reponse = await session.get("http://api.giphy.com/v1/gifs/search?q=" + correct_search + "&api_key=Y4hnrG09EqYcNnv63Sj2gJvmy9ilDPx5&limit=10")
data = json.loads(await reponse.text())
await session.close()
embed = discord.Embed(
description = '**showing result for ' + search + '**',
colour = discord.Colour.blue()
)
gif_choice = random.randint(0,9)
embed.set_image(url=data["data"][gif_choice]["images"]["original"]["url"])
if randomImage:
await bot.delete_message(randomMessage)
else:
await bot.delete_message(msg)
await bot.send_message(channel, embed=embed)
Thank you