Tuesday 26 November 2019

Show image

I get a random name from the array but at the time of displaying the images it fails and it puts me that it is not a file or directory, the js file is in the same folder as the images to prevent me from getting the name with the path, in another version that I have with the route if I get both the image and the corresponding name but with the route as well and I want to avoid showing that route, I have already avoided it with the extension but I don't know what else to try.-- 1st version (js in the same folder where the images)const Discord = require("discord.js");const config = require("../config.json");const colours = require("../colours.json");const window = require("window");const randomFile = require('random-file');const path = require('path');const fs = require('fs');module.exports.run = async(client, message, args) => {const randomimg = ["Aegiochusmon Blue.jpg","Aegiochusmon Dark.jpg","Aegiochusmon Green.jpg","Aegiochusmon Holy.jpg","Aegiochusmon.jpg","Aegisdramon.jpg","AeroVeedramon.jpg","Agumon (2006 anime).jpg","Agumon Burst Mode.png","Agumon Expert.jpg","Agumon X.jpg","Agumon.png","Agunimon.jpg","Aircraft Carrier Whamon.jpg","Airdramon.jpg","Akatorimon.jpg","Aldamon.jpg","Allomon.jpg","Allomon X.jpg","Alphamon.jpg","Alphamon Ouryuken.jpg","Amon.jpg","AncientBeetlemon.jpg","AncientGarurumon.jpg","AncientGreymon.jpg","AncientKazemon.jpg","AncientMegatheriummon.jpg","AncientMermaidmon.jpg","AncientSphinxmon.jpg","AncientTroiamon.jpg","AncientVolcanomon.jpg","AncientWisemon.jpg","Andromon.jpg","Angemon.jpg","Angewomon X.jpg","Angewomon.jpg"]const img = randomimg[Math.floor(Math.random() * randomimg.length - 1 + 1)]message.channel.send({file: img})message.channel.send("El digimon es: " + img.replace(/\.[^.$]+$/, ''));}module.exports.config = {name: "digimons",usage: "-digimons",aliases: ["dig", "digimdesc"]}In this case it shows me the name without the path or extension (just as I would like) but does not show the image.​-- 2nd version (js on a different route from where the images are)const Discord = require("discord.js");const config = require("../config.json");const colours = require("../colours.json");const window = require("window");const randomFile = require('random-file');const path = require('path');const fs = require('fs');module.exports.run = async(client, message, args) => {const randomimg = ["./Digimons/Aegiochusmon Blue.jpg","./Digimons/Aegiochusmon Dark.jpg","./Digimons/Aegiochusmon Green.jpg","./Digimons/Aegiochusmon Holy.jpg","./Digimons/Aegiochusmon.jpg","./Digimons/Aegisdramon.jpg""./Digimons/AeroVeedramon.jpg","./Digimons/Agumon (2006 anime).jpg","./Digimons/Agumon Burst Mode.png","./Digimons/Agumon Expert.jpg","./Digimons/Agumon X.jpg","./Digimons/Agumon.png","./Digimons/Agunimon.jpg","./Digimons/Aircraft Carrier Whamon.jpg","./Digimons/Airdramon.jpg","./Digimons/Akatorimon.jpg","./Digimons/Aldamon.jpg","./Digimons/Allomon.jpg","./Digimons/Allomon X.jpg","./Digimons/Alphamon.jpg","./Digimons/Alphamon Ouryuken.jpg","./Digimons/Amon.jpg","./Digimons/AncientBeetlemon.jpg","./Digimons/AncientGarurumon.jpg","./Digimons/AncientGreymon.jpg","./Digimons/AncientKazemon.jpg","./Digimons/AncientMegatheriummon.jpg","./Digimons/AncientMermaidmon.jpg","./Digimons/AncientSphinxmon.jpg","./Digimons/AncientTroiamon.jpg","./Digimons/AncientVolcanomon.jpg","./Digimons/AncientWisemon.jpg","./Digimons/Andromon.jpg","./Digimons/Angemon.jpg","./Digimons/Angewomon X.jpg","./Digimons/Angewomon.jpg"]const img = randomimg[Math.floor(Math.random() * randomimg.length - 1 + 1)]message.channel.send({ file: img })message.channel.send("El digimon es: " + img.replace(/\.[^.$]+$/, ''));}module.exports.config = {name: "digimon",usage: "-digimon",aliases: ["di", "digidesc"]}In this case it shows me the image and the file name but I want to somehow remove the path.

Submitted November 26, 2019 at 07:45AM by Racconccity

No comments:

Post a Comment