#development
1 messages ยท Page 202 of 1
Do you need node.js app open or nah
I have a problem, I am setting up an API to read json but this also allows access to the source code as removed?
const express = require('express');
const app = express();
const port = 80;
const fs = require('fs');
const endpoints = [
'/boss',
'/chorus',
'/clicker',
'/egghunt',
'/end',
'/faction',
'/koth',
'/money',
'/trixiumFaction',
'/trixiumPlayer'
];
app.get('/', (req, res) => {
res.json({
endpoints
});
});
endpoints.map(endpoint => {
app.get(endpoint, (req, res) => {
res.json(JSON.parse(fs.readFileSync(`./data${endpoint}.json`)));
});
});```
base_url/faction work
but base_url/index.js works when it shouldn't 
Sounds like a good idea
Iโd set a max amount per message tho
I also have no idea what they are talking about
That's why I would like to change that xD
Better off using a permission system at that point
Depending on how wide scale this api is
Does anyone use NextJS or React
im on the verge of breaking down
because data and userGroups doesn't want to accept data existin-
wait
brb
ur not awating the fetch
You canโt in useEffect
so just .then then
useeffect worst thing ever made gg
i genuinely despise jextns so much
i got desperate once and just made an asynchronous function inside useeffect and called it straight away
lol
worked like a dream
๐ข
yeah mine did that b4
but thats mes-
brb
okay yeah nvm
it didnt work
oh
wait
was i using the wrong api this entire time
omg i fuckign hate my life
nope still no data yay..
shouldve used svelte
jsx is the definition of bloatware in the web dev world
its not that bad
๐
its bad but not that bad
it handles fine
and i dont like svelte
its just react shenanigans
This might be helpful ^-^
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-client-with-route-handlers
I think these days route handlers are the "correct" approach.
oops
yeah
still get hit w no data
the data IS there
idk its weird
@solemn latchidk if i did it right or
if react is against that lol
but thats what i did
lol i love _next being exposed all the time
ts-ignore
without it; webstorm yells at me
(they exist)
i do
I just cba being typesafe rn
i been doin this for 7 hrs
^ thats that 1
wait-
brb...
Its just the best ๐
xdd
wasnt there a way to rename the _next endpoints? ๐
'd recommend extract useEffect logic in an async function
moreover when it reaches the fetching of api/admin, data might still be undefined even though it exists (assuming the first fetch goes successful)
mhm
type is not annotated
you will have to manually type the response type
fetch(...)
.then(res => res.json())
.then(data => consume(data as T))
okie lemme try this
declare an interface that represents the structure of the response, and replace T with it
jus did
2 sec lemme
make sure it all "works"
No data found-
wtf
so it does exist
but it still isnt setting state and idk why
also in your fetch you can just
async function fetchAll() {
const data = await fetch(...)
const roblox = await fetch (/* use `data` here */)
return ...
}
// ...
useEffect(() => {
fetchAll().then(...).catch(...)
}, [...])
m
it did set the state, not immediately
try this
it smells
nah
yeah lemme do dat rq
you stinky for depending on state like that
if state changes eagerly, your application will hang
not my faulttt
my friend told me to use state
o h
also to use the state
const [state, setState] = useState<T>();
^
specify the type, if you don't have an initial value for the state
oh chris i'm on phone
tip: 1. don't depend on ai
2. you can just
const data = await fetch(...).then(res => res.json());
yes i have
i dont depend on ai
it kinda jus
type mismatch
does its thing
ooo
pffft
Array<UserGroupData>
i use it for logic that i cant think of
array types are suffixed with []
Kewl
yup
yeah that's what i meant on "depend on ai"
use it for what you already know but too lazy to type
this no?
nono
i mean SIMPLEEE things
like
"i forgor how to check if x ISNT y..."
yes this happens often.
๐ญ
useState<UserGroupData[]>([])
is enough
no need for that array cast
okie
its still yelling :(
as for the object i would recommend using null for empty value instead
oh okie
check the error and fix
yeah it doesnt like null
you will need to annotate the type
thats <typenamehere> right-
yup
i normally have
type Nullable<T> = T | null;
annotate function return type
im so confused im sorry- ๐ญ
you declare a generic type that is maybe null, then use it in use state function
so that it allows null values
for example
const [user, setUser] = useState<Nullable<UserData>>(null);
this is useful when you have state with initially no meaningful values
like this?
yeah
what is fetchAll
me when I look in the mirror
normal [] ?
or
sorry
A [UserData | UserGroupData | null]?
nope
function fetchAll(...): [UserData, UserGroupData[]] {
// ...
}
I donโt like returning arrays of different types like that
that and the error should go away
I prefer a structure that wraps around both types as a member
because await fetch
tbh an object would be better
or- do i not need await-
So return as a object instead?
use Promise<T>
No worries
The fuck you mean
The syntax can be challenging at first
UserGroupData isnt UserGroupData
{
userData: ...
userGroupData: ...
}
idiot silly thingy smh.
hang on, just... do fetchAll first
change the signature and reflect return type
actually, you don't even need the return type annotations if you return it as an object
I want to return as an obj
which then you can destructure it in the consumer function
.then(({ userData, userGroupData }) => ... )
do it
do u know what i can do about this btw
bc nextauth seems to think a valid discord oauth is name emial image
:Cri:
This yuh ?
fix your type declaration
I.. can't-
It's a predefined Session
idk how to change that
tip: you can do property shorthand
return { groupData: groupData }
can be shortened to
return { groupData }
o
same thing applies with object destructuring
this ?
except you rename in the first case
use userData to fit the naming context
This is the useEffect
oh okie dokie
tip: use guard clauses in this context
if (condition) {
// do stuff
}
can be
if (!condition)
return; // early bail out
// do stuff
would help reduce nesting
le
do you really need loading in that useState dependency array?
productionnnn
setLoading(false)
I think so-
no
that would trigger a 2nd fetchAll call
you can mutate states even if it is not present in the dependency array
Anyone still able to help me I am on PC now
it would still rerender as usual
useEffect is the effect callback, after the component rerenders because of a state change (an effect)
eg. you changing user
How to fix
still works as usual
reinstall node
I have 5 times
type this in
where.exe npm
and send me the output
In the command VSC
also use screenshot (Win + Shift + S)
ye, or in windows terminal (Win + X then press I)
I did it and I got the destination. It Isn't even close to where it needs to be. How do i switch iy
uninstall node
I have 5 times and it still didn't work.
How to do that
smacks lips
Win key, then type "environment variables"
500.. oh thats database error
Now what
@warm imp hang on, send me the output of this command
cache the data
should have done that earlier
a wha huh
you heard it
alr time to jooj
kidding
tbh, create a mock server that stores the cached data
that way you can avoid the 429
like a jest 1?
have the server request once, then store in the cache
change the url to temporarily point to your server
strategy is simple
when request
i get cache
no cache? fetch external, then store
return data
this is honestly a next level of asking for help ๐ญ
i've seen it all
- Code bins
- Screenshots of code
- Pictures of a screen that has an error
they have chrome, chrome profile and edge...
How to get in code bins
what was the command that caused this error
npm?
๐
just typing npm
tfw npm errored finding npm
that file is a shell command
node path/to/npm-cli.js
guess what kind of project this was
Want me to redownload the whole node again or
run the installer again, modify the installation and check carefully
e a spors
@civic scroll cant i jus use a json-server lol
i hate life
Anything with path
Itโs crazy Iโve never seen someone struggle to install node
or

up to you, though i think the logic is custom, hence programming
lol
mm true.
yeah, add to path
if you want 429, go ahead lol
assuming your page reloads on save
It didnt download anything
requests from roblox
honestly, try to find a tutorial online on how to install node ๐คท
given its dev; yh
ah, choco, no need
Ok
Just hit enter
spawn a new terminal session and check if npm is still there
It literally tells you what to do
if it is, restart vscode
be niceee
I am being nice
be sayu rn
what
But I also donโt understand people who canโt read
It aint me. its the flipping thing
๐
I download all the things
and did it
welp time to deploy the machine
not sure why it isnt working
Try running node -v in a terminal
node is there
Okay then whatโs the issue
not the target script file tho
Well if he redownloaded it, then it would of fixed that
No
OK now what
Same error
Show the error
crazy it's a 3v1 and the error still outplaying you.
But the code isnt in those files where it is searches
what does that mean
it's looking in the wrong place
your path variables are fucked
https://stackoverflow.com/questions/24721903/npm-npm-cli-js-not-found-when-running-npm
This post here shows a similar issue
change your path variable for nodejs
point it to look in the correct location, and run npm again
okay let's go
In this tutorial, I share how to add to the PATH environment variable in Windows 10. For this example, I'm adding Python 3 to the PATH so that I may begin writing code (and executing it) using Python 3 as I had forgotten to add Python to the PATH when I installed it.
The method shared in this video can be used regardless of what you're adding t...
Just tell me for the people that dont know
open environment variables settings
you have the window opened?
it has visual exampls too :)
Sayu dont
just let him watch the video
If he can't even watch a video, then you explaining it will trip him up as well
i got them to open the window before, might as well point it out
@warm imp look in Path and look for any path that has nodejs or node in it
verify that it is correct
if not, remove that entry
then reinstall node
actually don't have to reinstall, but i wanted to make aure
dw, i haven't slept
All he has to do is make it point to the root nodejs dir
@civic scroll thanks for helping hon
yeah
imma try the mock server stuff tomorrow (or when i get the energy to)
yw
C:\Users\user\ProgramData\nodejs or wherever its installed
in this case, C:\Program Files\nodejs
Some might say I was stuck.
that works too
dw i spent 20 hours once
How do i find where node is
๐
where.exe node
k

i hate that i have to run with .exe
use cmd ;)
@sharp geyser 
rip
is node supposed to be this heavy
Path is there
I just find it kind of funny how when I first started out with node, I don't remember ever having this much trouble getting it to work
But it is still going to the other location
have you tried pressing ok to save your changes
save that and start a new shell
and then opening a NEW terminal
no need to be rude
I did\
youre the one who cant find npm....
Still didnt work
GASP
right not to be rude
See still going after i changed it
@civic scroll again cheers
right
i got it lol
I am not going to teach you how to use a fucking application
for quick tests, using a terminal is a very handy one
just close the window
jeez
its vsc dont forget
๐
shit hates the idea of deleting
it would close
I am gonna 
restarting vscode would also refresh the env vars since it has to start a new console host
so yeah
I did
what's the result?
wait so
Same thing
No
๐
It was getting lost in command prompt too
you wont fifnd it IN vsc
THEN TELL US THAT YOU BOZO
I did
๐
allow me to introduce you to corepack
type in ```
ls C:\Users\natha\Roaming\npm\node_modules\npm\bin
see what you get
corepack install pnpm
corepack enable pnpm bang
forgor
ls wont work
ls.exe
lol
๐
ls is a powershell command alias
is ls even a windows cmd
according to last screenshot, yes
it was my mistake, apologies
right
ls C:\Users\natha\Roaming\npm\node_modules\npm\bin @warm imp
ls C:\Users\natha\Roaming\npm\node_modules\npm\bin
get beat
but you should be able to read right? Sayuri is obviouslly not a user on your system
wrong ping, L

probably
Still didnt work
nah mention edits no
SS
i need the output
This is starting to feel like teaching Joe biden how to walk up a flight of steps
normally it would show something like this
There's an alternative to npm
Pretty Pwsh; send me ๐
he wont ever be able to use anything else
see to make it that i aint doing it in the wrong spot
ls isn't a windows command
why are you in administrator
ls C:\Users\natha\Roaming\npm
wait, why are you in admin
doesn't matter
ls C:\Users\natha\AppData\Roaming\npm
oh
ls doesn't work on windows

yeah appdata
it does on pwsh
It isnt in app data for my npm
it does in powershell
blud is in powershell
C:\Program Files\nodejs\node.exe
oh in powershelll?
Thats where node is
anyone that uses powershell is insane
you will need to reinstall
that's what I said
VM time
At this point completly delete node and never touch it again :)
๐ฆ
use rust
hey dont discourrage
better language
because unfortunately, that path is hardcoded
๐ช
@warm imp can i get you to try corepack rq to see if that can solve it
me when VM ๐ฃ๏ธ ๐ฅ
run this for me rq
all he needs to do is completely remove it from his system, reinstall it to the correct place and then try it again
To know where i am downloading it
am i insane ๐๐
depends
have you uninstalled the previous installation first????
corepack install --global pnpm@stable @warm imp
why pnpm
i use windows in linux in windows
Kiwi fucking stop
if you want bloat...
ffs
they cant even use npm dude
no one fucking cares
pnpm is a simpler installation.
yeah then pnpm wont help lol
the thing is, they are having trouble setting up npm
if pnpm ends up in the same fate, i will clown on you
shut up u came in here with the rudest attitude man
no need for the aggression all the time
so shut the fuck up
calm down folks
@solemn latch
Holy 
It's always worth trying sayu
tldr; pnpm won't help because it's just adding more confusing stuff
Let us help him with the current problem
๐ maybe its time to step away for a bit ๐ฆ
instead of confusing shit
if they use npm and the guides etc are using npm, then install npm since that is what they will need to follow
the main problem is, npm doesn't exist where it's supposed to be
so now we will need to do some shnenanigans
@warm imp lemme run it through with you
Woo, no disrespect, but I was always trying to help, not my fault that annoying fucks can't tell they are being more harmful than good
we can manuyally download npm
mm

no because you are going to install pnpm not npm 
don't
I redownload it
I was gonna do npm.
i want you to literally uninstall node
He already did
is this entire issue about failing to find npm
And then reinstalled it
yep
I did i went into the control panel and delete it
then why node didn't install npm
;C:\Program Files\nodejs\ on Path Variable -> User variable
weird
the binary hard coded the path for npm when he installed it

that is there
Anyways;
so you have it uninstalled rn?
then yeah just uninstall and reinstall node.js and it will fix itself ๐
reinstall nodejs
Again, he already reinstalled it
there you go
npm 10
but %APPDATA\npm\node_modules\npm doesn't exist (it should've)
npm install -g npm@latest
isn't npm 10 the latest
Not in VSC
what
samsung emoji
wait no nvm i was thinking of py ๐
literally the latest...
10.5.2
used to fixing peoples py311 installs
Its going to the wrong thing in VSC
not node installs
i did
Restart your computer for good measure then
I went in task manager and closed it
k BRB
shutdown /s /f /t 0 my beloved
Alt + F4
but what
what if ur in pwsh at the time
have you heard of a power button
why waste time alt f4'ing thru a bunch of screens
mines on the back
Win + D
then just reach for the back smh
yh but some software force-
even better, contact local power infrastructure to shut down the power
what software
personally i'd just use command prompt instead of vsc terminal
personally i would use powershell
it has some utils that i like using
what happens if i delete VSC and redownload it
what did u misread
nothing
youd waste about 5 mins of your time lol
maybe be a minor version up
What do you want me to search in VSC settings
More interested in the global settings.json file
How to get there
CTRL SHIFT P and iirc just search for Settings and it should give you an option to view the settings.json file
command prompt instead of vsc terminal
^^^^^^^^^^^^^^ ^^^^^^^^^^^^
| misread with `powershell`
|
caused by prediction of this prompt
at Sayuri.ParseToken(dir: Linear, strategy: EagerReturnEval)
ruh roh
got it
how long u spend writing that?
not long
too long? ๐ญ
Oh wait
Lol\
@warm imp ctrl+r wt bish bash bosh use that
500ms
typing takes time
my dev drive has you in it fr
what
guess its not vsc settings
sayu_smells
K
if not then its another issue entirely
Google sucks
bet it smells like lavender
It didnt show anything
Though what that issue is, no idea because it works outside of it
kinda smells of heat ngl.
this gotta be one of the most confusing diagnosis
good thing im not a doctor
works in powershell, but not vscode terminal (which uses powershell)
i won fnaf
honestly could be something fucked with vsc I wouldn't be surprised
it might be
no
k
unless you want to
Ok it is now installed \
How do i restart my powershell
for the path
Wait it isnt VSC
idk
It's because the path
And I don't know how to change it
Besides going into environment variables which I already did
at this point Iโve exhausted all options
Youโve already reinstalled it completely which should logically fix it
What does your system path look like
There is two different paths
User path and system path
i was looking through my codebase for code smells and found a place where i'm using null. it looks like discord is requiring me to send content: null to get rid of the content. is discord planning to change this behavior?
is there anyway to avoid using null here? i think i would need discord to update their api
removing code smells
i even said in my post
i was looking through my codebase for code smells
Didnโt read too much
it was the first sentence
Code smells are a played up concept and you should not care this much about them
i just put out a big update and wanted to do some cleaning
You are quite literally sending data to discord, and you yourself are not reading it anywhere. Null should not matter to you here
i have to use null right? no way out of it?
unless discord updates
Pretty sure
You really shouldnโt be caring this much. I hate the concept of โcode smellsโ because they are a blanket of rules that say โNEVER do [x]โ when in fact, there are plenty of valid situations where it is either unavoidable or unreasonable to avoid
yeah, every language should have undefined and null in it
Every language has some concept of emptiness whether you agree with the name or not
Undefined is a mistake, I understand avoiding undefined
But null exists in every language whether you like it or not, there is just different ways of handling it
undefined is built into the language. null is extra. but if they renamed undefined to null and removed undefined that would work
Rust has Option<T> instead of null, arguably one of the best ways of handling it
yeah, rust is pretty good for a typed language
This level of code nitpicking makes it difficult to contribute to projects because you are more worried about your โcode smellsโ than the actual code itself
Perfect code is not feasible to write. Strive for perfection, donโt expect it
These small little things are not problematic to the point where you need to find ways around them
spaghetti code is easy at first, then you cant add anything to it
Nobody said spaghetti code was okay to write
Youโre trying to get rid of a null where it would make literally 0 difference because it is only ever touched by discord, not you
That is nitpicking
i wanted to remove a line of code. when you see null it's a sign that something could be wrong
That is not a good mindset to have
I am pretty sure that nobody treats null as something that indicates a problem unless youโre not expecting it to be possible to be null
i need content: null here because discord wont delete the content part when you update a message unless you send content over
And whatโs wrong with that?
it's like half stateful and half stateless. the top level props have state, but props inside dont.
i have to send content: null instead of just not sending content.
i had a bug because of that
You have to do that, and thereโs nothing you can do to change that. Saying itโs a code smell because thereโs null isnโt valid
Sure, it might be odd on discordโs end, but you are also worrying far too much over 1 line that you already figured out simply because an arbitrary set of rules says itโs bad
If discord is expecting a content field, Iโd imagine that it would be unhappy if it didnโt receive one
discord is happy not to recieve the content field
the original message is an embed
Well then again, not a problem on your end. Discord should give you an error and they didnโt
Nothing you can do to fix that
then i update it with a content part to ping players when it's ready
then i update it again if someone leaves so it only has an embed with no content, but i have to send content: null instead of just ommiting it
it looks like they fixed it for attachments
You cant
votes reset every month
pylance is tripping
seeing camelCase in Python is so cursed
actually, it has
i think the camel case is for people who have java muscle memory
make functions with the camel case install a backdoor
thats what they get trying to bring their java shenanigans into python
Hi everyone, I'm programming my discord bot and I'm encountering this error, I don't understand how to fix it. Does anyone know what causes this problem? Many thanks in advance
that means you tried to fetch or process an interaction (eg: buttons) that no longer exists
I have this in the code:
await interaction.reply({ files: [{ attachment: canvas.toBuffer(), name: 'profile.png' }] });
Could that be what's causing this error?
maybe, cant say much without the full code
Chances are you either tried to fetch an expired interaction or something like that
Itโs also possible that you didnโt defer the interaction and it expired before you could respond
interactions must be replied to within 3 seconds
if your code is taking too long to respond (seeing you have image generation with canvas), the interaction will expire
the 3 seconds also count network delays, so realistically your code has less time than that
Exactly, I have to generate a fairly complex image and it's possible that it takes me more than 3 seconds, but how can I solve it then? Isn't there another way?
ie, if it takes 300ms for the request to arrive, then another 300ms for the response to be delivered, the actual code only has 2.4 seconds to respond
exactly
as soon as you receive the interaction, respond with a deferReply
afterwards you can take all the time you want
So if I do something like this I shouldn't have any time problems right?
await interaction.deferReply()
/* My code to generate the image */
await interaction.reply({ files: [{ attachment: canvas.toBuffer(), name: 'profile.png' }] });
Change .reply() to .editReply()
you will if you take too long, but the timeframe will be extended
iirc it'll extend to 15 min or so after deferral
daemon is better if you're building many times iirc
I meant building many times, like, edit build edit build edit build
not many projects
if you want to speed it up, it's better if u increase gradle threads
default is 4 iirc
How would I make a message response activate for a word like "no" but not activate where the word if part of another like "now"? I know there is a way but can't remember. I thought of just using .startswith or whatever the filter is called but that still wouldn't work for words like now and that.
my command handler makes the message content into an array so I suppose I could just use that. see if the first word matches "no" or whatever
.split(' ')[0].trim().toLowerCase() === 'no'?
This is probably a tragic way of doing this but if youโre only checking the first word then I donโt see why it would be a big deal
does that just make the message into an array and then just see if the first argument is no?
Assuming that youโre using the full content of the message, yes
nice
If itโs already split by your handler then you can get rid of the .split
yeah thats what I was thinking
But again, probably not a great way of doing it. Not sure what your needs are for this
If you just want it to only respond to "no"
Then content === "no" :p
you dont need the trim either, if you split with \s+ regex for example
If you just want to see if โnoโ exists in a sentence somewhere in there, you can use a regex
Yeah
my needs are, "its a funny bot on a mates discord" so I don't really mind about bad practice lol. that went out the window long ago
Regex can match basically anything you think of but I forget the syntax for stuff since I donโt use it very often
I know a bit of it but its not fresh in my mind at all
for my use case (ie to just say yes when some one says no) it would work better if its only from the first word not if its at any point in a sentance
Why wouldnt
content === "no"
work then?

I think I am just using .includes at the moment so yeah I think I will just change it to that.
one of these days I will actually make the auto responses their own command file instead of just being typed in the top of the message event file
but eh I will probabvyl do that when I have to rewrite my entire bot the next time I put it on another server because node.js will be on version 1000 by then and nothing will work
I'm tired of this grandpa
Everyone is recommending dpp lately
its everything a discord library for a large bot should be
indeed
storing things efficiently and caching sparingly becomes extremely crucial especially with discords JSON type data
Its quite the jump from js to c++ tho
json is very inefficient to store and play with
its basically a map but lets you have nested maps inside of it as well
i would honestly take on the challenge of porting an existing js bot to c++ if i had one
but a lot of discord developers dont do languages like that
I agree
I would not recommend starting out using D++ though unless you are completely new to programming
If you are already far into using js then stick with it until the need for D++ arises
json is a map lul
a lot of implementations anyways
this library is only for reading json but it doesnt store it as a map https://simdjson.org/ (not rapidjson)
it lets you jump through the keys and values on demand
nothing gets parsed until you need it
and consumed values disappear so memory footprint is extremely low
but it takes away the simplicity of json really
the memory requirement per server count in discord.js is ridiculous
you need a somewhat beefy server already at only a couple of thousand servers
it was even worse before they added in partials and better cache control
oh i meant json itself, you can parse/read it in other ways ofc
Oh I know, its stupid, mac's bot uses 16gb right now



