jeudi 26 août 2021

Discord.js - Post image from folder ERROR

I want my bot to respond with an image if someone uses the command !image. This image needs to be a random image from a specific folder named gta.

My code:

client.on("message",message=>{
  if(message.content==('!imagetest')){
    var files = fs.readdirSync('./gta/')
    var chosenFile = files[Math.floor(Math.random() * files.length)] 
    console.log(chosenFile)
    message.channel.send(
      {
        files : [
          chosenFile
        ]
      }
    )
  }
})

The error: UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat '/home/container/d864050.jpg'

It think should be /home/container/gta/... (a random image), but i don't know how to do that.

Any help would be appreciated!




Aucun commentaire:

Enregistrer un commentaire