I am using puppeteer, and I want to send a screenshot of the webpage if there is an error. The screenshot is taken correctly, but I cannot send the screenshot. I keep getting [object Object] in the channel instead of the image.
let message = new Discord.MessageAttachment(await page.screenshot({
quality:10,
type:'jpeg'
}),"ERRORIMAGE.png")
mainChannel.send({files:[message]});
I have also tried .send(message), .send('error image',message), and .send({attachments:[message]}).
I also tried saving the image as a file then giving the path but that also just gave [object Object].
Your best option is sending it through a Discord.messageEmbed using the setImage method on it .
const embed = new Discord.MessageEmbed().setImage('insert the url of the image here')
mainChannel.send(embed)
If it is an image you will be using frequently you might need to host it somewhere for better response times.
here is a link for a guide on Discord.MessageEmbed
it also includes stuff related to Discord.MessageAttachments which you can check out
you are looking for a slightly different syntax
//I will not include the screenshot code, since you said that was working fine, and I will therefore assume you do not need help with that
let message = new Discord.MessageAttachment(await page.screenshot({quality:10,type:'jpeg'}),"ERRORIMAGE.png");
message.channel.send('Message that goes above image - can be removed for no message', {
files: [message.path] //can attach multiple files, simply add more commma delimited filepaths
});
This should work - make sure to add the filepath of the image, not just its name
Edit: the [object, Object] error occurs when you try to use an object without specifying what part you are using. This means that most likely you need to do message.path or something similar, since message is an object.
Related
When I make a post request with a photo in it to a controller for a model that has a photo attached through activestorage but am receiving a #<ActiveRecord::RecordNotSaved: Failed to save the new associated photo_attachment.>
Code is in the following gist for readability, please let me know if i should break it down and put it in this post more directly.
https://gist.github.com/njmbb8/0042e47a5427606da70727de9dd6617d
i had commented out config.active_storage.service = :local in config/environments/development.rb
I'm trying to get the URL of any attachments in a message. I can't seem to find a way to do this: whenever I try to run console.log(message.attachments.url), it just outputs undefined. What am I doing wrong?
I've tried reading the docs and other Stack Overflow questions but nothing worked.
I expect the output to be a URL of the attachment, i.e. 'https://cdn.discordapp.com/attachments/serverid/channelid/file.png' However, it just outputs undefined.
message.attachments is a Collection (a Map with additional Utility functions) so you either have to get the specific attachment via message.attachments.get('ID') or if you are sure that the message only has one attachment you can use message.attachments.first(). Otherwise you have to iterate through the Collection via
message.attachments.forEach(attachment => {
// do something with the attachment
const url = attachment.url;
});
I linked to the Collection docs of Discord.js. You also have access to the typical Map functions as well.
Trying to do something which is very simple but am getting strange results.
I have an image stored as an attachment which I want to display in a VF Page.
If I do this it works fine
<apex:image url="{!URLFOR($Action.Attachment.Download,'00PR0000008Q3YmMAK')}"/>
However that was for testing purposes that I hardcoded the id. If I try reference the Id in the object then it fails. Even though the value contained in the object is exactly the same as above.
<apex:image url="{!URLFOR($Action.Attachment.Download,model.PreviewImageAttachId)}"/>
When I load the page I get an error in URLFOR param!!!
I thought my problem was because model.PreviewImageAttachId was a String and not an Id so I created a wrapper to return it as an Id - same error.
I then decided Salesforce must have some strange requirement that you can only pass in the REAL object so I did that and passed in model.Attach.Id and it still fails!!
Please can someone explain this to me and more importantly suggest a solution??!?
Once again if I output to the page
{!model.PreviewImageAttachId} i get 00PR0000008Q3YmMAK
So I just cant explain this!
Thanks!
My bad...
Was using apex:repeat and turns out SOME of the id values were null.
Hence the error
Inside my WebKitGTK+ widget, I want to transparently replace some of the images of an HTML page with different image data I hold in memory.
According to the documentation at http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#WebKitWebView-resource-request-starting, I've hooked into this signal, which allows the request URI to be changed, but what I really want is to leave it unchanged but generate my own response.
I've tried filling out the WebKitWebResource parameter, and filling out the SoupMessage response from the WebKitNetworkRequest to no avail. Anyone know how to do this?
figured out one way to do it: replacing the request URL with "data:image/jpeg;base64,[inline data]".
Will do for me.
I have a grid that is embedded within a ContentPane which is in a tabContainer. When loading the itemfilewritestore IE7 pops an error.
Code:
var theData = {identifies : id , items[]};
var theStore = new dojo.data.ItemFileWriteStore({data: theData});
console.debug(theStore); // this throws some weird error
error:
{close:function(_81)if(!this.isDirty)........There are unsaved changes present in the store Please save or revert the changes before invoking close.
This error only shows itself in IE7. FF has no problem and renders the data properly. And yes I know there is no data in this code but in the real code the data is added later.
This issue was not as described. The error was not the store in any way. After digging around more, I found out that the real problem was a parsing on a javascript that was being imported. Going step by step through it the problem was because a JSON object was using the term "class" as an attribute. This seems to be against the IE "standards".