I am creating a discord bot (irrelevent) that sends images into the chat. The user can type out the name of the image without needing to type the file extention. The problem is that the bot doesn't know what the file extention is so it will crash if the picture is a .jpg and the program was expecting a .png. Is there a way to make the program not require a file extention to open the file?
let image = imageName;
message.channel.send({ files: [`media/stickers/${imageName}.png`] });
fsfunctions to read the folder (readdir) then find the file whose name matches the given filename part - then you'll have the extension partfsyou can find it byconst file = (await readdir(folder)).find(f => f.split('.').slice(0,-1).join('.') === target);wherefolderis the folder the file is in, andtargetis the filename without the the extension