48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
|
const { MessageAttachment } = require("discord.js");
|
||
|
const wget = require("node-wget");
|
||
|
const fs = require("fs");
|
||
|
|
||
|
module.exports = {
|
||
|
name: "menu",
|
||
|
aliases: ["menu", "menuadd"],
|
||
|
utilisation: [
|
||
|
"Pour télécharger un fichier, renseignez soit le lien google drive ou juste l'ID",
|
||
|
"{prefix}menu <link_GDrive>",
|
||
|
"{prefix}menuadd <ID>"
|
||
|
],
|
||
|
|
||
|
async execute(client, message, args) {
|
||
|
if (!args[0])
|
||
|
return message.channel.send("Merci de me préciser un lien ! ");
|
||
|
|
||
|
const id = args[0].split("/")[5];
|
||
|
|
||
|
wget(
|
||
|
{
|
||
|
url: `https://drive.google.com/uc?export=download&id=${id}`,
|
||
|
dest: "./Files/menu.pdf", // destination path or path with filenname, default is ./
|
||
|
},
|
||
|
function (error, response, body) {
|
||
|
if (error) {
|
||
|
console.log("--- error:");
|
||
|
console.log(error); // error encountered
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
|
||
|
// attendre que le fichier menu.pdf soit téléchargé puis l'envoyer dans le salon
|
||
|
setTimeout(() => {
|
||
|
const attachment = new MessageAttachment("./Files/menu.pdf");
|
||
|
message.channel.send({ files: [attachment] });
|
||
|
}, 5000);
|
||
|
|
||
|
// supprimer le fichier menu.pdf
|
||
|
setTimeout(() => {
|
||
|
fs.unlink("./Files/menu.pdf", (err) => {
|
||
|
if (err) throw err;
|
||
|
console.log("File deleted!");
|
||
|
});
|
||
|
}, 10000);
|
||
|
},
|
||
|
};
|