#development
1 messages · Page 139 of 1
cloudflare is but they seem to support sse so I think im doing something wrong
for example in nginx you have proxy_read_timeout and proxy_connect_timeout
is set to like 800k seconds
try adding the X-Accel-Buffering: no; header to the nodejs response
also Cache-Control: no-cache;
your nginx proxy already has these right?
proxy_http_version 1.1;
proxy_set_header Connection "";
it has connection upgrade
afaik a sse request should instantly show the status in the network dev tab
mine just shows nothing (loading)
i believe connection "" is the correct one for persistent connections
lemme try rq
the nodejs headers should be ```
'Content-Type': 'text/event-stream',
'Connection': 'keep-alive',
'Cache-Control': 'no-cache',
'X-Accel-Buffering': 'no'
yup
Ur using websocket with nginx?
i found something interesting, might wanna give it a try
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection '';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 60s; # SSE gets sent on whatever interval this is set to
chunked_transfer_encoding off;
proxy_set_header X-Forwarded-For $remote_addr;
}
Ah, was gonna ask you whether u get random disconnects from it
more specifically this proxy_read_timeout 60s; # SSE gets sent on whatever interval this is set to
Tried finding the cause for too long already, never discovered why my websockets get dropped after a while
ooh, do I have to send "pings" every now and then for it to not close?
im not sure, but from what that comment says it seems nginx waits for data to come from node, and once it timesout, it sends the data so far to the client
and starts waiting again
thats what the commend suggests
ill try sending pings
even though the timeout suggests it would close the connection
try setting the timeout to something like 2 seconds
as discord says, the internet is a scary place
since forever
you dont always need bidirectional
yeah, that fixed it (the event stream is still not recognized properly but ehh, it doesnt reconnect so its fine)
cool
ehhhhhhhhhh still use websockets at that point lmao
I mean yeah they are convenient but to my knowledge relatively resource heavy
react trying to re-render the whole page just because the user moved their mouse 1cm
react rerenders too much
dont know how the browser implements websockets but both use tcp (as far as i know) and tcp is bidirectional so the notification one intentionally limits it
Like, I have a long timeout, I send a ping every 30 mins, and yet I get disconnects after a while running
doesn't affect much, aside from the occasional broken pipes, but it's annoying to have the log full of "Client disconnected with reason xxxx"
i think os's generally disconnect sockets if keep alives havent been exchanged for 30 minutes more or less?
talking about tcp
not sure if that may be the case here
not talking about websockets but for tcp sockets i make clients exchange "heartbeats" every 2 minutes if a connection has been dormant and it doesnt seem to disconnect me
browser might have its own quirks
might be worth to reduce my ping interval to test
there really isnt a standardised way to test/see if a tcp connection is properly dead or not so os's just kill them if nothing has been sent/received for a while
how tf do I prevent react from making 2 requests? basically tried everything at this point
wdym 2?
that subscribe
30 min is a long time
discord heartbeats/pings every 45 seconds lol
bro wants to save that bandwidth
people on internet that limits their total download/upload per month thanking kuuhaku rn
xD
Yes there is, TCP connections have keepalive packets in which they are sent at regular intervals by the operating system or the application, if the remote endpoint does not respond to the keepalive packets after a certain number of retries then the TCP connection is considered dead and terminated by the operating system or application
via raw tcp right?
i never had any luck with them
because websocket add a lot of overhead
i tried setting up keep alives with the c api and they never worked
Skill issue™️
xD
actually my issue was it took the os way too long to disconnect dead sockets with keepalive
i think i checked somewhere and found out you cant change it its an os-level thing
how do I make a websocket
from scratch or...
yea
blud CANNOT ❌ wait 30 MINUTES for the os to tell SCHLAWG ✅ 🐶 if a socket is DEAD 💀❌
in the browser you cant
why would you want to make one from scratch
i don’t want browser
then dont use websockets
but in nodejs you can make a websocket implementation using the built in net module
cus I wanna make one
or the http module also works
yes
since http uses and gves you access to a instance of a net socket anyways
in c the api for connections with tcp is actually very pleasant
Ong
you get functions that block the thread until some data is received and you can send bytes with a simple function
On what operating system were you doing this?
ubuntu
did you check the code for tiny-discord? the websocket file basically does this, its a custom websocket client using the http module
npm says it doesn’t exist
its a node module
its built in
oh
let me see
but you can also make the server part the same way
this?
yes
the websocket part is only a small part of the code
for example
this is where i make the connection ```js
const req = request({
hostname: (this._session.id && this._session.url) || this.url,
path: path,
headers: {
"Connection": "Upgrade",
"Upgrade": "websocket",
"Sec-WebSocket-Key": key,
"Sec-WebSocket-Version": "13",
}
});
does it have to be that long
no
ah good, I was fearing that u managed to make a discord lib within only 1400 lines
alot of it is discord-specific code
request is const { request } = require("node:https");
You can absolutely change it, you can change the net.ipv4.tcp_fin_timeout property in the /etc/sysctl.conf file (the property value is in seconds)
The default value is 2 minutes
then this is how to initiate the connection once its established ```js
req.on("upgrade", (res, socket) => {
const hash = createHash("sha1").update(key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest("base64");
const accept = res.headers["sec-websocket-accept"];
if(hash !== accept) {
socket.end(() => {
this.emit("debug", "Failed websocket-key validation");
const error = /** @type {Error & { expected?: string, received?: string }} */ (new Error("Invalid Sec-Websocket-Accept"));
error.expected = hash;
error.received = accept;
reject(error);
});
return;
}
socket.on("error", this._onError.bind(this));
socket.on("close", this._onClose.bind(this));
socket.on("readable", this._onReadable.bind(this));
yeah but thats a system level setting what if you want to do it per application
mine was definitely not 2 minutes
dont know what happened
notice the socket.on("readable", this._onReadable.bind(this)); thats how i start receiving data from discord
it can also be socket.on("data")
You can't do such a thing per-application in any operating system
this is not what I mean
then you need the code to understand the websocket specification
how to extract the data from the websocket frames
then why is it so long
i do that part here ```js
_onReadable() {
const socket = /** @type {NonNullable<typeof this._socket>} */ (this._socket);
while(socket.readableLength > 1) {
let length = readRange(socket, 1, 1) & 127;
let bytes = 0;
if(length > 125) {
bytes = length === 126 ? 2 : 8;
if(socket.readableLength < 2 + bytes) { return; }
length = readRange(socket, 2, bytes);
}
const frame = socket.read(2 + bytes + length);
if(!frame) { return; }
const fin = frame[0] >> 7;
const opcode = frame[0] & 15;
if(fin !== 1 || opcode === 0) { throw new Error("discord actually does send messages with fin=0. if you see this error let me know"); }
const payload = frame.slice(2 + bytes);
this._processFrame(opcode, payload);
}
}
Also why the hell is Battleless trying to make a websocket from scratch
because
the file contains websocket logic as well as discord api logic, thats why its long
I wanna learn
so how long does my websocket need to be
and event emitter stuff
if you want only the websocket part
let me show you, i actually changed it into a separate version
i separated the websocket code into its own file, its ~250 lines
why does that take up 1100 lines
because discord is complex
so will I need to do that
and i also included a built in ETF converter
⁉️
which takes a lot of lines
You should see how discord.js handles it 👽
probably less than that
tiny-discord
just the websocket part
sounds excessive
the thing is
if you want a minimal implementation
you can do it in few lines of code
but then you need to start adding stuff to handle edge cases
so it ends up being larger than you thought
like code to handle all possible ways of disconnections
code to handle websocket pings
_handleFrame(/** @type {number} */ opcode, /** @type {Buffer} */ message) {
if(opcode > 2) {
switch(opcode) {
case 8: { // close
this._closeCode = message.length > 1 ? (message[0] << 8) + message[1] : 0;
this._closeMessage = message.length > 2 ? message.subarray(2).toString() : "";
this.ondebug(`Received close frame with code: ${this._closeCode} ${this._closeMessage}`);
if(!this._closed) {
this._write(message.subarray(0, 2), 8); // echo close code
this._closed = true;
}
break;
}
case 9: { // ping
this.ondebug("Received ping frame, responding with pong");
this._write(message, 10);
break;
}
case 10: { // pong
this.ondebug("Received pong frame");
if(this._ping) { this._ping.resolve(); }
break;
}
}
} else {
this.onmessage(opcode, message);
}
}
that’s more than a few lines
few lines i mean at least a few dozen
😵
i mean
depends what exactly you want to accomplish
if all you want is to see discord events flodding your console logs
then you can do it in about 10-20 lines
only 771 lines
yes
and thats only the discord api logic
it does not include websocker logic, nor compression, nor conversion
everything else is handled in other files
discordjs uses the ws package for the websocket implementation
ws alone is sevral thousand lines
because they have to support every single feature and quirk of the websocket specification
i dont
what’s the difference between Ws and http
so yours doesn’t stay open?
it does
ws is built on top of http
you start with sending an http requiest
and then you tell it to not close
without ws yes
in lays terms, water running from a tap continuously is a websocket, water in a cup is a served http request
ws is like an app built on top of http that specifically tells http not to close
http is the base connection for everything
ws is a style of using http
a normal http request is automatically closed after it finishes
a ws requiest specifically asks it not to close
it overrides the normal http setting
One message removed from a suspended account.
One message removed from a suspended account.
then there's a difference where u handle the cup or throw on their face
tcp vs udp
lmao
one asks you if you would like a cup of water
the other throws the water at you
LMAO
cry has been around here longer than you
why have I never seen them
i pop in here and there mostly when i get on to game a bit, but it's mostly been work lately
what's ironic is that my work consists of the one thing i hated the most; java
xD
i participated in a java mini course as an assistant teacher
safe to say it reinforced my idea that java is bullshit
:^)
was about to ask how'd that go lmfao, yeah expected
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
lmao
i was just trying to be an edgelord i didn't hate anyone fr 😭
I don’t get the hate against Java tbh
One message removed from a suspended account.
the course was about unit testing and stuff, so we went over java testing libs, integration testing with spring, cucumber, and stuff
One message removed from a suspended account.
that's good, mostly everything that's used in the industry
useful knowledge
especially because java is horrid without spring in large scale apps
it has so many cons but after yearsssss of working in all kinds of languages
it's all the same
One message removed from a suspended account.
your thought process is what matters the most not the language
funny enough, I find it worse with spring
One message removed from a suspended account.
One message removed from a suspended account.
ye
show us your block list
:^)
damn how so? it's my safe haven for the projects I've been working on
granted that's aimed at web so
One message removed from a suspended account.
why
i keep trying to send /s but the slash commands are getting in the way god what happened to this app
blocked
waaaay too much abstraction
what i didnt like about the course was that they teach the students spring with a very fixed mindset on mvc principles
the code is always split into controllers, models, views, requests, entities, services, etcc
yeah fair, it was definitely overwhelming when i first jumped into it
no why do u hate Java
daamn, mvc has its place but it's really not for everything, it hits you when you start to question yourself whether you just over engineered what you just built
One message removed from a suspended account.
i don't hate it anymore, but i do dislike the lack of proper generic support and things a normal person probably wouldn't care about
one of my main reasons way back was performance
but performance is irrelevant in the industry, unless you're making a game or something that requires squeezing every single point of performance out of your hardware
Gotta love you can access secret information on so many government websites just by searching intext:"ArcGIS REST Services Directory" intitle:"Folder: /" on Google 
you shouldn't concern yourself
what's funny is most of government websites are built on old technology and a massive amount of money is poured into maintaining that
which is fair, older tech leaves more space for refining
Government websites be using the oldest technology in existence
is JavaScript your favourite language
And they never bother using something newer
maybe because they don’t need to
i don't have a favourite language, it's literally all the same to me
⁉️
an 90% of the money ends up in some politician's pockets and not into the actual maintainance
adapt improvise overcome B)
so you don’t have a language you’d rather use over all others
hm ok
if i want a UI app that i can quickly write the styling and logic for, id go for js because of electron etc etc
They don't need to, but they should instead of just using something incredibly old that nobody really cares about, and imagine trying to find someone to maintain the said old thing if the current maintainers leave or get fired
Reminds me of this meme
but they aren’t going to because they don’t need to
I think they should focus on more important things
🧌
nah that's definitely changing, technology is constantly evolving and there should definitely be more care about keeping things up to date
we're slowly entering a new age of computing which leaves the doors open for all kinds of exploits and cracks
The backbone of the internet is likely mostly run by old tech barely maintained/touched because it all JUST WORKS LIKE MAGIC
Same with my bot's old code
Some code, I just had to copy paste
the government should focus on implementing an official Uber eats / doordash
I was on some shit 4 years ago
psilocybin and a long programming session is the new shit
what’s psilocybin
a topic mods probably wouldn't like me talking about :')
is it drugs
it's a psychedelic commonly found in shrooms, from personal experience microdosing it boosted my cognitive performance by a milestone
it's definitely not for everyone but i did notice the code I've been writing after a few months was extremely structurally sound
One message removed from a suspended account.
One message removed from a suspended account.
so it helps u code?
hey hey let's not mix natural and synthetic chemicals, but it's a nsfw topic for this server anyway xd
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
I’m not exposing my age to strangers on the internet
One message removed from a suspended account.
One message removed from a suspended account.
yes but he will get exposed as an immortal time traveler
they can
some people on the internet are crazy
One message removed from a suspended account.
the word subpoena implies the existence of a superpoena
the irony
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
damn, you got me
One message removed from a suspended account.
it’s true
Tim hasn’t blocked me
i unfriend scammers
they friend me out of nowhere, i accept to see what they want, they offer an amazing crypto oportunity, i unfriend
:^)
why would you not unfriend scammers
free tech support
sometimes I love to fuck around with them
wtf? 😳
1000% return always
but for some reason it always ends up in me parting ways with my own money
I updated my logo for my bot and I was wondering how to change the image on top.gg or how long till it auto updates
One message removed from a suspended account.
Fetching Your New Bot Data
To fetch your bot's new name or avatar, please follow these steps:
Click the Refresh Data button in the sidebar on the right.
Click Edit on your bot page and then Save.
💡 Please note: If it still doesn't seem to change, make sure you actually changed the bot's avatar / name on your Discord Developer Portal and not the application's icon / name.
thank you so much! seriously!
Where do you find your slash command Id
ah ty

I have a cache with a ttl of 15 seconds, now I also want to clear this using a cronjob every x time. How long should I put between clearing the cache? Every 5 minutes?
To clear the ones that exceeded the ttl
if entries are managing to exceed the ttl u need to either find a better lib or find out why it happened
ttl is supposed to be absolute, nothing should exceed it
I'm just using a js map
for js there's a lib called expiring-map
is it also for ts?
ts is js
find a supported lib for a ttl map if that one doesnt work
"certified" no longer exists, do u mean verified?
Seems to be working, thank you
in topgg or discord?
I have this C++ struct here:
struct Entry {
uint32_t f1 : 16;
uint32_t f2 : 16;
} __attribute__((packed));
members are defined by a bitfield size so both fields are 16 bits making it 32 bits, a size of a uint32_t
i wanna create them on the stack like Entry e; but the members in the struct have to be 0, this is very important
and I don't think I can use default initialisation here because:
i could always use a messy solution like
uint32_t struc = 0;
Entry* e = reinterpret_cast<Entry*>(&struc);
but wondering if theres a better way
You can just do:
Entry entry = {};
This uses the {} initializer to initialize the data members to their default values which in case of bit-fields is 0
This is called aggregate initialization
https://en.cppreference.com/w/cpp/language/aggregate_initialization
anyone got recommendations for fast image manipulation libraries for NodeJS? Thought about using node-canvas. Previously used node-canvas and JIMP, but didn't know if there were better options
depending on what ur trying to do, using an external application will be the fastest option
like imagemagick
cant get much faster than node canvas
Sharp is incredibly fast if all you do is resizing, converting, or slightly editing images (a lot faster than the other libraries) but it only has a small feature set and doesn't support all platforms
Node-Canvas is very good, there's also @napi-rs/canvas which seems to be faster than Node-Canvas though it's not yet stable as said by the developers themselves
So your best bet for now is Node-Canvas
If you want, you can make node-gyp compile Node-Canvas with ThinLTO which can also improve it's performance quite well
Will look into it. I do have some complex ops like masking so yeah
anything for gifs specifically?
I tried before and the processing times were extreme
gif is...terrible
Wish Discord allowed embedding animations of other types
video formats as seen on the gif feature doesnt work. apng doesnt work. webm/webp doesnt work
if webp even supports animation
as in no autoplay I mean by not working
to make it worse, discord technically does support apng but they've made it exclusive for stickers
Yeah
Imagescript
they used to support apng for avatars and people could get animated avatars without nitro, then they blocked that
shit was so dumb
I'll have to see how imagescript performs
It is really fast
is it just an encoder or?
I'm a wee bit dumb so im just going to: https://www.npmjs.com/package/imagescript
mmm does support decoding and encoding gifs, but it's a bitmap based solution
might be considerably slower than canvas
I'll see if there's any gif support for canvas through external libs/built in first
Whenever I've used it the time it takes for it to do the manipulation and then send the image in discord seems to be just about the same as with canvas
Well you can also use a different library for encoding/decoding GIFs and use https://www.npmjs.com/package/gifencoder to put them together in Canvas
Though it can be quite slow
how slow we talking
I remember making it take the user's avatar, and output a GIF with lots of frames where the avatar was being pet, a few of them were added to the discord.js server
Like

all image manipulation is bitmap based
bitmap is basically a pixel grid
It generally took 5-6 seconds to generate
Though note that it was making my bot come down to its knees because it's quite resource-intensive, make sure to do this in a different process or server unless you have a pretty beefy server
oh yikes
I mean. I have separate processes for stuff and I planned on shoving it onto a worker that didn't handle any important tasks like http or queue handling
unless it makes use of multiple cores, I won't have to scale servers just yet
Although that has nothing to do with the gifencoder library I mentioned, it's because of me doing quite a good amount of canvas operations
And as I said, you can compile Canvas with LTO (Full or Thin) to not only improve its performance but also potentially reduce memory usage
My encoding solutions would be quite simple. Just create the background and copy the base and stitch a frame of the user's avatar to it then push those to the encoder
Then you should be good to go

I also fixed multiple memory leaks in Canvas itself but a new update hasn't been released that includes those fixes
I have absolutely no idea, I fixed them a few months ago I think and yet no new releases
Could just build manually tbh
Though I'm not really sure if these memory leaks are on hot or common paths so you can just use it and update when the release is available
oh fair
What platform do you host the bot on?
You can run the following to compile with LTO (note that you gotta remove the package-lock.json file and the node_modules directory):
$ CFLAGS='-flto' CXXFLAGS='-flto' npm i
Though note that Ubuntu uses the GCC compiler and doesn't have the Clang compiler installed so you won't be able to compile with ThinLTO with GCC which is better than just GCC's LTO
Clang also generally emits better and faster assembly than GCC so I'd recommend switching to it
Yep
Thanks 
You're welcome 
show the error
...?
I could cry
how are u registering 'em?
It is sending
events in events is really really bad
even if it's once
Type error : cannot read properties of undefined reading 'FLAGS')
well if there is no other way`🤷
show an image of the error
Sec
there're location info in the stacktrace, to know where it happened
the leak is coming from when I do auto reconnect, without it it runs fine
Image sending
save the internal event to an outside variable
then close it inside socket close
Iam not really a very pro coder last time I coded 3 years ago iam just doing now a basic code urgently
here
whatever ur trying to do, you're tryng to use FLAGS.properties but FLAGS isn't defined in the scope
did you write the code yourself?
What should I do
idk, I'm still waiting for the image
I tried chat gpt but it is trash now ian struggling alone
don't use chatgpt for fixing code, it doesn't work
chances are you'll just add another error to it
Also iam using prefix bcz slash always shows errorsi worked like 6 hours it is only 4 commands
did you write that code yourself?
interesting, I thought each of those were always a seperate instance
it seems to work
you're not supposed to be using the socket event
hm?
sockets can be reused under the hood
they are separate, this is why it's leaking (ur creating a listener but not closing it)
listen to the response event instead
thanks
Yes
uhhh
it doesnt seem to reconnect anymore actually
this is my current state https://pastes.dev/niBpXAaqzQ
why are you using socket and not response? if you wanna handle raw http might as well use the tls or net modules
I dont want to mess with http/ssl boilerplate
well, i dont see why it shouldnt be reconnecting
seems like the events arent firing
shouldnt need to manually destroy them tho
ah
well
the right way is to attach an end event to the response
but you dont use response
even that isnt firing
ah no
wait
it doesnt fire if the server was never online
makes sense
but how can I still make it reconnect in that case
if the connection did not succeed, the request should emit an error event no?
nope
although close should also be emitted regardless
wtf
its spamming the timeout event like crazy
even though im connected
im confused
@_@
just use a tls socket
you dont need to setup any ssl stuff
you're not a server, you're the client
it turned out to be me not doing .removeAllListeners() (?)
anyways that was just a test to try to even get anything working, now for the hard part I want to make that browser and node compatible, the current solution only works with node
@lyric mountain here it is
Show what's in index line 3
I suppose that's where ur creating the bot client
If so, don't blindly copypaste the example code
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
What
Type Intents. then press ctrl space
Variables are case sensitive
FLAGS is not equal to Flags or flags
Whatever that lib uses
@quartz kindle do you know what the best way to get this working in browser & node would be? for some reason EventSource is just not working (probably because I am still not sending proper sse)
flags.guilds ?
^
Let the editor tell you what you should use
We don't give copypaste-ready codes here
We show u the way, and help with questions
Doesn't make sence for 2 words
If you're making a bot you need to get used to reading the documentation, discord.js even gives u guides for popular topics
Then u didn't read
Don't jump to the code, read the context
Just download bot from github at this point 
https://i-am-a.dev moment
Bruh 2 words took 6 hrs lpp
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Search for Client
I guess it isn't the issue
NONE works
I've used docs ones
Still same error presist
Djs?
Yes
Why didn't u use npm?
I did use npm
Npm install discord.js@latest
I sent this or simillar one
I dont rmember
Ok anyways what should I do with rhay
That
Let me chrck
Idk I didn't install smtng like that
U don't edit packages manually, but everything u install with npm is listed there
My issue is just with 2 word
i wouldnt know really, never used sse, but id try to understand what exactly is the sse sending so i could emulate what the browser does with a node client
by logging raw tcp packets
for example
Thing is, if u read the docs I sent and it still doesn't work then it's likely version mismatch
Try starting the bot without any intent
Will that work
intents are required since v13, if it works it means hes using v12 or lower
I'll do that tomorrow it is 1:12AM iam so tired I spent 6hr trying to do it
Always check the docs if you're struggling
Trying to guess properties or methods never works well
And as long as it might be, usually the issue is solved within minutes
If a pc user got invited to my repl he can fix it?
Anyone free here
lmao
Also having someone else do it for you will do no good for u
Not code just a button to click
plus if you want to learn, then don't have other people write code for you
Because iam not on pc
You'll still don't know the issue, so you'll be always dependant on someone else
I just need sm1 to click ctrl+ space
Quick dip on the docs will solve it easily
To chrck
Just to select the option
does replit even support auto completition in the web editor?
I think so
yes
fancy
I'll try tomorrow iam tired that bot is so important to finish
Did u even code the rest of it already?
Then yeah, u didn't code the bot
copied from somewhere?
No airpurple did them for me
Wherever u copied it from, see if there are no instructions on how to configure
Why didn't they fix that?
also make sure the code is compatible with the discord.js version you installed
That's my cousin he said I can help last time I coded a powerfull bot in 3 years before I retire but my team scammed me
Stole codes and made different bots
Well...
lel
Don't ask me he said replit sucks
I also didn't use replit it always show useless things
Also their is nowhere to copy or clone the current bot source iam doing
I dont think anyone did this idea yet
Doubt it, but most bot repos are private anyway
If ur afraid someone might steal the code it's best to not invite anyone to the replit
Actually, does replit still allow private projects?
No it is not important codes it is just announcements:
Additem ( name info photo)
Checkitem added by botadmin
Promote and demote user pwrms in using the additem command and updatechannel wheir it send new item added onfo and photo etc
Not for free
the link I sent has the full example on setting up a bot
but given u had it called Intent, I'm afraid ur code is outdated
yep
it's for version 13
if u installed djs with npm then you're on version 14
so it wont work
may I say, in that case FLAGS is not your only problem
or u can uninstall djs and force version 13
How
but then you'll be on the line, as version 15 is releasing soon
so v13 will be the next to be abandoned since v12 goes down when v15 releases
Can't I just work on 1 version those new versions are annoying qf
issue is discord updates a lot
so they need to make new versions to include those changes
Oof
(tho d.js devs don't really need to completely rewrite the lib every update)
Online ai can't update codes?
so there are two choices
- revert to version 13 and live with the risk of eventual breaks
- refactor code to be valid for version 14
nope
galaxygate, hetzner and contabo
only know those 3
that's the life of a programmer
code that never needs to be maintained doesn't exist
it's the philosopher's stone of coding
Shouldn't they do ais for that
ai cant solve everything
It could
nah, they simply can't read your mind to be able to write a code that maintains the exact same functionality
don't be lazy, eventual refactors are commonplace
I have tons of thing to do I mean can't they translate
me too, still on it for a year already
buddy, look, there are no shortcuts, simple as that
get ur hands on the dough and start shaping that bread
I was building my dream bot when I got scammed and now I just need a small bot for a hobby
Idw to put effort on smtng small each time I do I remember how huge my project was and I feel pain
if you want to own a discord bot, then you will have to maintain it as well, its part of the job.
you will make code for one specific version, then when there is an update, you need to check what was updated, and check if those updates affect your bot, and if they do, you will have to adapt your bot to the new versions, or stay in the old version and risk your bot breaking at some point
thats what being a developer means
Yes but it hurts me anyways now ill consider my small bot my new baby
accept the previous bot is gone and move on
It had everything
It is like mee6 and Carl combined
Anyways now I have a new baby
😁
I'll start from tomorrow
good luck!
Thanks
paradigm cycle:
you start writing a giant procedural shit
rewrite everything into classes because oop is cool
realize you made a huge mess and is a pain to maintain
rewrite everything into small functions and go functional style <- this is where i am now lmao
I don’t get the point of classes
just use normal git, or the one included in vscode
so I’m switching to gitlab
lmao same
LMAO U REALLY THINK GITHUB IS GIT

it is basically
be it github, gitlab, bitbucket, svn, whatever, if you don't pay attention to what ur doing the same will happen again
it's the same as car and carpet
lmao again
git is a versioning system that manages files
github is a platform that hosts files for you and uses the git system to sync them
gitlab is also a platform that hosts files for you and uses the git system to sync them
for context tim, e0c resetted his entire 4-day uncommited project
rip
tbh i also have a giant backlog of uncomitted stuff
but i have a second backup on google drive lel
I commit after every single time I leave the keyboard
well,
i dont
lmao
danger boy
also
tiny-discord
havent worked on it in months
sometimes i change a bunch of stuff, then leave it shelved for a while
when i go back to it i have to relearn wtf did i change and why
and i dont wanna commit because many changes are not finished so the code is pretty much in a broken state
don’t
GitHub desktop deleted my bots rewr it e that took days to make
well then that happens its likely because you did something wrong
and also, i have a backup on google drive
yeah right
bro I clicked commit
then all my code reverted to old code
probably did you a favor
Lol
well rip, idk what happened but that is not normal
it never happened to me
but in any case its good to have backups
i have all my projects in a folder that autosyncs with google drive
@hushed robin status update?
blocked 👍
oh, i know how to revert code after a git commit
how do I fetch a message in discordjs
channel.messages.fetch(id)
but
what if I wanna
fetch from any channel
do I need to looo through all the channels
messages belong to channels
there is no way to find messages if you dont know the channel
also there is no way to search through messages through the api
discord does not expose the search api that we have in the discord client
so in conclusion I need to
by what criteria are you trying to find the message?
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
nice
by message I’d
link soon™️ maybe?
if you're storing the message id in a database to fetch it later, you need to store the channel id as well
make the text typing thing better
One message removed from a suspended account.
One message removed from a suspended account.
no
by id only
not possible
it is
One message removed from a suspended account.
woah, alive for 37 months
define "all" channels
surely not "all discord channels in all servers ever"
yea
One message removed from a suspended account.
Yes because that’s so much easier and more efficient than storing an extra bigint in a database 🥰
One message removed from a suspended account.
SQLite doesn’t have binging
It’ll be funny if someone uses that feature on a server with hundreds of channels
Enjoy your ratelimiting
it’ll be fine
Famous last words
One message removed from a suspended account.
enjoy trying to guess channel ids as well
I do
I’m not
Much more than I could do 😭 I hate frontend
I will just loop through them all
there is no way to list all channels in discord
One message removed from a suspended account.
there is
from a server yes, not for all discord
client.guilds.cache
thays for a server, not for entire discord
and in the very least you need to know the guild id
well ofc I’m not going to check the entirety of discord
If my bots isn’t in the server it can’t edit the message anyways
lol
so if you already need tje guild id along with the message id, why not add the channel id
I don’t need the guild id
client.guilds.cache will give me all of my bots cached channels in all guilds
which since I have the guilds intents it will be all of them
so instead of searching throight a couple dozen channels you want to search through thousands of channels
got it
Who the hell at GitHub fucked up the C syntax highlighter 
Smartest battleless solution
Next question: who the fuck is writing code like this?
good luck having your search be stupidly slow and cause rate ljmit errors
technically it will only be about 50 max
since this bot is only for my server
50 is a lot when you’re fetching
Could literally save yourself a ratelimit nightmare by just saving one channel ID
It’s not that hard
You’re acting like it’s rocket science
but that’s an extra value for the person to add
there is absolutely no reason not to save the channel id
I’d prefer a more user friendly experience
That's the IDNA code in libuv, it's written by one of the best C programmers in the world, if you're talking about the formatting that's because of GitHub Mobile
huh???
I meant the variable names mostly 😭
wym friendly user exoerience, how is the user chosing whicj message to save?
Oh fair 
bc they can pick whichever one they want
so whayever message they picked, save its channel id as well
the user doesbt need to tell you, you get ir from the message
bru
u just said I can’t fetch a message without the channel
they user will provide the message I’d
you want the user to give you a message id ?
thats not very user friendly eitherway lol
😐
its more user friendly if you ask for a message link for example
Can you even copy message IDs without developer mode on?
since the user can just right click and copy message link
Nope
the nessage id you only get with dev mode enabled
a lot of users dont know how to get it
hm true
maybe I’ll just scrap this totally
Good idea 👍
last part of the url is the message id
Well yes but the average user doesn’t know that
yeah because discord users aren’t smart
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
old looks better
Probably a bad idea to help you in an exan
exam
Figure it out yourself, if you can't, keep a note of it and try to learn about it
you could
hm
why am i getting Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
if (!queueData.channel || !queueData.message) return await interaction.followUp({
content: `The queue message has not been sent!`,
ephemeral: true
});
the interaction should be a new one I believe
it would not work if you reply, and then do a follow up under the same interaction
then wtf is the point of it
how do i add a user channel permission in discord.js
nvm
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({
intents: [Intents.Flags.Guilds],
});
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
if (commandName === 'addiots') {
const name = options.getString('name');
const info = options.getString('info');
const image = options.getString('image');
// Your code to add the iots with the provided information goes here
await interaction.reply(`Added iots: ${name}`);
} else if (commandName === 'checkiots') {
const name = options.getString('name');
// Your code to retrieve information about the specified iots goes here
const embed = new MessageEmbed()
.setTitle(name)
.setDescription('Some information about the iots');
await interaction.reply({ embeds: [embed] });
} else if (commandName === 'updatechannel') {
const channel = options.getChannel('channel');
// Your code to update the channel for sending iots information goes here
await interaction.reply(`Updated channel to: ${channel}`);
} else if (commandName === 'addpress') {
// Check if the user is the owner of the bot
if (interaction.user.id !== '1002843443992743996') {
return await interaction.reply('You are not authorized to use this command.');
}
await interaction.reply('Press added successfully.');
} else if (commandName === 'addadmin') {
// Check if the user is the owner of the bot
if (interaction.user.id !== '1002843443992743996') {
return await interaction.reply('You are not authorized to use this command.');
}
const admin = options.getUser('admin');
// Your code to add an admin goes here
await interaction.reply(`${admin} has been added as an admin.`);
}
});
client.login('');
Those should be now done
Now time to read
So much work but really happy with the outcome :)
what’s this
profiles
for what
my bot??
what’s your bot
nice
what version of discord.js r u using
V 14
well
that’s v13 code
Intents is now GatewayIntentBits
and MessageEmbed is now EmbedBuilder
Those all I need to replace?
yes
Okay I'll do them and send
GatewayIntentBits.Guilds instead of Intents.Flags.Guilds
yea
Thabbbkkks
then u need to change MessageEmbed to EmbedBuilder
and it may work
idk though cus that’s v13 code
you still may need to update some parts
u need to require GatewayIntentBits from discord.js
Like
like 😋
const { Client, Intents, EmbedBuilder, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds],
});
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
if (commandName === 'addiots') {
const name = options.getString('name');
const info = options.getString('info');
const image = options.getString('image');
// Your code to add the iots with the provided information goes here
await interaction.reply(`Added iots: ${name}`);
} else if (commandName === 'checkiots') {
const name = options.getString('name');
// Your code to retrieve information about the specified iots goes here
const embed = new EmbedBuilder()
.setTitle(name)
.setDescription('Some information about the iots');
await interaction.reply({ embeds: [embed] });
} else if (commandName === 'updatechannel') {
const channel = options.getChannel('channel');
// Your code to update the channel for sending iots information goes here
await interaction.reply(`Updated channel to: ${channel}`);
} else if (commandName === 'addpress') {
// Check if the user is the owner of the bot
if (interaction.user.id !== '1002843443992743996') {
return await interaction.reply('You are not authorized to use this command.');
}
await interaction.reply('Press added successfully.');
} else if (commandName === 'addadmin') {
// Check if the user is the owner of the bot
if (interaction.user.id !== '1002843443992743996') {
return await interaction.reply('You are not authorized to use this command.');
}
const admin = options.getUser('admin');
// Your code to add an admin goes here
await interaction.reply(`${admin} has been added as an admin.`);
}
});
client.login('');
You need to register slash commands read the guides on discord.js.org
I didnt really understand how to register a command
It require coding or something else?
Just a little bit of rest request
Pretty explains every step thoroughly
@earnest phoenix so in my index their is the codes for slash commands (string roles user etc....)
So i need to create commands folder and add for example addadmin. Then what to do
The codes of it are in index
Iam not professional sorry if they are dumb questions
Take the lines of code belonging to the specific commands and convert them to slash-commands, and separate them to different files like shown in that guide
They are already slash commands so I skip the convert thing ?
Sure, then put them in different files in that commands directory that you've got, and follow the instructions outlined in the guide
Okay
@earnest phoenix iam testing it only on addadmin rn and still not showing I've moved codes to addadmin.js in commands file and placed this in index :
client.commands.set('addadmin', require('./commands/addadmin'));
I added deploy command and file
const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9'); const { token, clientId, guildId } = require('./config.json'); const commands = [ require('./commands/addadmin'), const rest = new REST({ version: '9' }).setToken(token); (async () => { try { console.log('Started refreshing application (/) commands.'); await rest.put( Routes.applicationGuildCommands(clientId, guildId), { body: commands }, ); console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error(error); } })();
I also added config.json
And the command still not showing
2 things
unless you want to eventually lose your bot, put token in replit secrets, instead of a plain json
and u don't need to create another client, or should, simply pass the client to the commands
I've formatted that code, no idea how you're coding like that
there's an error on the commands line
Are you gonna tell him? 
Their is not error in my thing
if the code you sent is the full code, then yeah there's an error
It is not
const { SlashCommandBuilder } = require('discord.js');
if (commandName === 'addadmin') {
// Check if the user is the owner of the bot
if (interaction.user.id !== '1002843443992743996') {
return await interaction.reply('You are not authorized to use this command.');
}
const admin = options.getUser('admin');
// Your code to add an admin goes here
await interaction.reply(`${admin} has been added as an admin.`);
}
Here for addadmin in commands file
And for the index I placed the first code line In this message
And here for deploy