#somewhy the file is there but itt can't read it?

43 messages · Page 1 of 1 (latest)

hardy dirge
Error: ENOENT: no such file or directory, open 'NSFW.txt'
    at Object.openSync (node:fs:601:3)
    at Object.readFileSync (node:fs:469:35)
    at Object.execute (C:\Users\SkyOPG\Desktop\StarBot\interactions\ai\imagine.js:26:26)
    at Object.execute (C:\Users\SkyOPG\Desktop\StarBot\events\interactionCreate.js:16:18)
    at BotClient.<anonymous> (C:\Users\SkyOPG\Desktop\StarBot\events.js:15:44)
    at BotClient.emit (node:events:513:28)
    at InteractionCreateAction.handle (C:\Users\SkyOPG\Desktop\StarBot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
    at module.exports [as INTERACTION_CREATE] (C:\Users\SkyOPG\Desktop\StarBot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\Users\SkyOPG\Desktop\StarBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
    at WebSocketShard.onPacket (C:\Users\SkyOPG\Desktop\StarBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:494:22) {
  errno: -4058,
  syscall: 'open',
  code: 'ENOENT',
  path: 'NSFW.txt'
}
young lantern

NSFW.txt wouldn’t be a path

hardy dirge

but that's how it works in this line

const nsfwWords = fs.readFileSync('NSFW.txt', 'utf8').split('\n').map((word) => word.trim().toLowerCase());

ill try though

young lantern

It’s from your working directory ig

hardy dirge

my working directory, i changed it to ./NSFW.txt and still gives the error

young lantern

Can you show me your file structure

hardy dirge

as a screenshot?

young lantern

Yes

In vs code

Or so

hardy dirge
young lantern

Try

./interactions/ai/NSFW.txt

hardy dirge

okay

tysm it worked!

young lantern

I am probably wrong

young lantern

But that means you start from index.js, so you need to go from there

Hence ./interactions/ai/…

hardy dirge

cause everything is getting read from it

young lantern

Kinda, not too sure

But you’re welcome :)

hardy dirge

:)

hardy dirge

index.js

interactions.js

interactions.js actually processes the commands

and it is required by the index.js

thanks again for the help

distant sinew
young lantern

Is it?

distant sinew

yes

young lantern

I thought like ./NSFW.txt would be a park

Path *

distant sinew

it just refers to the file relative to the cwd

file.js wouldn't be a valid import via require or import because of node's module resolution but for file access it's perfectly fine

young lantern

So if it was in the same folder as index.js in this case, that would be completely valid

distant sinew

well, the cwd

but yes

young lantern

Yh, missed that ig lol