Trying to retrieve killing gifs from api

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

@ -167,29 +167,34 @@ 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
# Open the file containing the killing gifs search_term = "anime-kill"
with open('images/FunCommands/killing.txt') as file: url = f"https://api.tenor.com/v1/random?q={search_term}&key={apikey}&limit=1&media_filter=minimal"
# Store content of the file in killing_array
killing_array = file.readlines()
# Get the member and the userAvatar # get random results using default locale of EN_US
member, userAvatar = getMember(ctx) # Searching API for the current airing shows
async with aiohttp.ClientSession() as session:
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!**")
# Set up the embed to display a random killing gif # Get the member and the userAvatar
embed = Embed( member, userAvatar = getMember(ctx)
title=title,
colour=self.bot.random_colour(),
timestamp=datetime.datetime.utcnow())
embed.set_image(url=random.choice(killing_array))
embed.set_footer(text=f"Requested by {member}", icon_url=userAvatar)
# Send the embedded message to the user # Set up the embed to display a random killing gif
await ctx.send(embed=embed) embed = Embed(
title=title,
colour=self.bot.random_colour(),
timestamp=datetime.datetime.utcnow())
embed.set_image(url=url)
embed.set_footer(text=f"Requested by {member}", icon_url=userAvatar)
except FileNotFoundError as e: # Send the embedded message to the user
print(e) await ctx.send(embed=embed)
@command(name="slap") @command(name="slap")
@bot_has_permissions(embed_links=True) @bot_has_permissions(embed_links=True)

Loading…
Cancel
Save