Attaching local thumbnail to Discord Embed - discord

I've tried everything, and nothing is working. How would I attach a local thumbnail in Discord? The image is inside the images directory
msg.py:
embed = discord.Embed(title="Game Started", description=body)
embed.add_field(name=captain1, value=', '.join(team_one), inline=False)
embed.add_field(name=captain2, value=', '.join(team_two))
embed.set_thumbnail(url=f"attachment://images/elite.png")
await ctx.send(embed=embed)
The thumbnail is not showing

You have to send the file as well
The url in set_thumbnail should just be attachment://{FILENAME}, without the actual path since it refers to the attachment of the message
file = discord.File("images/elite.png")
embed = discord.Embed(title="Game Started", description=body)
embed.add_field(name=captain1, value=', '.join(team_one), inline=False)
embed.add_field(name=captain2, value=', '.join(team_two))
embed.set_thumbnail(url=f"attachment://{file.filename}") # you could just do `attachment://elite.png`, but this is a more "procedural" way
await ctx.send(embed=embed, file=file)

Related

Discord.js v12 image in message embed

I would like to make a vouch system but with images, when they take screenshot with lightshot to copy the image and paste it to discord chat and when it's been sent, bot will upload it in embed.
My current attempt:
client.on("message", message => {
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (message.channel.id == `912767631344423032`) { //Channel ID
if (message.author.bot) return;
message.delete();
const vch = new Discord.MessageEmbed()
.setTitle(`Feedback`)
.setColor("#F3950D")
.setDescription(`<a:bluefire:911708697988845569> Vouched By:\n**${message.author.tag}**`)
.setThumbnail("https://cdn.discordapp.com/icons/911530458637033514/a_d62f915")
.setImage(`${message.content}`)
.setFooter("Created and Developed by Tana#6969 ❤️")
message.channel.send(vch)
}
});
What does it do now? Like you haven't shown any errors or any parts where we can see the problem is at.
Message.content relates to the message content (text), if no message content (text) is sent it will result into null. You would need to get the image from the attachment option. https://discord.js.org/#/docs/main/v12/class/Message?scrollTo=attachments
There is a lot of ways of doing this, you can go to google and look for a picture that suits you, then right-click it and click "Copy image link" or something similar, or you can do the same but on discord, by sending the image you want then opening it then right-clicking it then choose "Copy image link" or something similar.

dropbox-api get_thumbnail_v2 & get_thumbnail returns question marks(?) inside rhombs ()

I am trying to use DropBox API to get a thumbnail from DropBox and show them on Lightning Web Component in Salesforce, but can not do it because in a response Apex receiving body with black rhombs and question marks inside.
I use standard HTTP method to call
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer sl.validToken');
req.setHeader('Dropbox-API-Arg', '{"resource": {".tag": "path","path": "/folderName/pictureName.jpg"},"format": "jpeg","size": "w64h64","mode": "strict"}');
req.setHeader('Content-Type', 'text/plain; charset=utf-8');
req.setEndpoint('https://content.dropboxapi.com/2/files/get_thumbnail_v2');
req.setMethod('POST');
Http httpreq = new Http();
HttpResponse res = httpreq.send(req);
this is what I receive in body of response in Apex. The same response I have in Postman.
https://i.stack.imgur.com/90yjI.png
This is what I have in DropBox explorer with same values and headers (JSON)
https://i.stack.imgur.com/ytDxv.png
File scope is Read to everyone. SF Remote Site Settings & CSP Trusted Sites are set.
Short update:
I`ve been able to get JSON From header. I did use that piece of code:
List<String> headers = new List<String>(res.getHeaderKeys());
for(String key : headers){
System.debug('key ->>> '+key+' = '+res.getHeader(key));
}
String jsonString = res.getHeader('Dropbox-Api-Result');
System.debug('->>>ddd '+jsonString);
But still do not understand how to use it as a thumbnail in LWC.
Thank you in advance for your help.
The /2/files/get_thumbnail_v2 Dropbox API endpoint is a "content-download" style endpoint, meaning the "response body contains file content, so the result will appear as JSON in the Dropbox-API-Result response header". So, the illegible value you're receiving is the actual bytes of the thumbnail data itself. You're currently attempting to display it as text, but you'll instead need to save and display it as an image to see the thumbnail. Refer to your platform's documentation for information on how to display an image.
For reference, the Dropbox API v2 Explorer is built with knowledge of the different endpoint formats, so in this case it displays the metadata from the Dropbox-API-Result response header, and just offers the file data, in this case the thumbnail data, as a download via a "Download" button.

Discordpy, Praw, get img preview of a link or if there isn't a link and there's an img attached, embed that one

I'm using discordpy and the Praw module to access Reddit. I was wondering how I send the image preview of an article that is attached to the reddit submission, or, if there is no reddit link and there's instead an image attached, how I send that.
This is my current code:
#client.command()
#cooldown(1, 5, BucketType.user) #Command can only be used once every 5 seconds
async def webdev(ctx):
subreddit = reddit.subreddit("webdev") #Subreddit name
all_subs = []
hot = subreddit.hot(limit = 100)
for submission in hot: #Iterating through the submissions in hot
all_subs.append(submission) #Appending the submissions to the all_subs variable list
random_sub = random.choice(all_subs) #Using the random module to randomly select one
name = random_sub.title #Title of the submission
body = random_sub.selftext #Body text of the submission
link = random_sub.shortlink #Link to the submission
url = random_sub.url #image of the submission
img = random_sub.thumbnail #thumbnail of an exterior link (if there is one)
em = discord.Embed(title = name) #Creating discordpy embed
em.description = body #Setting the descriptiong to the body variable
em.set_image(url = url) or em.set_image(url = img) #Attempting to send either the image attachment, or a link preview image
em.add_field(name = f"Link to post:", value = link, inline= False) #Adding the submission link
await ctx.send(embed = em) #Sending the embed
Thank you
In order for you to send the image, it got to be hosted somewhere. With your Discord bot, you can either send an image from a link or an image that is locally hosted with your bot.
You can send the image with the link like you did with your code. Otherwise, you will have to save the image on your host then send it from there.
To save your image on your host, you can use PIL module. Convert the image that you get into a savable file, then use img.save("name.png") then you can use: file = discord.File("name.png") to get the image then use it with set_image() after that, you just have to send the embed this way: await ctx.send(embed = em, file = file)

How can I send an image from an API from a Discord bot?

For context, this Discord bot gets a players displayname from the Hypixel API. It then uses the displayname to get an image from the Plancke API: gen.plancke.io/exp/${player.displayname}.png
I have been looking for ways of sending this image to a channel and I have found this way of doing it.
message.channel.send({files: [`gen.plancke.io/exp/${player.displayname}.png`]});
This method works with local files, but I am trying to send an image from an API, which in this case is gen.plancke.io/exp/${player.displayname}.png. When I run my code, it gives me an error saying it cannot find the file. How can I send the image from an API instead of a local file path?
Passing a link to files without using http:// or https:// will make it assume it's a file path, not a URL, that is why it "cannot find the file".
message.channel.send({files: [`https://gen.plancke.io/exp/${player.displayname}.png`]});
message.channel.send({ file: `http://gen.plancke.io/exp/${player.displayname}.png` });
This should do you justice. Also, errors will be thrown If the user's name is not found on the "API".
message.channel.send({ file: `http://gen.plancke.io/exp/${player.displayname}.png` }).catch(e => {
console.log("Invalid displayname provided.");
});
With this code, the errors will be logged clearly.

Discord.js (Upload a Attachmend also Image and get the URL of This attchemend directly)

I need help.
I want to upload an Image in Discord and after finished upload, I will post it automaticly in an embed.
its this possible?
You can use an attachment in a rich embed without having to send the attachment separately.
Create an attachment using the Attachment class constructor. You can use a Buffer, local path, URL, or Stream to generate the file.
Construct your RichEmbed as usual. Attachments can be referred to within an embed with this syntax: attachment://<filename>.
By utilizing the options parameter of TextBasedChannel.send(), you can send both attachments and embeds.
Consider the following code which sends a rich embed with Discord's logo as the image...
const { Attachment, RichEmbed } = require('discord.js');
const attachment = new Attachment('https://discordapp.com/assets/fc0b01fe10a0b8c602fb0106d8189d9b.png', 'Discord.png');
const files = [attachment];
const embed = new RichEmbed()
.setColor('#7289DA')
.setImage('attachment://Discord.png');
/* TextBasedChannel */.send({ embed, files })
.catch(console.error);

Resources