DEV Community

Discussion on: discord.py project 3: Random Dog Pics! ๐Ÿ•

Collapse
 
wasian1 profile image
Wasian1

Hi, I'm trying to apply your methodology but with a different API. The key for mine is different (url) and I'm wondering if this might be affecting why my bot won't send the image when I input the command. I've attached my current code below. Please let me know if you can assist and thank you for the post! Code done in Replit

import discord
import os
from discord.ext import commands
import aiohttp

client = discord.Client()

client = commands.Bot(command_prefix="$")

@client.command()
async def waifu(ctx):
async with aiohttp.ClientSession() as session:
request = await session.get('api.waifu.pics/sfw/waifu') # Make a request
waifujson = await request.json() # Convert it to a JSON dictionary
embed = discord.Embed(title="Yabei", color=discord.Color.random()) # Create embed
embed.set_image(url=waifujson['url']) # Set the embed image to the value of the 'link' key
await ctx.send(embed=embed) # Send the embed

@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))

client.run(os.getenv('TOKEN'))