Answers for "how to code discord bot events random pictures"

1

how to code discord bot events random pictures

import discord
from discord.ext import commands
import aiohttp

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

@client.event
async def on_ready():
   print("Ready")

@client.command()
async def dog(ctx):
   async with aiohttp.ClientSession() as session:
      request = await session.get('https://some-random-api.ml/img/dog') # Make a request
      dogjson = await request.json() # Convert it to a JSON dictionary
   embed = discord.Embed(title="Doggo!", color=discord.Color.purple()) # Create embed
   embed.set_image(url=dogjson['link']) # Set the embed image to the value of the 'link' key
   await ctx.send(embed=embed) # Send the embed

client.run('token')
Posted by: Guest on September-09-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language