#development
1 messages Ā· Page 2067 of 1
If only I could do something aobut the memory leaks haha
and back
V8 does actually care about size a lot, but that's as much as it can give it care when it's doing everything on the fly
It's pretty complex in simple terms
wont even ask about objects š
but apparently this means it's pretty much unsolvable
@rose warren how do you record your bot's data? like how many users use slash commands vs message commands?
tbh most of the complaints about java gc are programmer's fault
like holding references hostage or forgetting to close streams
V8 has become so complex that even us maintainers of it get confused sometimes
Just listen to the command calls and slash command interactions and use a counter in your database
Which reminds me...
doesnt v8 use SMI for small numbers? those only take 1 byte
Time for June's adoption figures... š
What can you really say when the entire thing is almost the size of the Linux kernel
a different collection just for 1 document? 
or new documents per month
You know something is incredibly complex when they designed a language just for use within that project
by the way is js supposed to start acting weird when the memory usage is very high (like 4gb+)
Although there are a few different projects that do that
You simply record (un)successful executing in your event no matter itās a message or interaction event
Yeah, it depends on the number's size, switching between types and such
End of June: pretty much 50:50 adoption rate amongst 25k active command users this month.
Woah I find that really surprising
Are you doing something to urge them to switch?
I think more users are just finding out about slash commands. Theyāre actually pretty convenient to use compared to message commands
Nope. Users on slash have exactly the same user experience as users on prefixed commands. I'm just kinda promoting slash as the default prefix but not a lot.
Guarantees you donāt mistype something about the command
And this ^
Weird how?
i disagree, but that's alright
Or mixing any arguments at least in their order
Where do you use which and what's the difference between <type> | : type? I'm still confused about this.
if i remember correctly a bot i used to run sometimes used a shit ton of ram per cluster and that caused the node process to sometimes freeze completely, or at least parts of it such as connections, so the process would log and work but connections would just completely freeze and everything becomes very weird
the freezing isnt only temporary, that i would understand considering the gc is trying not to die
Think about it this way, instead of having 30 different -optionFlagName toggles that you have to use a help command to find, you can use boolean options and explain what they do in the description field
I prefer slash commands by far. If I were to make a new bot tomorrow I would go 100% slash.
Makes it a lot easier for the average user that doesnāt want to spend 30 minutes shuffling through a help command just to do something in a command
Same
the problem here is discord, most of its numbers are 64 bits wide natively
meaning must store as string
Not to mention itās so much easier to verify user input on the developerās end because most of it is already done on discordās end
nice graph I wonder if I'm seeing similar? last I checked a lot of my users were continuing to use prefix commands
Yeah I see an advantage there of course, it's pretty good the first couple of times you use the command
I've done nothing to force them to move over, just changed the docs and help to refer to everything with / on the start instead of !
I wasn't sold on them in the beginning but after rewriting my bot and being forced to test them and use them I actually prefer them now. They're much easier as a user, they save time, they're easy to type and select, and when made properly by the dev, they guide you through the required parameters which means there's less of a chance of a user running the command incorrectly or struggling to read through documentation to figure out how to use command options.
Same. My slash commands run off exactly the same files as my prefixed ones.
I suppose either the gateway refuses to continue the connection for some reason that may relate to either the process not responding back due to the event loop being frozen, either because of too much memory usage above the set max memory space, or something related to the libraries used to do the connections, whenever you did that; it's probably fixed now or someway, if it's not then it's probably the first case
But once you know how to use the command that benefit is gone and where I am from most users are used to multi-flag commands
formatting is very nice too
But if you use the -prefix, the bot will show you the -prefix in the response (like in the help menu etc) and will respond using your preferred prefix. I'm really not forcing them at all.
forcing inputted data to be formatted
aka user input MUST be a valid user or user id
Maybe they have changed slash commands since then, but when I tried them, getting the user inputs was really painful
They've gotten a lot better recently
But still are missing a lot more possible input types as well as different field types in modals
like search the array of options... When they could just have sent them as keys in the object...
nah its not that bad
Yeah once we get more input types they'll be super pog
hit ratelimit 548 times today according to sentry
Or sub command nesting which is on the list since the beginning 
My bot has a habit of getting fucked up on weeks I'm too busy to fix it
mine got really fucked up last week for about a week
never had such an issue

Can slash cmds get attachments yet?
Multi line input when :c
wait no its in djs but undocumented iirc
Only in modals sir
My clusters are dying for no reason and my voting manager which has worked for MONTHS without issue just stopped working on my VPS at lunchtime. I spun up an instance of it on my laptop, tested it and it worked.
Also Iām gonna make a new bot soon, does anyone recommend anything like error frameworks, etc to put on it? Heard sentry is good but never tried it
made that command for the Anti.fish server, discovered drop downs so thought I'd impliment it
Me fixing bugs this week
https://tenor.com/view/flex-tape-gif-10921536
that's a bacteria sir
(Iām using detritus)
They said they're gonna implement that once they're done with the slash-commands UI redesign, especially with the argument inputs as pills now, but the redesign seems to already be done
Still no multi-line inputs, classic Discord
What bot are you going to make 
sentry is great
by Ian
Idk still thinking
Gonna make it alone tho sorry babe š
.catch(err => {})
The other 100 unhandled errors:
nothing better than ol' trusty .catch
Just await every promise and you wonāt need it!
Fr
Some new emojis or nitro variants first, priorities Sir!
Discord is going into direction money > user... tbh
Nah that's not true... Back in like 2019 they were making fast stuff for users and not only focusing on nitro updates
I didn't say they shouldn't focus on money at all. But not ONLY.
Sad times weāre living in
Well I kinda disagree then. Making slash commands and new interaction methods for bots is giving the dev community a lot of love they deserve. Up until now, bots were glorified user accounts really, just listening to messages.
I understand that a company needs to make money and pay their bills etc. and nothing to say against that.. But you notice if the company starts to only focus on making more money and actual user updates come second
Automod, forums, threads, new bot interactions... Even more in data mining.
yes yes ofc slash commands are a great improvement and they do bring updates.
It's kinda unfair to say Discord are only focusing on nitro
Well about automod you could argue that they replace some successful bots that their base is automod etc.
If they would only put a little bit more effort into this especially delivering needed stuff instead of dealing with the crying large library developers trying to suck their dick
I want to say I've notices in the alst 3 years I'm using Discord they started focusing more on the money, still they also bring new brilliant features for the community and devs.
you shouldnāt forget there are always different teams dealing with different jobs, while nitro features may have become more and more that team probably has no clue how to deal with api features
An artist is creating new content not going to build the backend
Also to be fair all that nitro shit is mostly just cosmetic stuff nobody actually needs
And has a specific age of people as target
.catch(() => null) this is how you get rid of errors
lmao
any idea how to fix [object Map]? when I try mapping it it just turns to [Object object]
nano /dev/null 
That command gives you a +200 in social credits
Donāt try this at home, it will explode immediately
you are likely trying to show an object in a string
yeah.. do I put it in a variable then instead?
Well what exactly are you doing first
cause I am not going to just guess what is happening
just trying to freaking map / put all the users into an array who reacted to a message
but I'm having trouble
isn't joinedUsers already a array?
no idea, it returns object Map by itself and when trying to map it it returns object object
Wait if I remember correctly this is the handler function for your collector right?
this is what joinedUsers it
yes
so joinedUsers is a collection which extends map
so ofc it will look like that when trying to use it out right
okay that makes sense, how can I fix it?
I tried boxing it into a promise and resolving nothing seems to work
you could use .join on joinedUsersMap as it is now an array
let me try that
not necessarily, i mean, bigint in v8 is much more memory-friendly than a string representation of the number
and you can always offload you cache to somehting like lmdb or redis which can store them as native 64bit ints
still returns object object
Just log your var and see what its structure actually is
you mapped it so now it is an array of user objects
map it so it only returns what you want it to ig
that code doesnt make much sense, why are you awaiting collected, then doing collected.size?
and not awaiting endFunc, which is the thing that should actually be awaited
cause checking size doesn't need awaitng as in, for some reason, from what everybody is telling me, to get users I need to do some weird awaiting, mapping or god knows what

promises dont even have a .size property
well it works so I won't question it
that collected.size returns the size of the reactions
meaning how many people reacted
I'm not structing it
if it needs to be awaited, it doesnt have .size
if it has .size its not a promise so it does not need to be awaited
it's what discord.js returns
then what am I doing wrong
I just want to display all the users who reacted
to a message
why is everyone making it out so difficult
.map also does not need awaiting
you are seeing [Object object] because joinedUsersMap is a Map/Object/Array
you cannot convert that to a string directly
you need to either JSON.stringify or join into a string
I'm doing that
but joinedUsersMap is a map of joinedUsers which is the collection
so if he just .map(e => e) doesn't that just turn the contents into an array. So it is still an array of user objects
exactly, that map is not doing anything
its a collection of objects, so joining objects will implicitly convert them to [object object]
you can map for specific things though like .map(e => e.username) or smth along those lines
you need to map into something actually useful ^
Just log your var and see what its structure actually is
I said this for a reason
If people see the structure of their vars they may understand what they have done wrong
FakE this guy is notorious for not doing that kind of thing
its talking onto deaf ears
I know 
It is sad when Team Snapchat is the only one to message you š
oh yea
(trying to explain)
nah that is just tim as soon as he walks into development
fuck am I talking about general

ban soon
which var do you want me to log?
joinedUsers or joinedUsersMap?
well you don't need to log any anymore as we already told you the issue
map the info into something useful
not into itself
I told you to log it before they explained what it is to see yourself what structure this var has
bro I don't know what you mean by "map the info into something useful"
can you please just tell me how to get all the users who reacted to the message
you already have all the information you need
you just need to turn it into something that can actually be used
map the user names as you want them or not?!
which if I might add
I already told you here
Ah there we go
you have a map of user objects. a user object contains many things, for exampe id, username, avatar, etc
you need to specify which part of the user object you want
thats what we mean with "remap into something useful"
If you donāt and map the entire object (item) the result is the same as the array youāre trying to map in the beginning
show
cod
oof

if that is showing null, that means those are not even users
what exactly are you collecting?
I'm collecting freaking reactions, and trying to get who reacted out of them...
Is this the same collector like the last discussion?
like literally trying to take all the users who reacted into an array map or anything I just want them stored
yes, but I've stopped cause I was angry at it
why can't nobody just tell me straight how to store users who reacted to a single message
I mean people can spoon feed but arenāt there like 1 million examples out there how a reaction collector works?
Iām sure there are
no I've literally been browing google for shitty examples that don't work or explain anything
show your collector code
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
it was formatted better before I just changed it to a code an other guy who tried to help me gave me
it didn't work either though.
ok there are a few things that are wrong
users and reactions are separate things, im not sure what djs's collected returns on the end event, but i assume its only the reactions and not users
so the safe way would be to collect the users in the collect event
simiarly to how you are counting the number of users
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
so something like this?
I wanted to do that from the start but someone said that's not how you do it
jesus christ
well dont blindly follow people and try to read docs instead
and console.log your variables so you dont do it blindly
yeah I should've done that

if I have picked a word how can I slice it into individual letters to put into an array?
ok that will probably require doing some math
if I have a word and split it into _ using .repeat
startingEmbed.addField("Letters Guessed", "_".repeat(wordToGuess.length));
how can I replace the specific letter if guessed instead of _?
TypeError: Cannot read properties of undefined (reading 'awaitMessages')
const startGame = async function (joined) {
const peoplePlaying = joined;
const wordToGuess = possible_words[Math.floor(Math.random() * possible_words.length)].toUpperCase();
const lettersToGuess = wordToGuess.split("(?!^)");
const startingEmbed = new MessageEmbed();
startingEmbed.setTitle("Hang Man");
startingEmbed.setColor(commandColor);
startingEmbed.addField("Current Players", peoplePlaying.join(", "));
startingEmbed.addField("Letters Guessed", "_".repeat(wordToGuess.length));
const startingMessage = message.channel.send({embeds: [startingEmbed]});
const filter = (reaction, member) => peoplePlaying.includes(member.user.username);
const collection = await startingMessage.channel.awaitMessages({ filter, time: 180000 });
const replaceAt = function(text, index, replacement) {
return text.substring(0, index) + replacement + text.substring(index + replacement.length);
}
collection.on('collect', (msg) => {
if (lettersToGuess.includes(msg.content)) {
const msgIndex = wordToGuess.indexOf(msg.content);
let newGuessedText = replaceAt(wordToGuess, wordToGuess, msg.content);
const startingEmbed = new MessageEmbed();
startingEmbed.setTitle("Hang Man");
startingEmbed.setColor(commandColor);
startingEmbed.addField("Current Players", peoplePlaying.join(", "));
startingEmbed.addField("Letters Guessed", newGuessedText);
startingMessage.edit({embeds: [startingEmbed]});
}
});
}
any ideas?
.send() has to be awaited
getting? typeError: Cannot read properties of undefined (reading 'username') now?
this line: ```js
const filter = (reaction, member) => peoplePlaying.includes(member.user.username);
Because thatās not the filter
The filter for awaitMessages is only one parameter, a Message object
can I do m.author.username then?
doesn't appear to catch any messages
am I doing anything wrong?
looks quite cool already not going to lie tho
hopefully I can get it working
doesn't have to be, but it does return a promise ignore me

Ima just go back to learning python
awaitMessages does not return a collector
you cannot use .on("collect") on it
awaitMessages is a simplified collector that returns when the collector ends, its the same as returning the value of the end event in a collector
oh then what can I do to keep collecting messages indefinitely until the time ends?
Doesn't the normal message collector do that?
define "normal"?
just don't give it a max
I thought this was the only one
ofc not
what's the other one?
the more you talk in this channel the more I realize you never read documentation
When I used djs I only ever used createMessageCollector
so idk if awaitMessages can already do what this one does so you might not even need to use this one
but it is an option if you wanna handle the data yourself
yeah this seems to be what I wanted
lets see if it works
hmm still doesn't appear to collect any messages
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
any idea why this collector doesn't work?
can paste letters nothing ever updates
the boomers would, fstring only exists in the newer python (3.6), so oldies might still use that kind of format
nothing, the embed just sends and doesn't update when you type the correct letter
yikes
question
can't you just include your lettersToGuess logic in the filter
actually nvm
I am dumb

Neither do I
haven't touched djs in ages so can't really help when it comes to collectors
lol
just when I think I found the answer my VPS getting ddosed
š
I am officially deceased
lock the ports ez pz
but really, you shouldn't have unlocked ports without any authentication or safety layer
somehow the replacement doens't work
it just gives the correct char first and then the word u were supposed to guess
man yall really send messages to your bot through discord to test your business logic like this?
must be an excruciating development cycle
Imagine wasting all the identify sessions just to test your hangman game
tbf unit testing a discord bot is annoying and hard
you should still separate your business logic from the discord mess though, at least make the testing a tiny bit easier
What you want people to emit messageCreate events?
why involve discord at all?
you don't need discord to play and test the business logic of hangman
I mean true
Set up tests for the logic of your hangman game instead
It can be easier in some cases
instead of messing around on discord constantly restarting and reconnecting your bot. Go write a test and keep changing stuff until it passes. By the end you'll have a working test suite instead of a channel with 800 spammed messages
Personally I donāt do this but for the next bot I make Iāll probably end up doing that, would save a ton of time
Once you have the logic of your game, then you can move to the logic of the bot š
doing functional programming really drills this concept into ur brain since your life becomes so much harder when you don't do it this way
Tim you are literally the js interpreter though
idk what ppl have against unit tests tho. It's literally faster to test than sending messages on discord
setting up jest is a pain in the ass that's true
Because itās annoying to set up your logic separately sometimes and some people just want to see how it looks in discord
I mean the discord part of things is the smallest portion
most of what you're dealing with is business logic
you know the backbone of the game literally being discord I don't think I really can test it without it :]
I like to see what it looks like in discord, if you do a command 30 times testing it then you can make design choices on how to make it more usable/enjoyable
sure but then you send like 4 messages instead of 480
you absolutely can. You just need to not tightly couple your game
if it's intended for discord why would I try making it work without it just for the purpose of testing
it will take twice as long to code and test
even if the game logic works flawlessly integrating it to work with discord afterwards also takes time
not as much as making the game itself
I still have the error but I decided to continue with the game tomorrow
can't be bothered to finish
give it a shot sometime, you might be surprised at how much nicer it is to work with raw data instead of coupling to discord
I get what you mean, I've done other projects besides discord bots, but I won't since it's kind of a waste of time in the long run

yes, it may be a little easier to make that, but it will take a longer time
so what will you pick?
i mean idk it sounds like you wasted a lot of time dealing with discord related stuff already 
you're not writing more code, just decoupling stuff
how do i check for user permission from a interaction
there should be a .member prop on the interaction you get back
with that you can access their permissions and do what you will with em
py-cord slash commands do be kinda cool tho
š¤Ø
What waffle
just donāt ask
Idk man, blood sugar too low to think rn
isn;t 55 very low
how you not die
Got lucky
Common guy has literally no clue about this if thatās high or low
That is why I asked FakE
Lemme answer with
smh

Normal humanās blood sugar usually ranges from 80-140
My average blood sugar for the past 3 months was not good, 262
oof
I have no clue too thatās why I wrote this (to Waffle) dingus

well there was 2 people talking boomer
This is my blood sugar in the last 24 hours, red line is below 80 and yellow line is above 180
Looks weird
It literally all looks black and white to me
Zoom in my gosh
My dude you are colorblind
I see black dots and a big blue rectangle going across the screen
I see red yellow and gray
Bruh tf is up with discord
It doesn't show the colors (veryy very dim btw) until I go to take an ss
Probably your bad screen not discord
Are you talking about me having bad eyes?
fucking auto correct I should stop talking about blind people

@wheat mesa I went through an entire 2h crash course on python I think I got the basics

Better forget it all, quickly
nobody needs python
no u
Wait until they make a minor release that breaks everything
who
what
based opinion
misty using python? š±
Yes
time to rate your indentation š¤
i have a function which use instagram oauth and it works well but as soon as i use it inside of a express .get() event it starts to give errors
does anyone have idea about it?
app.get("/", async (req, res) => {
var code = req.query.code.toString();
console.log("CODE", code)
getAccessToken(code)
res.send("<body></body>")
})
const getAccessToken = async (code) => {
axios({
method: 'POST',
url: 'https://api.instagram.com/oauth/access_token',
data: qs.stringify({
client_id: '',
client_secret: "",
grant_type: 'authorization_code',
redirect_uri: "URL",
code: code.toString()
})
})
.then(function (response) {
console.log(response)
axios.get("https://graph.instagram.com/me/media?fields=id,caption,media_url&access_token="+response.data.access_token)
.then(async (response) => {
console.log(response.data)
})
.catch((e) => { console.log(e) })
})
.catch((e) => { console.log(e) })
};
instagram oauth is getting annoying if anyone have experience using it will be appreciated
shut up fake
I wouldn't show your client secret
š„ŗ thanks
Its just im trying this for 3 days and it's keep on getting irritating
https://sourceb.in/eITrejT74a, just wanna try about connecting 2 js files using discordjs, but how do I call the async execute for client, message, args, prefix on my levels.js?
I want to repleace a word with a letter but keep everything the same. how
word = hey
replace e with i
word = hiy
how can I do that?
but not by text since wordToGuess is just a bunch of _ _ _ _
but by position of the char
so
word = hey
replace 2nd char with i
word = hiy
HOW
TO
DO
THAT
?
keep your string as an array and join it when you need to display it
any idea why this doesn't work?
only works for one letter then breaks
tries used doesn't even count itself for some reason
:/
Yo misty, do you think checking all array for one item is possible?
I am
if wordToGuess contains the letter, increment choice and if more than 6 choices kill the game
is that not right/
it ony works for 1 letter then stops accepting any others
plus it doesn't seem to count the wrongChoices even though it's clearly there
ever seen a 19kb hangman game 
the code is a mess
Even though you increment wrongChoices you do know you have to edit the embed right
I am
do you intend to replace the _ value to array value?
no, I just map it, not replace
so after the one word
collection.on('collect', (msg) => {
const guessedLetter = msg.content.toUpperCase();
// Checking if the leter includes the any of the correct letters
if (lettersToGuess.includes(guessedLetter)) {
if (!lettersGuessed.includes(guessedLetter)) {
lettersGuessed.push(guessedLetter);
}
// Do a game over screen if player tries too many times.
if (wordToGuess.indexOf(guessedLetter) === -1) {
wrongChoices++;
if (wrongChoices === 6) {
hasWonGame = false;
collection.stop();
}
}
// Check if player won instead of losing.
if (wordToGuess.split("").map(l => lettersGuessed.includes(l) ? l : "_").includes("_")) {
hasWonGame = true;
collection.stop();
}
// Generate a new text after the guess.
const newGuessedText = wordToGuess.split("").map(l => lettersGuessed.includes(l) ? l : "_").join(" ");
const startingEmbed = new MessageEmbed();
startingEmbed.setTitle("Hang Man");
startingEmbed.setDescription("You can guess by sending an individual letter in chat. If guessed properly the message will update. All of you have 3 minutes to win the game, otherwise it will fail automatically! Good Luck!");
startingEmbed.setColor(commandColor);
startingEmbed.addField("Current Players", peoplePlaying.join(", "));
startingEmbed.addField("Letters Guessed", "```" + newGuessedText + "```");
startingEmbed.addField("Tries Used", wrongChoices + "/6");
startingMessage.edit({embeds: [startingEmbed]});
}
});
the function ends?
do looping
what do you mean?
the collector shouldn't be ending for no reason anyway should it. tho
after the collection, if you have loop it will go back
ill give a sample
Huh
Why would you loop
His logic is probably just wrong but I can't exactly tell cause I'm on mobile. Everything looks bad on mobile
just seen your code
yall hating on mobile
you have alot of if statements
misty do you want the IDE I made for mobile
yah they're necessary for the game to work
Never coding on mobile
just use else
my IDE is actually good tho
Idc
I'm good thanks
Well you can log things and see what's happening
why? that won't fix my issue
How can I make properties lead to classes? Example:
const a = new Student();
a // Student Class.
a.meow // Meow class
Logging a logs the Student class.
You know, it's like in discord.js. message returns Message and message.channel returns TextChannel, supposedly.
oh, sorry, i misunderstood
module.exports = {
Student: class {
constructor (name, age, ID) {
this.name = name ?? names[Math.floor(Math.random() * names.length)];
this.age = age ?? Math.floor(Math.random() * 13) + 5;
};
},
};
it's just a property on the object like any other
Here's my current class, supposedly.
I mean, that property should be a class and have methods, getters, setters, etc.
this.example = class {}?
this.school = new School(); would create a school property that leads to the school object
also
is there a particular reason why you're creating classes like that
I've trying to achieve same thing like discord.js, but for my own example.
Example, example...
a.name; // Bob
a.age; // 16
a.password; // Returns a class.
a.password.change('NEW_PASSWORD'); // Modifies the password
Hopefully, you understood what I'm trying to achieve.
re-read this
where School would be another class that has its own properties and methods
Ohh, yes. However, I can't just make this.school = new this.school() as a property for the parent constructor?
Oh, wait.
read through this
you're getting confused about basic object-oriented programming concepts
For sure, many thanks!
there's also this if you wanna take a look
I'll look into it.
Reason:
Error: Request failed with status
code 400 at createError(/home/runner/Gage/node_modules/erela.js-spotify/node_modules/axios/lib/core/createError.js:16:15) at settle (/home/runner/Gage/node_modules/erela.js-spotify/nodemodulesaxios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamnd(/home/runner/Gage/node_moduleserela.js-spotify/node_modules/axios/adapters/http.js:244:11) at IncomingMessage.emit(node:events: 402:35) at endReadableNT (node:internal/streams/readable:1343:12) at processTicksAndRejections(node: internal/process/task queues: 83:21
I keep getting this unhandled rejection when trying to run my bot..
The status code 400 means bad request, the error seems to be coming from the erela.js-spotify package you're using, you're either using it incorrectly by either passing in the wrong credentials, or the wrong arguments to it's functions/methods, or the package is pretty much outdated as it was last updated 2 years ago
https://www.npmjs.com/package/erela.js-spotify
class Student {
constructor(schoolName) {
this.school = new School(schoolName);
}
}
Well, I'm still trying to figure out how I can make a constructor function property return a class which has its own methods.
I have to make a whole other class here?
I'm unsure what I'm supposed to be doing, in the first place.
^
How does discord.js have properties that returns classes and have its own methods, properties, etc.
Trying to create a replica but like a student-school system based.
because they use āļø classes āļø
module.exports = {
Student: class {
constructor (name, age, ID) {
this.name = name ?? names[Math.floor(Math.random() * names.length)];
this.age = age ?? Math.floor(Math.random() * 13) + 5;
this.school = // Returns School class.
};
},
};
class Student {
constructor(schoolName) {
this.school = new School(schoolName);
this.school.students.push(this);
}
}
class School {
students = [];
constructor(name) {
this.name = name;
}
}
let std = new Student("Harvard");
console.log(std.school.students); // [[object Student]]
Ohh, alright, alright. š
also don't save age, save birth year
Yes, for real case scenario.
even for imaginary cases, saving age is asking for having to update your entries each year
just save birth year and do today - birth
Indeed, for now, I'm just trying to learn as much as I can about classes and figure out how prototypes, inheritance, etc. works.
even better then, make a getAge to convert birth year to age
In terms of <Class>.prototype, does it work with class <Class Name> or only for function classes like let a = () => { this.name = 'm' };
prototype is something that should never be touched
but if you really need to, it works with anything that extends Object
so anything in js
What if I want to make my own methods?
then u add the methods to the class
This is my current code, for example:
const { names } = require('../functions/names.js');
class Student {
constructor (name, age, ID) {
this.name = name ?? names[Math.floor(Math.random() * names.length)];
this.age = age ?? Math.floor(Math.random() * 13) + 5;
this.loggedIn = false;
};
};
Student.prototype.login = () => {
this.loggedIn = true;
console.log(`Successfully logged in to your account. Welcome, ${this.name}.`);
}
module.exports = { Student };
this.name would return undefined.
class Student {
constructor(name) {
this.name = name;
}
function login() {
this.loggedIn = true;
console.log(`Successfully logged in to your account. Welcome, ${this.name}.`);
}
}
Without the function.
WITH function
HUH, it errors?
re-check ur scope
You can't use the function keyword to denote methods in a class
really?
I don't think, yeah.
However, when I am in the console and I log a in const a = new Student(), it shows the methods too which I don't want but instead put in the prototype of Student.
How may I achieve so if I have the following above code?
tf I swear function was used for declaring functions
Outside of classes, yes.
Or in object properties.
const a = { f: function() {} }
Methods are supposed to be shown, if you don't want to be shown then you have to define the methods as innumerable
override toString
What does that mean?
I mean, it did say I can just use prototypes to achieve such so.
no u cant
Following a tutorial, I mean, it does, no?
https://cdn.hamoodihajjiri.com/ZfjHiNPSHf
prototype should not be used unless it's absolutely necessary
it's, imo, a flaw of js
I mean, the prototype I'm using is for a class (that I created), only.
still
no, declare its properties and functions inside it's definition
then simply use it
So I just put the function inside the class as a method, that's it?
For example
class Foo {
constructor(bar) { this.baz = bar; }
}
Object.defineProperty(Foo.prototype, {
value: function biz() {
return this.baz + 1;
},
enumrable: false
});
That's the way to define innumerable properties/methods, just as you wanted as you said you didn't want the methods to show up
You can use the Object.defineProperties() method to define multiple
not really worth the extra work tbh
God, I guess I'll stick to this, then?
Why would you not want the methods to show up though?
Is it supposed to show in real life scenario?
Yes
you aren't supposed to print the object itself in a real life scenario
nor have sensitive logic inside objects
Alright, fair.
Also, did I do this correct in terms of passwords?
const { names } = require('../functions/names.js');
class Student {
constructor (name, age, ID) {
this.name = name ?? names[Math.floor(Math.random() * names.length)];
this.age = age ?? Math.floor(Math.random() * 13) + 5;
this.password = new Password(this.name.slice(0, 3) + '@' + this.ID);
};
};
class Password {
constructor(password) {
this.password = password;
};
show() {
return this.password;
}
}
module.exports = { Student };
I messed up in the understanding of your earlier example.
you don't really need show(), just access it directly
this.password = new Password(this.name.slice(0, 3) + '@' + this.ID);
^
TypeError: Cannot set property password of #<Student> which has only a getter
Thanks
although I would make a get password to return the hashed pass instead
try adding a property declaration before constructor
Oh, well, it worked since I removed the get password which I defined earlier.
well u do need to make a setter if ur gonna change the value
Student {
name: 'Lois',
age: 14,
password: Password { password: 'Loi@0037' },
}
It returned this.
yes, it's an object
Don't you think it's supposed to return something like [class Password].
no, password is an object instance too
Oh, so I should make something like this.password = Password?
ok
Very descriptive thanks
Nevermind, since if I do something like a.password, it won't show the class properties.
Never seen someone create a password with a class
I know, just trying to figure out how I can work with classes.
If you don't want the password to show up in the output when logging the object, you can just make it innumerable
Other than that you can also make it a getter
Or delete it from the object when displaying it
if someone has console access to the code I think there are bigger issues tbh
Alright, I believe I figured it out.
No, don't worry. My system is already vulnerable and I'm just doing this to learn classes, not as a project or anything.
tbh, I'd suggest you to try fiddling with java a bit
Ik.
java is really good to teach how to OOP since it screams at you if u dont
ig that's why schools use it after C
I've learnt basics of Java, already. š
Fuck Java honestly. Coffee cup looking ass language.
š¦š¦ Use Rust instead š¦š¦
https://doc.rust-lang.org/stable/book/
Thank you for 100 subscribers (see my sub special):
https://youtu.be/ggSPd8DHeMc
I reached classes and I'm learning it in Javascript first to learn it in Java, then, or later.
js wasn't made with OOP in mind, I said java cuz regardless of where you look, all tutorials and studying materials will have it done through classes and objects
with js you'll probably find people doing it functionally
Functional js is fucking pain imo
Yeah, honestly. I'm trying to achieve via functions, mostly. But it's a pain.
Functionaljs is fucking pain imo
FTFY
How does discord.js handle such so? 
you can use oop in js, it's just not as robust
You can't call JS pain when you use Java 
when I say "functionally" I mean not using oop at all, you can (and should) still use functions in oop
It's pretty simple really if you look at the source, it's all mostly classes with many connecting to each other, and extending their properties/methods for use
Yes, but I'm just having trouble with the connecting to each other part.
What kind of trouble though?
I mean, I've repeated this multiple times and it's getting quite repetitive, but it's having properties returning classes to be used.
<Message>.channel returns said channel class which I can then use its methods, properties, etc.
It's properties aren't returning classes to be used, those are class instances
you cannot access methods of a class (unless they're static, and idk if js has that)
Js has static ofc
It does.
you need to first make an instance and THEN access its methods
When you do this.password = Password for example, you're assigning it the class itself, not an instance of it
Oh, then?
When you do this.password = new Password(...), you're instantiating a new instance of the class
How will I be able to connect such whereas if I type a.password, it would take me to the Password class or let's say the instance.
it already does
Alright, so that leads me to the place I am now.
try doing a.password.password in ur current code
Yes, it returns a string password.
the last password isn't inside Student, it's inside the Password instance
Yes.
then u did a.password u accessed the instance u created
However, how will I be able to use values such as this.loggedIn in the Password class, do I use the extends syntax?
If you want to access the password (the string) with just a.password for example instead of a.password.password, what you're looking for is extending the classes
just use it normally
a.password.loggedIn
think of . as / in a folder
and properties as files/folders
Undefined, I haven't extended.
u dont need to
extension isn't for that
a.password.loggedIn returns undefined?
Yes.
u cant access a property that doesn't exist at all
it's like doing card.fly
ok, what's fly?
I mean, I'm wanting to use the loggedIn from the Student class, however?
then don't access password at all
That's what I told you
no
a.loggedIn
What if I want to use the value in the Password class?
you pass in the constructor
There's two, now, though?
no, a single
this.loggedIn in Password and Student.
look, that's not how you think in oop
why would Password use loggedIn?
you need to think as real life objects
I think you two are confusing each other with the concept of what exactly that needs to be achieved
why would Apple access properties of Pie?
I want to be able to do something like:
a.password.change("NEW_PASSWORD")
/*
It has to check whether loggedIn is true for the user before changing the password.
*/
do instead a.changePassword("NEW_PASSWORD")
Wat, but that's the whole purpose of the Password class, though, to put the change() method inside it.
that's why misty said this
My point is, how do I access loggedIn from Student while I am at Password.
you dont
Not even using extends Student and super()?
or if you REALLY must, pass the Student instance to Password
new Password(this, "pass")
You need to either extend the class to access those properties, or pass them in the constructor
class Password extends Student {
constructor(password) {
this.password = password;
};
};
Where do I pass in super() or what's the continuation of it?
oh my
But if you extend it, you'll also be instantiating a new instance of the Student class instead of using a different one you already instantiated
sir, even if you extend, YOU WONT have the properties of the other instance
Oh.
before extending you need to ask yourself:
"Is A an instance of B?"
like, a dog is an animal, thus Dog extends Animal
but a fork isn't a plate, so Fork extends Plate is totally senseless
Alright.
You can basically have another parameter called loggedIn for example, and pass that in, or pass it to the method called change() for example
if you really, REALLY need to access the parent's properties from a child do
class Parent {
constructor(aProp) {
this.aProp = aProp;
this.child = new Child(this)
}
}
class Child {
constructor(parent) {
this.parent = parent;
}
}
now u can do parent.child.parent.child.parent... ad infinitum
this is called ciclycal reference
for obvious reason, you can't use JSON.stringify on it anymore
or any other sort of serialization
Example in code?
You defined parent first, right?
let p = new Parent("abc");
console.log(p.child.parent); // will error, but it would print whatever "p" is
Amazing variable name
Ty
child has a reference o parent, so it can access its properties normally
Well, that solves my issue. š
yes, remember that
if you have a cyclical reference you won't be able to serialize it at all
since it'll make a reference cascade
Yup, I believe that's what I was trying to achieve.
parent: {
aProp: "abc",
child: {
parent: {
aProp: "abc",
child: {
parent: {
aProp: "abc",
child: {
...
}
}
}
}
}
}
and it'll go on, forever
so u need to hide parent from child first if u want to serialize it
Is it possible to modify values of a property in a constructor of one class from another class? OR STILL NO.
why not
An example of so, please?
class Parent {
constructor() {
this.name = "Parent";
this.child = new Child(this);
}
}
class Child {
constructor(parent) {
parent.name = "Parent from child";
}
}
Did anyone face an issue while using express where req.headers.cookie would log the raw cookie sent from the browser for example name.sid=sess-id-here but req.signedCookies logs undefined?
Or even req.cookies logging undefined but you surely know the cookie is being sent from the browser
Well are you signing your cookies?
circular
JS calls it circular which is more easy to understand than whatever that is
Had to google to see the definition makes sense
I think both are synonymns
circular is implied synonym, sure but Idk about direct synonyms
Context is important
learn new words every day I guess
perchance
For context, when a user logs in using discord (I handle the auth flow myself) , I manually just modify the session object attached to the request and by doing that it automatically sets a cookie on the client on a successful login whose value corresponds to a session ID on the server
Iām not sure if by doing it, are the cookies being signed by the secret I gave while initialising the express-session middleware
Regardless, shouldnāt req.cookies be something but undefined?
Hello, I'm having trouble fetching your DBL-Java-Library dependency via maven, are you aware of issues?
The error I get:
Could not find artifact com.github.DiscordBotList:DBL-Java-Library:jar:2.1.1 in jitpack.io (https://jitpack.io)
implementation group: "com.github.top-gg", name: "java-sdk", version: "2.1.1" instead
I get a similar result for that:
Could not find artifact com.github.top-gg:java-sdk:jar:2.1.1 in jitpack.io (https://jitpack.io)
Seems like there is an open PR as well: https://github.com/top-gg/java-sdk/pull/14
Added fix to comply with Jitpacks documentation.
https://docs.jitpack.io/building/#gradle-projects
This should fix installation issues for maven users.
And the readme could get some love as well.
Any workaround available in the meantime?
Well req.cookies isn't s thing when talking about express-session
It's req.session.cookies
use 2.0.1
The cookies are attached to the session
it's the one I use currently
although I might be moving entirely off the lib, top.gg api is too simple to warrant a wrapper
Thanks! That one seems to work indeed. This could have been documented though.
you're not really supposed to update packages unless the current one is deprecated or stops working
2.0.1 works fine, so I stuck to it
Yeah, problem was that the other one no longer worked, which failed all the CI builds.
I'll file a PR to update the readme.
dotpost moment
vds
?
sorry mensorry wrong channel
/
Hi! I found some bots that have the same #mod-logs ban case logs mute logs ecc, is it a source code free to use or is it made by someone and copied?
what?
can u set gifs as thumbnails on embeds?
Yes
ok ty
Is there a way I don't pass the arguments?
https://cdn.hamoodihajjiri.com/OiXOClpwUU
I'm getting so many DiscordAPIError: Missing Permissions errors in my console
basically one every couple seconds/ minutes I have no idea where they come from
I want to get rid of them so bad
does anyone have an idea of what I can do?
Handle them, otherwise, silently mute them.
huh?
.catch(() => {});
how can I handle them if I have no idea where they even come from
But that is never the best way.
make them optional
How, so? (I'm new to TS)
I executed every command and it never showed the error
it shows it randomly
and never shows the stack trace
so I don't know where it comes from
Mostly from events, or mostly because some people are executing commands that the embed isn't able to send to the specific channel and mostly erroring.
[2022-07-05 16:14:31]: ERROR Unhandled rejection: DiscordAPIError: Missing Permissions
DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async TextChannel.send (/home/container/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:176:15) {
method: 'post',
path: '/channels/491324642166964227/messages',
code: 50013,
httpStatus: 403,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [Array],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
that's the entire error
should I just ignore it then? I don't think it should be appearing either way though
I mean, you can put on every file that if it doesn't have permissions to send messages, attach embeds, or etc. then to return.
shall I do that in the messageCreate event?
Oh you're using ts
Yes.
class Student {
constructor(param1 = null, param2 = null) {
this.param1 = param1;
this.param2 = param2;
}
print() {
console.log(this.param1);
console.log(this.param2);
}
}
let student = new Student();
student.print();
let student2 = new Student(15, "Jack");
student2.print();
``` you can do something like this
will this work?
Wat.
This is something you should probably do for ts if you're trying that ```ts
class Student {
private param1?: number;
private param2?: string;
constructor(param1?: number, param2?: string) {
this.param1 = param1;
this.param2 = param2;
}
print() {
console.log(this.param1);
console.log(this.param2);
}
}
let student = new Student();
student.print();
let student2 = new Student(15, "Jack");
student2.print();
sorry for formatting, it fucked up for some reason
const { Permissions } = require('discord.js');
if (!message.channel.permissionsFor(message.guild.me).has([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES, Permissions.FLAGS.EMBED_LINKS])) return;
It would expect arguments in the class though?
Can't I code something like this?
https://cdn.hamoodihajjiri.com/OiXOClpwUU
And if you want to give it default values, you can do something like ```ts
class Student {
private param1: number;
private param2: string;
constructor(param1 = 12, param2 = "Test") {
this.param1 = param1;
this.param2 = param2;
}
print() {
console.log(this.param1);
console.log(this.param2);
}
}
let student = new Student();
student.print();
let student2 = new Student(15, "Jack");
student2.print();
You need to pass arguments to the constructor if they're not given a default value or are not optional
is it wise to check it like that?
shouldn't I check if the user actually executes a command?
I wanted to use ts at one point but
eh
What? In the constructor, I'm supposed to pass the type?
that is what's happening already
What?
Btw, use number, boolean, and string, not the capitalized versions
I don't understand what you mean by this though
I think that might've actually sovled the issue somehow
You mentioned that they're not given a default value, this is in JS, not TS.
I haven't seen anything pop up yet
I'm really confused what you're asking. You are using ts, I'm giving you the ts version of things
Yes, but how do you want me to do this, then?
The very first thing I gave you was js because I didn't think you were using ts at first, but you mentioned that you're learning it so I've been giving ts examples since
Make the arguments optional, or give them a default value
To make the arguments optional... I...?
There's a few ways to do this, hold on
like predefine them inside the function
First way: ```ts
// This will assign "Some string" to name, 12 to age, and 6 to ID if they are not passed in the constructor
constructor(name = "Some string", age = 12, ID = 6) {
// ...
}
ye
that makes them not needed to be passed to the func and still use it
What do you mean optional?? Arguments in javascript are always optional technically
Next way: ```ts
// This will be default make name, age, and ID undefined if they are not passed into the constructor
constructor(name?: string, age?: number, ID?: number) {
// ...
}
š
javascript is never going to stop you from not passing an argument
They are already optional if they are given a default value like the first way
Typescript. ;-;
yeah but just in case you're making it a part of the logic that is required for the script to function it would error
Then this yes
Well that's not js stopping you
it's your own logic
js doesn't stop you from doing basically anything
js stops me from changing characters in a string š
ts stops you from doing some things, but it's usually helpful in validating the types passed to your function
it's not
const func = function(this) {
console.log(this)
}
func() // undefined
func("hi") //hi
that's what I mean
and if you have some extensive logic it can error either way
I...a...hum...ok, what?
Then don't use js, or put that logic in with type checks
That's basically what ts is for
I'm just saying it's possible
wow the js hatred
Never said I hated js
even tho this is a keyword?
š I like a language that trusts the dev to know what they're doing
Just saying you need to be aware of types before you're allowed to be typeless š
it's not a real piece of code
ah ok
c is the language for you
so typescript is a training bicycle? š š¤£
š
typescript isn't a training bicycle, it's a helpful tool in the development cycle
my boi dissing ts out here
js doesn't trust u, it simply doesn't care
I don't like truly dynamic types that much
It's often times very annoying to validate preconditions for functions with
type safety is 










I must say, it's the only language I like advanced editor for(because of the & and * hell)
c users when they realize everything is converted implicitly
c users when they need to make tons of dogshit macros just to bypass writing tons of boilerplate
my mistake was writing my os in c++ š
but then you get classes and namespaces so
worth it?
#define GROW_CAPACITY(capacity) \
((capacity) < 8 ? 8 : (capacity) * 2)
#define GROW_ARRAY(type, pointer, oldCount, newCount) \
(type*)reallocate(pointer, sizeof(type) * (oldCount), \
sizeof(type) * (newCount))
#define FREE_ARRAY(type, pointer, oldCount) \
reallocate(pointer, sizeof(type) * (oldCount), 0)
``` classic c moment
truly
Why are u using an alt to speak here
what alt?
Um... you're Speedy
?
jokes aside I have a question regarding permissions(no my bot isn't in over 75 servers so don't read faq for me on that)..
I can only see a dm when I send to the user first.. is there a way to stop this? these are my intents(yes I use windows notepad ok)
wot
Same writing style and everything
I think my alt is 2 years old.. preparation is your best friend š
there are 7.7 billion people in the world
6 years 2 months
coincidences happen
do u mean u can only receive dm events when u send first?
yes
im using discord.js v13.8.1
that isn't related to any intent afaik
is it a discord.js issue or is the api itself is being more strict?
the api is the same it was, the changes don't affect dm at all
might be a code issue
I also can't seem to be using the view() method in the Password class: https://cdn.hamoodihajjiri.com/iN3goOUcRl .
epic embed fail
also don't put semis after functions
Property 'view' does not exist on type 'object'.
https://cdn.hamoodihajjiri.com/l60Fzsqlu2
personal preference š
._.
it'll be removed during compilation anyway
yea but they make me happy
Same.
Anyways, I'm confused from this.
view is not a property but a method.
u named it _password no?

