How to show the url of an image with python discord bot?
Question:
I am creating a small bot in Python, but I have a small problem and I want it to show me the image as a link and I don’t know how to do it.
This is the code I am currently using:
with io.BytesIO() as image_binary:
img1.save(image_binary, 'PNG')
image_binary.seek(0)
embed=discord.Embed(title="Skin Minecraft", url="https://twitter.com/", description=f"", color=discord.Colour.random())
embed.set_image(url=f"attachment://Skin-{usuariominecraft}.png")
await ctx.send(embed=embed, file=discord.File(fp=image_binary, filename=f"Skin-{usuariominecraft}.png"))
What I want is for it to show me the link directly, like this:
https://cdn.discordapp.com/attachments/1050554950377295932/1051229055581700216/Skin-TCGBayQ.png
I can’t get how to do it.
Is it possible to do this?
Answers:
I leave you what I could do…
import import base64
import requests
Code:
nombre_local_imagen = f"Skin-Minecraft.png"
imagen = requests.get(f"{SkinMc}").content
with open(f"{nombre_local_imagen}", "wb") as handler:
handler.write(imagen)
embed=discord.Embed(title="Skin Minecraft", url="https://twitter.com/", description=f"", color=discord.Colour.random())
file = discord.File(f"Skin-Minecraft.png", filename=f"Skin-Minecraft.png")
embed.set_image(url=f"attachment://Skin-Minecraft.png")
embed.set_footer(text=f"TEXTO")
await ctx.send(file=file, embed=embed)
headers = {'Authorization': 'Client-ID XxXx',} #get client_ID => https://api.imgur.com/oauth2/addclient
params = {'image': base64.b64encode(open(f'Skin-Minecraft.png', 'rb').read())}
r = requests.post(f'https://api.imgur.com/3/image', headers=headers, data=params)
data = r.json()["data"]["link"]
await ctx.channel.send(f"```{data}```")
Hope this can help you
I am creating a small bot in Python, but I have a small problem and I want it to show me the image as a link and I don’t know how to do it.
This is the code I am currently using:
with io.BytesIO() as image_binary:
img1.save(image_binary, 'PNG')
image_binary.seek(0)
embed=discord.Embed(title="Skin Minecraft", url="https://twitter.com/", description=f"", color=discord.Colour.random())
embed.set_image(url=f"attachment://Skin-{usuariominecraft}.png")
await ctx.send(embed=embed, file=discord.File(fp=image_binary, filename=f"Skin-{usuariominecraft}.png"))
What I want is for it to show me the link directly, like this:
https://cdn.discordapp.com/attachments/1050554950377295932/1051229055581700216/Skin-TCGBayQ.png
I can’t get how to do it.
Is it possible to do this?
I leave you what I could do…
import import base64
import requests
Code:
nombre_local_imagen = f"Skin-Minecraft.png"
imagen = requests.get(f"{SkinMc}").content
with open(f"{nombre_local_imagen}", "wb") as handler:
handler.write(imagen)
embed=discord.Embed(title="Skin Minecraft", url="https://twitter.com/", description=f"", color=discord.Colour.random())
file = discord.File(f"Skin-Minecraft.png", filename=f"Skin-Minecraft.png")
embed.set_image(url=f"attachment://Skin-Minecraft.png")
embed.set_footer(text=f"TEXTO")
await ctx.send(file=file, embed=embed)
headers = {'Authorization': 'Client-ID XxXx',} #get client_ID => https://api.imgur.com/oauth2/addclient
params = {'image': base64.b64encode(open(f'Skin-Minecraft.png', 'rb').read())}
r = requests.post(f'https://api.imgur.com/3/image', headers=headers, data=params)
data = r.json()["data"]["link"]
await ctx.channel.send(f"```{data}```")
Hope this can help you