0

Im devleoping a discord bot ( discord.js) so, I want to create a command which is like -

+mask Name_Surname(Image URL) and when a user uses that cmd, the bot saves the image from the image url provided into a folder with the name provided by the user. (This is like for a signature bot)

An illustrative example for the above is provided -

The users uses a cmd .upload Name (URL) and the bot saves the image ( in .png format) to a folder which already exists with the "Name" provided by the user.

Click Here to View the example

Im pretty new to this, so what I would like is an example code for the above ^^ so that I can work it out myself. I hope someone can help me! Thanks

Lisk
  • 3
  • 3
  • StackOverflow is not a code writing service. Make an attempt at coding this yourself and then come here when you encounter issues. – Itamar S Apr 07 '21 at 05:20
  • 2
    [Why is “Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question) – charlietfl Apr 07 '21 at 05:29
  • This one could help you https://stackoverflow.com/questions/12740659/downloading-images-with-node-js – Gilles Heinesch Apr 07 '21 at 06:39

1 Answers1

1

So, if you are using Node.js you can use request npm library.

client.on('message', message => {
  if (message.content.startsWith('+mask')) {
    const args = message.content.split(' ');
    const imageURL = args[1];
    var imageName = ""; //Image name

    request(imageURL).pipe(fs.createWriteStream(imageName));
    const attachment = new MessageAttachment(imageURL);
    message.channel.send(attachment);
  }
});

Request library docs - https://www.npmjs.com/package/request#streaming

Sanchir
  • 99
  • 1
  • 8