Trying to retrieve killing gifs from api

pull/8/head
sgoudham 4 years ago
parent a11402ac8e
commit 0e2f256f8c

@ -167,12 +167,20 @@ class Interactive(Cog):
else: else:
title = f":scream: :scream: | **{ctx.author.display_name}** killed **{member.display_name}**" title = f":scream: :scream: | **{ctx.author.display_name}** killed **{member.display_name}**"
try: # Set details for search
apikey = config("TENOR_AUTH") # test value
search_term = "anime-kill"
url = f"https://api.tenor.com/v1/random?q={search_term}&key={apikey}&limit=1&media_filter=minimal"
# Open the file containing the killing gifs # get random results using default locale of EN_US
with open('images/FunCommands/killing.txt') as file: # Searching API for the current airing shows
# Store content of the file in killing_array async with aiohttp.ClientSession() as session:
killing_array = file.readlines() async with session.get(url) as resp:
if resp.status == 200:
gifs = await resp.json()
url = gifs["results"][0]["media"][0]["gif"]["url"]
else:
self.bot.generate_embed(ctx, desc="**Something Went Wrong With Tenor!**")
# Get the member and the userAvatar # Get the member and the userAvatar
member, userAvatar = getMember(ctx) member, userAvatar = getMember(ctx)
@ -182,15 +190,12 @@ class Interactive(Cog):
title=title, title=title,
colour=self.bot.random_colour(), colour=self.bot.random_colour(),
timestamp=datetime.datetime.utcnow()) timestamp=datetime.datetime.utcnow())
embed.set_image(url=random.choice(killing_array)) embed.set_image(url=url)
embed.set_footer(text=f"Requested by {member}", icon_url=userAvatar) embed.set_footer(text=f"Requested by {member}", icon_url=userAvatar)
# Send the embedded message to the user # Send the embedded message to the user
await ctx.send(embed=embed) await ctx.send(embed=embed)
except FileNotFoundError as e:
print(e)
@command(name="slap") @command(name="slap")
@bot_has_permissions(embed_links=True) @bot_has_permissions(embed_links=True)
@cooldown(1, 3, BucketType.user) @cooldown(1, 3, BucketType.user)

Loading…
Cancel
Save