The new discord update added the feature to mark images and text as spoilers for text: you just have to type || text ||. For images, there is a check mark at the bottom of the attachment prompt:
Is there a way to mark images as spoiler or is the feature too new?
This does not work:
let image = new Attachment('./img/image.jpg');
message.channel.send("|| " + image + " ||");`
a quick way of doing it would be starting the filename with SPOILER_
for example img.png would become SPOILER_img.png
message.channel.send({
files: [{
attachment: 'IMG LINK',
name: 'SPOILER_NAME.jpg'
}]
})
This is what the API has listed for the image for embeds and it doesn't seem to mention marking as a spoiler so perhaps it is yet to be added for bots. I can't find anything about spoilers in the API, maybe you'll have more luck.
Related
Discord.js released v13 and I'm trying to update my little homebrew discordbot.
I've come across an issue where I can no longer send an attached file (png) via a web URL.
Discord.js v12
var testchart = `http://jegin.net/testchart2.php?sysid=268.png`;
message.channel.send("Last updated " + updatedAt.fromNow(), {
files: [{
attachment: testchart,
name: 'file.png'
}]
No errors to the console are made (other than a depreciation warning):
And the bot does not return an image:
I've tried:
message.channel.send("Last updated " + updatedAt.fromNow(), {
files: [testchart]
and
message.channel.send("Last updated " + updatedAt.fromNow(), {
files: Array.from(testchart)
});
And finally
message.channel.send({
files: [testchart],
content: `Last updated ${updatedAt.fromNow()}`
});
Which gives me this AWFUL output:
Thanks for the help!
Discord.js's guide for updates: https://discordjs.guide/additional-info/changes-in-v13.html#sending-messages-embeds-files-etc
Only other issue I was able to find on the matter: Discord.js V13 sending message attachments
Found the issue, it has to do with the testchart2.php part of the URL (http://jegin.net/testchart2.php?sysid=268.png)
Was able to get it sent by using:
message.channel.send({
files: [{
attachment: testchart,
name: 'chart.png'
}],
content:`Last updated ${updatedAt.fromNow()}`,
});
Basically, just take the content part of the v12 and move it to it's own area. Worked like a charm.
Your first attempt was close, but not exactly correct. You just have to merge those together (sending messages only takes 1 argument now) and you will get a png file (because you specified the file name), along with the content:
var testchart = `http://jegin.net/testchart2.php?sysid=268.png`;
message.channel.send({
content: "Last updated " + updatedAt.fromNow(),
files: [{
attachment: testchart,
name: 'file.png'
}]
})
I am building a react project where a user needs to be able to preview a document that has been uploaded. I have the file stored in a blob file in a variable called 'upload', and I use the following code to display it in a new tab when the user clicks on the preview button:
var newWIndow;
if (upload.includes("data:application/pdf"))
newWIndow = "<iframe width='100%' height='100%' src='" + upload + "'></iframe>"
else
newWIndow = "<img width='100%' src='" + upload + "'></img>";
var x = window.open();
x.document.open();
x.document.write(newWIndow);
x.document.close();
The uploads are limited to image or pdf files, and works great, except when the file size goes over 1MB. In that case, it simply opens a blank page:
THe entire blob file is too large to post here, but I thought that giving an idea of what it looks like might help someone spot what I am doing wrong, so here is a snippet:
data:application/pdf;base64,JVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvTWV0YWRhdGEgMiAwIFIvUGFnZXMgMyAwIFI
Does anyone perhaps have any advice for me? Is there a better way to open the uploaded document? Is there a way to get around the size issue? Any advice would be greatly appreciated.
I was mistaken, I was not using a blob object but a binary Base64 one. The new question, as well as the solution, is posted in this post.
line of code:
footer: {
text: `${message.guild.name}`,
icon_url: `${message.guild.iconURL({ format: "png", dynamic: true })}`,
}
the command shows the name and icon of the server in the footer of the embed and it works perfectly fine unless the guild doesn't have an icon in which case i get the error:
Invalid Form Body
embed.footer.icon_url: Not a well formed URL.
any tips?
Have you tried to do an if(){} statement? eg
if(!message.guild.iconURL){}
if(message.guild.iconURL){}
The "!" means "if not", I might be wrong but that should help you out.
I'm using CamanJS to add some image processing features to my website, it's a simple and great library but still its documentation is somehow poor.
I'm uploading an image to my website, then I'm applying all the effects on the image uploaded (it's not saved on the Server, I'm modifying it on the client side).
as shown on the official website (http://camanjs.com/guides/#BasicUsage):
function invertColors() {
Caman("#original-img", function () {
this.invert().render();
});
}
The problem is when I re-upload a new image. apparently CamanJS keeps the first image cashed, and the new image is not shown.
when I read about this issue the only place I found an answer for this is here:
CamanJS - change underlying canvas after applying filters/manipulations
but I'm sorry the answer was not that clear for me. so I have to ask it again.
the answer suggested to use reloadCanvasData() but I didn't know exactly how to use it, I tried so many ways but all went in vain!
I tried:
Caman("#original-img", function () {
this.reloadCanvasData();
});
and:
Caman.reloadCanvasData();
etc.
Can anyone provide a working example?
Thanks
I thought I'd help those who came here looking at how to replace PIXEL data rather than just a loaded image:
can1 = document.getElementById("MyCanvas1");
ctx1 = can1.getContext("2d");
var c = <do what ever you need and make a new canvas here>
ctx1.putImageData(c, 0,0); // <---this replaces the pixeldata
Caman("#MyCanvas1", function () {
this.render();
});
This way you can process the image at the pixel level, and then get it back into camanjs.
As a solution what I have done is clear the canvas and have again Inserted an HTML Image tag. before calling Second Image.with camanjs
something like following
function clearCanvas() {
$('#ImageParentDiv').empty();
var htmlTag = '<img src="../images/Loading.gif" id="original-img">';
$('#ImageParentDiv').html(htmlTag);
}
Just call the revert() when you need an original image:
Caman("#original-img", function () {
this.revert();
this.render();
});
I'm trying to replace a PDF file in a Google Drive Folder using a script. Since GAS does not provide a method for adding revisions (versions), I'm trying to replace the content of the file, but all I get is a blank PDF.
I can't use the DriveApp.File class since our Admin has disabled the new API, so I have to use DocsList.File instead.
Input:
OldFile.pdf (8 pages)
NewFile.pdf (20 pages)
Output expected:
OldFile.pdf with the same content as NewFile.pdf
Real Output:
OldFile.pdf with 20 empty pages.
Process:
var old = DocsList.getFileById("####");
var new = DocsList.getFileById("####");
old.replace(new.getContentAsString());
Any ideas, please?
Thanks a lot in advance.
PS.: I also tried calling old.clear() first, but I'd say the problem lies on the getContentAsString method.
The Advanced Drive Service can be used to replace the content of an existing PDF file in Google Drive. This answer also includes an example of how to update a PDF file in a shared Drive.
function overwriteFile(blobOfNewContent,currentFileID) {
var currentFile;
currentFile = DriveApp.getFileById(currentFileID);
if (currentFile) {//If there is a truthy value for the current file
Drive.Files.update({
title: currentFile.getName(), mimeType: currentFile.getMimeType()
}, currentFile.getId(), blobOfNewContent);
}
}
References
https://developers.google.com/apps-script/advanced/drive
https://developers.google.com/drive/api/v3/reference/files/update
An example of using with a shared Drive:
Drive.Files.update({ title: currentFile.getName(), mimeType:
currentFile.getMimeType() }, currentFile.getId(), blobOfNewContent,
{supportsTeamDrives: true});
Try to get it as a blob datatype instead.