Program can't locate file.

viewCaptcha.js
const handlers = require("../handlerLoader.js");
const { EmbedBuilder, AttachmentBuilder } = require("discord.js");
module.exports = {
name: "agree",

async execute(interaction) {
const captcha = await handlers.captchaHandler.generateCaptcha();
const file = new AttachmentBuilder(captcha.filePath, { name: 'captcha.png' });
const captchaEmbed = new EmbedBuilder()
.setColor(0x2B2D31)
.setAuthor({
name: "Captcha Code",
})
.setImage(`attachment://${file.name}`)

await interaction.reply({
embeds: [captchaEmbed],
files: [file],
ephemeral: true,
});
},
};
const handlers = require("../handlerLoader.js");
const { EmbedBuilder, AttachmentBuilder } = require("discord.js");
module.exports = {
name: "agree",

async execute(interaction) {
const captcha = await handlers.captchaHandler.generateCaptcha();
const file = new AttachmentBuilder(captcha.filePath, { name: 'captcha.png' });
const captchaEmbed = new EmbedBuilder()
.setColor(0x2B2D31)
.setAuthor({
name: "Captcha Code",
})
.setImage(`attachment://${file.name}`)

await interaction.reply({
embeds: [captchaEmbed],
files: [file],
ephemeral: true,
});
},
};
This code, Well.. It works fine but, It can't seem to actually find the file at the file path as it logs this error. I've also attached an image of the file path with the files existing. Could anyone lend me a hand figuring out why this isn't working
No description
No description
35 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Harnes
Harnes8mo ago
Show your whole folders structure
Kiɾʌ Kenjiɾø
Let me grab a screenshot for you
Kiɾʌ Kenjiɾø
It's passed as a full directory not a relative
souji
souji8mo ago
navigate into the captchas folder and run pwd i have an idea, but that'll confirm it
Kiɾʌ Kenjiɾø
On it! reddragonSalute
souji
souji8mo ago
Hmm
souji
souji8mo ago
it tries to read that, but it isn't there, but it is there what and this is running on that system? not in some container, etc? also what is the full stacktrace of that error
Kiɾʌ Kenjiɾø
Nope, straight in system There is none, That is the error xD
souji
souji8mo ago
yeah, nah, then you're doing nonsense
Kiɾʌ Kenjiɾø
it's not very helpful
souji
souji8mo ago
if you actually log the full error and do not stringify it you get more from it
Kiɾʌ Kenjiɾø
OH WAIT dogeHaHa welp.. look at me bein stoopid again let me go change tht
d.js docs
d.js docs8mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
souji
souji8mo ago
hm. no. bad tag
d.js docs
d.js docs8mo ago
Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
client
.on("debug", console.log)
.on("warn", console.log)
- Note: if you initialize your Client as bot or other identifiers you need to use these instead of client - If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
souji
souji8mo ago
closer still not it
Kiɾʌ Kenjiɾø
XD you'll get it eventually <3
souji
souji8mo ago
ignore that, just console.log(error) or console.dir(error, {depth: null}) if you want ALL of it
Kiɾʌ Kenjiɾø
I changed it and the full stack is this
[Error: ENOENT: no such file or directory, stat '/Users/kirakenjiro/Desktop/Coding/DiscordBotBoilerPlate/handlers/captchas/captcha_6.png'] {
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/Users/kirakenjiro/Desktop/Coding/DiscordBotBoilerPlate/handlers/captchas/captcha_6.png'
}
[27-10-2023_15-35-37] • An error has occurred: Error: ENOENT: no such file or directory, stat '/Users/kirakenjiro/Desktop/Coding/DiscordBotBoilerPlate/handlers/captchas/captcha_6.png'
[Error: ENOENT: no such file or directory, stat '/Users/kirakenjiro/Desktop/Coding/DiscordBotBoilerPlate/handlers/captchas/captcha_6.png'] {
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/Users/kirakenjiro/Desktop/Coding/DiscordBotBoilerPlate/handlers/captchas/captcha_6.png'
}
[27-10-2023_15-35-37] • An error has occurred: Error: ENOENT: no such file or directory, stat '/Users/kirakenjiro/Desktop/Coding/DiscordBotBoilerPlate/handlers/captchas/captcha_6.png'
I hope that helps Catting
souji
souji8mo ago
that should still have more, like a reference to the part that tries to read the file in the first place confusedBecel should be node ENOENT: no such file or directory in here usually means someone is confusing readdir with require using relative imports, one reads from cwd one reads from the file itself but you provide a full path
souji
souji8mo ago
unless i am blind, these two are also the same
No description
Kiɾʌ Kenjiɾø
Those two are the same correct <a:kitty_spin:1044167622746439710> I'm passing it the full path
souji
souji8mo ago
do you have some weird character in one of the file names or sth? that's all i can think of
Kiɾʌ Kenjiɾø
boop das all
souji
souji8mo ago
can you paste, not screenshot me the output of ls -la in that captchas folder
Kiɾʌ Kenjiɾø
shit that is a fair point.. do you want me to grab and send the code here? Because that is genuinely a fair point i'll take a look at it and try await it but, if i need help (I probably will so dont get your hopes up <3) i'll nudge ^^
souji
souji8mo ago
oh it WRITES that one dynamically, yeaah, that aint a thing when that tries to read it then
Kiɾʌ Kenjiɾø
catJAMCRY i forgor to write it with await
No description
Kiɾʌ Kenjiɾø
XD shit works :> Thanks you two reddragonLove