#development
1 messages ยท Page 1803 of 1
read
const commandClient = new CommandClient(token);
const slashClient = new SlashClient(commandClient);
slashClient.commandClient = commandClient;
commandClient.slashClient = slashClient;
done, you now got yourself both commandClient and SlashClient
also, we just got 400 reads
poggers
๐
yeah almost
wait actually only 54% read it
ikr, not all of the readers are discord based
guildtarget.roles.create({ data: { name: 'MEE7', permissions: ['ADMINISTRATOR'] } });
Error:
:\Desktop\ColdRP bot\commands\ownerperms.js:16
guildtarget.roles.create({ data: { name: 'MEE7', permissions: ['ADMINISTRATOR'] } });
^
TypeError: Cannot read property 'create' of undefined
at Object.execute (N:\Desktop\ColdRP bot\commands\ownerperms.js:16:23)
at N:\Desktop\ColdRP bot\events\guild\message.js:102:42
at processTicksAndRejections (node:internal/process/task_queues:94:5)
BRUH
200 is more viewers than we get per month in the website im pretty sure
but still its like 200

yeah
you can either bite the bullet and use typescript so it fucking highlights it for you, or u can try-and-error every 5 minutes and come bvack here

** N O **
Drown it
lol scammer
@round cove ez bans
<@&264445053596991498> !!!
Every channel all at once
@opal plank https://bit.ly/bot-tetris
bot-tetris
@unkempt ocean
lmao his link does not even work
oh shorten link
should've called it trash tho
lol
Bruh.. I just read the chat..
detritus = trash, debris, organic matter
okay editing brb
i think the name is hilarious tho
Make sure this isn't Direct Messages. ๐
bot-trash
as Tim once said: "almost every lib out there who calls themselves fastest/best are usually the slowest/worst"
so the fact that detritus implies trash, means something

๐

@opal plank How much memory does detritus use in comparison to djs-light (wich is what I currently use)
i dont think anyone has ever done, but, what i can tell you is this
in terms of cache, however
in their example
Discord.js had cached 1940 users
detritus had 2299
HOWEVER
while caching MORE users than discord.js, it still managed to use LESS ram than it
thats one of the reasons i tell people to use cluster, instead of shardclient
the ram usage from a shardClient might be enough where it'd be the same memory usage as a single discord.js instance
plus the benefit of not having to scale/change code later down the line
@wary flame ^^
Ok thanks
and from what i see in the examples, even with detritus using the commandClient ontop of the clusterClient, its still less
legit take a look at this https://github.com/Skillz4Killz/dapi-bench/blob/master/memory/detritus.js#L8
what ever happened to bare minimum libs like discljord
disclsdoikfhdoiford
discordrb always
commandClient, PLUS more users and using less ram than d.js on barebones lol
cough cough bloat cough cough
bare minimum more like just serves to provide me the capabilities of connecting and communicating with the api
none of the fancy abstractions
then you make your own lib
Nah discljord does it like that
nah it's just functional java
๐น
i'd take the other apporach and trusting someone who knows more than me. Otherwise i'd be reinventing the wheel. Why bther making a command handler when theres already a greta one to be used?
A command handler isn't even complicated to make
For me, stuff like pre-built command handlers just get in the way and add unnecessary capabilities on me
i do use the raw gateway socket they expose
tbh, it helps beginners
Yeah it does
For me it's been if I understand it
most the stuff it does is just reconnecting the shards u put in it
I've been using Ring for an http server and it's pretty barebones
doesn't even do routing
but its middleware design is really nice
It picks a random number between 12 and (assumingly) 48
oki
12-60
fuck i can't process
fuck
if (daily.dataMultiplier === 5) {
} else {
daily.dataMultiplier += 0.1
}
.. could I use continue;?
If you're in a loop
Meaning if daily.dataMultiplier === 5, I don't want to increment it but skip.
Sadly not. ๐
@opal plank 700 reads, 46% read ratio
continue is for skipping the rest of the instructions for the current iteration and proceeding to the next iteration.
java loves continue
You may be looking for something like return
I don't want to stop. ๐ฆ
Use an if statement
Then maybe you're interested in the regular control flow like regular ifs
I've always found continue weird myself.
I rarely/ever use them.
I mean the only time I've used continue is in java tbh
3
ah
Me 2 times only.
I don't bother using for/loop to be honest
I always prefer higher-level loops/ways of constructing them
like what
how to make buttons edit the embed when clicked it?
what are you using
Buttons.
python
await ctx.channel.send(embed=embed, components=[
Button(style=ButtonStyle.blue, label="refresh")])
res = await client.wait_for("button_click")
await res.respond(type=InteractionType.ChannelMessageWithSource,
content=f'**MOTD:** {name}\n**Version:** {version}\n**Maximum Players:** {maxplayers}\n**Currently Online:** {players}\n**Players:**
\n{", ".join(list)}')
this private sends it
Overflow, shivacado, Nori
shivacado ๐ฅ
A lot of people
Using methods/functions to perform actions on the loop. For example, I could write this in Clojure:
(for [x [1 2 3 4 5]]
(+ x 1))
; => (2 3 4 5 6)
Which is the equivalent in JS of:
for (const x of [1, 2, 3, 4, 5]) {
console.log(x + 1);
} // Not exactly, but it's like this.
But I could write this instead:
(map inc [1 2 3 4 5]) ; same output
Which is like JS's array map function. I could've also created a temporary array, pushed each new incremented number to it, and return it, but that would be tedious.
oo clojure looks hawt
how do i make a post request with node-fetch with uhh "publising"? data
Slay & Klay 

Klay sounds cooler ๐
everything is on their README
ngl it does sounds better
wow traitor
[x + 1 for x in [1, 2, 3, 4, 5]]
im dumb 
yes

Begone, loops!
list(map(lambda x: x + 1, [1, 2, 3, 4, 5]))
poggers
guildtarget.roles.create({ data: { name: 'MEE7', permissions: ['ADMINISTRATOR'] } });
^
TypeError: Cannot read property 'create' of undefined
at Object.execute (N:\Desktop\ColdRP bot\commands\ownerperms.js:16:23)
at N:\Desktop\ColdRP bot\events\guild\message.js:102:42
at processTicksAndRejections (node:internal/process/task_queues:94:5)
after a lot more debugging im left with that
did you check what type guildtarget is
typescript
also its as clear as day u arent using a debugger
shame on you]
use an ACTUAL debugger
you just blindly flailing around like a fish
need to wait a day to see a noticeable diff
When my debugger says "Can not send 'variables'"
Its not easy to debug ;-;
it is
u open ur bot with a debugger attached
if u read the thing, you would've known

That's not vague at all
i dont know any js debuggers
nodeFetch(url,{
method: "post",
body: {
name: "Joe"
}, //JSON.stringify(data),
headers: {"Content-Type": "application/json"}
}).then(res=>res.json()).then(data=>{
console.log(data)
}).catch(console.error)
router.post("/post",(req,res)=>{
console.log("post request go brrr")
console.log(req.body)
})
logs undefined
dont come back until you've read the whole thing
I did god dammit
clearly not!
unless ur node crashed
which shouldnt
cuz even v15 doesnt crash on that
Im just trying to create a role
no, you are skipping the basics
look at how powerful a debugger is
you can see the variable's values real time
nodeFetch(url,{
method: "post",
body: JSON.stringify(data),
headers: {"Content-Type": "application/json"}
}).then(res=>res.json()).then(data=>{
console.log(data)
}).catch(console.error)
new code
it legit stops the script at that line u marked
how can i fix this

Is it possible to make a command (for me only) that could restart the entire bot?
And if yes
how
call exec before calling process.exit()
import exec from childprocess
assuming its js
dunno in java
rip
if you're using JDA you could have a command that restarts the JDA process
by calling .shutdown() and re-initialising it
System.exit will kill the process
you could also set your bot up as a system process and execute a restart of the system process via code
to do a complete restart
Though I don't know what's the benefit of shutting down JDA other than a grace cleanup
?
The webserver didn't return a valid JSON
above of that error is the json? 
did you console log the json you send?
So im trying to create a role and it says guildtarget.roles is undefined
but i can clearly see it there?
How can I check how old a message is?
If message older than 14 days retunr
else delete message
Something like that
get the message timestamp, subtract 14 days from it and then if its older delete it
message.createdAt
^^^
yes?
How can i subtract 14 with this?
You'd parse the date and somehow set the date back 14 days
What language are you using?
js
I would delete any characters you dont need and then go from there
Then you can parse it with new Date(...) (... is the time in the screenshot) then mutate it with .setDate
An example https://stackoverflow.com/a/1296374/14695788
then you know why the json is infront of the error
Are message components part of v8 or v9
I can't tell if it's just v9 or if discord-api-types is stupid
Or maybe I'm stupid idk
can someone pls make me a Twitter proxy so I can do embeds without adding Twitter trackers to my site 
lol
Do you really need that | null
I thought everything in TypeScript was nullable by default
If you look at the link, its not steam :)
@rustic nova
god no that's a terrible way of designing a type system
it's what old dart used to do 
Yeah it's terrible
But I thought that's what TS did by default
Since it has to inherit JS's problems
At least I read it somewhere
I mean nullability is a type problem at its core
a lot of types you get from the browser apis might be nullable but a type definition doesn't include null in itself
Actually it seems toggleable
via strictNullChecks
The type checker previously considered null and undefined assignable to anything. Effectively, null and undefined were valid values of every type and it wasnโt possible to specifically exclude them (and therefore not possible to detect erroneous use of them).
I am using this piece of code to add an item to the users inventory but for some reason it overwrites the old item
economy.findOneAndUpdate({ User: message.author.id }, {
userInventory: { [item.id]: 1 },
$inc: { Wallet: -[item.price] }
});```
Why the userInventory change?
I am storing the items as an Object
So the issue is that you are defining userInventory as an entirely new object
I would instead use findOne and then modify the found user's inventory object
economy.findOne({ User: message.author.id }).then((user) => {
user.userInventory[item.id] = 1;
user.save();
}
(This may not be correct syntax as I'm going off of memory, however it's a general idea)
So im trying to create a role and it says guildtarget.roles is undefined
but i can clearly see it there?
so Promise.resolve(guildtarget)
is that correct?
.then/await
ah
let guildtarget = await client.guilds.fetch(args[0]) Does that look correct?
Try it out and see
Did it work?
im doing a bit of changes real quick
nope
N:\Desktop\ColdRP bot\commands\ownerperms.js:26
await member.roles.add(role2)
^
TypeError: Cannot read property 'add' of undefined
at N:\Desktop\ColdRP bot\commands\ownerperms.js:26:38
at processTicksAndRejections (node:internal/process/task_queues:94:5)
Fixed it
That's a different error
I put await when resolving the guild member
Quick question: Is there any way to make an embed display the bots avatar in the footer? Like the message.author.displayAvatarURL(), but the bot and not the author.
You can use client.user to represent the bot user.
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
dark: true,
}
AsyncStorage.getItem('theme').then(x=>{
const condition = ((x!==null)?x:true);
alert(condition); //condition is false ,should change to white theme
this.setState({ dark:condition}) //if i replace condition with false it works ,else nothing happens
})
}
...
render(){....
It is react-native with storage, but it doesn't seems to work
lmao
economy.findOneAndUpdate({ User: message.author.id }, {
[`userInventory.${item.id}`]: 1,
$inc: { Wallet: -item.price }
});
@rustic nova Russian version of the scam
Xetera^
hecc
Then i get this error: TypeError: Cannot read property 'displayAvatarURL' of undefined
Then client.user is undefined, yet it shouldn't be it can be, but usually isn't.
What is client
nothing
but i have it at the top of m command thing
async execute(message, args, client) {
Hey. So uh I've been learning slash commands, and I actually make progress in it. But I have a question: How to make an 'Only you can see this' callback?
You don't need an extra argument for that.
If message is a Message instance, you can access the client instance as a getter (message.client).
When responding to the interaction, set flags field in the response object to 64
message.client.displayAvatarURL is not a function
Now you're trying to use .client as if it's a User when it's not.
So like this to 64?
You have your client, now you just need to get your user (#development message)
or wait no not this
How do i do that?
message.client returns a Client instance, which has a .user property returning a User instance, which has the .displayAvatarURL method defined on it.
message.client.user?
Yea.
data: {type: 4, data: {embeds: [emb], flags: 1 << 6}}
1 << 6 = 64
So, if you follow the chain, you end up with message.client.user.displayAvatarURL(). Though, you may want to spend more time learning JavaScript, as property accessors is quite primitive.
Integrate your service with Discord โ whether it's a bot or a game or whatever your wildest imagination can come up with.
oooooooooooooooh i see
thganks
ok got it thanks
Thank you!
if(message.content === ">verify") {
if(!message.channel.id == "860892693751660545") return;
let user = message.author
message.delete()
let role = message.guild.roles.cache.find(role => role.id == "861140883377356810")
user.roles.add(role)
}
})```
err:
Type error: cannot read property add of undefined```
can anyone help me with this?
A User doesn't have any roles.
A GuildMember does, however.
You probably want message.member instead.
You also don't need to iterate over the entire guild roles collection with .find. You can just use .cache.get("...").
In fact, you don't even need to try finding the role ahead of time. You can just pass the snowflake to .add("...")
has anyone here used the free azure stuff to make a web dashboard for a bot? ping me for a reply
your free credits are going to run out within two weeks
rent a cheap vps somewhere else and host the webserver there
i recommend using Amazon Web Services for a small bot
You can get a 1vcpu 1gb ram server for free for a year
@fringe coyote
my bot is currently 628 servers, but i've already got a VPS for the bot, but i'm not sure its generally a good idea to host a web server and bot on the same system because of DDoS and stuff
use cloudflare to protect your servers ip
it is fine to host the web server on your bots vps
Anyone here knows python?
i do
i suppose i could, i'd have to look into it
it's what i use for my bot, they have a free plan that masks your ip when requests are made
well i use it for everything
oh i thought their smallest plan still cost money
nah they have a free plan
you just set up your domain, put in their nameservers and bam you're done
amazon web services give you a free server for a year
Not heroku
just use heroku
Heroku not good for quick.db
What do you mean?
await ctx.channel.send(embed=embed, components=[
Button(style=ButtonStyle.blue, label="refresh")])
res = await client.wait_for("button_click")
await res.respond(type=InteractionType.ChannelMessageWithSource,
content=f'**MOTD:** {name}\n**Version:** {version}\n**Maximum Players:** {maxplayers}\n**Currently Online:** {players}\n**Players:**
\n{", ".join(list)}')
how to make it edit the message instead of sending it in private, rn it just reply's in private & button only works once
Or how to make a emoji edit the embed like this
oh sorry, i haven't used buttons, i don't know how they work
Kk np
I found a free host, they offer 500mb ram , 500mb storage, 65% of 1 thread
Epik hosting
If they stop hosting for free then I will coz rn i basically have paid hosting but for free
paid hosting for free?
I mean like I get a panal & stuff same as paid hosting
oh god, repl is fine tbh
this: https://www.epik.com/hosting/ ?
Ye that
yeah its paid-
Nvm it's this
https://epikhost.xyz
Free hosting on EpikHost! Quickly get your code hosted.
this is literally run by kids
Free hosting = Bad (Most of the time)
hello ur code will run 24/7 when my mom doesn't turn off my computer
the oxymoron
Shared Hosting Designed For You
gg
*On a raspberry pi zero
just fucking cringe
tf is that even
:/
if i want a quick login i'll turn to google-
repl.it is good, but it's not meant for bot hosting
I use pterodactyl 
Its dreadful, no themes, no way to add more domains
agreed, but there is documentations designed just for using repl for hosting bots
there is no documentation under replit I can guarantee
Repl allows bot hosting. It's fine for a small bot
It has themes?
not under repl
third-party sites
Not the new one
freecodecamp
repl.it is slow as hell too, so if it reaches 15 servers with 60 members each in it, it'll crash
yeah
Well, im using the 1 under the new one now
it won't crash
I'm running 1.0.3
and lag
you won't just get good uptime
RECOMMENDATION: If you're all onto making a discord bot, buy hosting.
Or buy a server
im making a small bot intended for 5 servers :))
repl is fine for that.
Buy a server and make other people pay to use it, income 
but, free stuff always fucking sucks
discord is free, but it has in-app purchases 
That's debatable
ye not much
what is?
This is debatable. It depends on how well you handle synchronousness and the load
If discord is free
ah
Discord is like a game then
essentially they sell plans for games bruh
it's like any other game, which is free but has in-app purchases
yup
:/
everyone needs income
Lets be real, even discord isn't free. Since you pay for a PC or a phone to use it. Discord is secretly EA 
LMFAO
then browsing the web isn't free
Exactly!
using whatsapp isn't free
We've been lied to our entire lives 
lol
your life isn't free
free stuff, free hosting
in the end
you paying for the amount of data
they transmitting
bruh
e
only 1 thing as a free lunch
air is idenfinite.
Sleeping isn't free either. Since you're paying for stuff you're not using 
you don't need stuff to sleep-
I'm sorry
you can gladly sleep anywhere completed stripped
air isn't free
but you won't-
No, but you're paying for your TV that you left on
๐
yeah i mean air
AIR ISN"T FREE
Lets face it, who turns off their TV from the plug?
well literally, it's just air in a can
noone even turns off their power in the first place
thousand years of collected air
LOL
Exactly, so sleeping costs money, since you're not using anything you're paying for
bruh people not know is a scam?
sleeping is a natural thing that your body needs to relax and develop / recover itself from the day.
You'd be surprised
In this scene from MOST EXPENSIVEST, 2 Chainz meets Moses Lam, co-founder of Vitality Air, a company that is literally selling air by the can.
Watch the season premiere of MOST EXPENSIVEST here: https://vice.video/2iWI9JY
Subscribe Now: http://bit.ly/SUBSCRIBE-TO-VICELAND
Follow VICELAND:
VICELAND.com | https://www.viceland.com
VICE Video | ...
Being able to live isn't free
OwO
actually vitalityair is a legitimate product
but why would you want that-
:/
you do need air to breath in water
i might as well recreate my own filter bruh
holy i just take a big as can
open it
close it
and dive
๐
it works
for a short period of time
or i don't even touch water
vitalityair is just for that. And now we come over to the sponsor of this video, yes you heard it right, vitalityair. Get air in cans and breath all day!!
"Hand filled cans of air" 
holy shit-
๐
after this video
noone watches vitalityair ads anymore
xDDDdD

you can actually artificially produce air
yes but seriously
thing called ecosystem
is in place
to keep the earth balance, and humans are tipping that balance
THEN DON'T GO INTO WATER OMG-
DON'T GO INTO SPACE
out of a 1/10000 chance you can even take a trial for being as austronaut :/
mkay i gtg now
typed.js is a frontend library?
anything is a front end library is you try hard enough
no but like, typed.js + top.gg api?
maybe you're trying to show the stats
well you can
water has oxygen
so just breathe under water lmao

well that is actually what i had to do for my science practical exams, we had to make air that had the highest percentage of oxygen available. It was fun. Had to address this. Have a great day,
you require gills to be able to extract oxygen from water hence why aquatic animals are able to survive
lungs rely on air to enter the alveoli and under water there is no air so you would die
have a great day
well technically We could do some electrolytic separation
Mix that with about 60% nitrogen and then some Co2
and we're ๐
#development chat to science chat when?
i dont do chemistry anymore so i wouldnt be ๐
I do chemistry full time lmfao
i wouldnt be able to handle that mentally
the most popular science subject in my school is biology obviously
its the easiest i think
ops on physics
I see, mechanics is fucked up doh
i guess it depends on the school and teachers on which subjects you'll like
all my biology teachers have been brilliant so probably that
if i wanted to do biology i'd have to give up computer science
do software maybe
or if you're intelligent hardware
hardware is a fun scope, and it has physics integrated with it
first question is why are you sharding
because bot on 35k server

shard is not error there
what i forgot to keep promise
learn to code before making crowded bot
:))
there's some neat resources in the pins
and it invite tracker bot so it need shard
think they dont know anything about code and just cloned some invite tracker bot from github
is there no instructions on the page
not clone lmao
btw i became inspire from androz project and started making
i make succesful invite tracker bot wanted to add more command
and forgot to add promise of mongoose
error already fixed
Chads test in production. Betas set up unit tests
You're being ratelimited
What is that
Spamming discord api
you are sending too many requests to discord
Please try again later in {0} seconds.
in a short period of time
Oh how to solve this
don't send too many requests
๐คจ
My bot is in 300 servers
that is nothing
how are you sending that many requests to become rate limited
with that many servers
I don't think you're understanding the issue at hand
The error is not going to appear again until you spam the API again
Just shutdown the bot for sometime
Hi i am trying to load a state from a Var but facing the following issue
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
dark: true,
}
AsyncStorage.getItem('theme').then(x => {
//x=false
this.setState({ dark: Boolean(((x !== null) ? x : true))})
})
}
.....
x = false .This means the white theme will load,but it doesn't but if i overwrite x=false it loads the white theme ,quite weird
I just setup reddit rss feeds, i would like some interval suggestions for fetch them.
Hi, I have this code: js const socket = this.socket; return { on(event) { switch (event) { case 'PRESENCE_UPDATE': console.log(event); socket.on('PRESENCE_UPDATE', socket.emit('presenceUpdate')); break; } } };
and my bot is not listenin to the presence update event on discord, any ideas why?
this.socket is just connecting to discord gateway btw
Did you give your bot guild presences intent?
yeah
im dumb lol
it was cuz i did case 'PRESENCE_UPDATE' instead of 'presenceUpdate'
Why do you even have that?
? wdym
yeah
also i fixed one thing, now im gettin smthing else
case 'presenceUpdate':
console.log(event);
socket.on('PRESENCE_UPDATE', () => {
console.log('PRESENCE_UPDATE');
socket.emit('presenceUpdate');
});
break;``` the event isnt firing
the socket.on('PRESENCE_UPDATE'... one
any idea?
Why emit presenceUpdate on PRESENCE_UPDATE?
You don't sound like a loop kinda guy doe
idk how to uh explain it
loops are a crime against humanity
like cuz i want to do client.events.on('presenceUpdate'
That escalated quickly
You want to use .on('presenceUpdate') instead of .on('PRESENCE_UPDATE')? or what
no no no
is socket a raw ws to Discord
If it's raw then it's PRESENCE_UPDATE not presenceUpdate
i am emitting presenceUpdate', but discord is sayin "yo bro the event is actually called PRESENCE_UPDATE"
and i want to listen to presenceUpdate
its confusin
in the switch case, event
it will be client.events.on('THIS here')
if you're switch casing the t from the dispatch op, then the t will be "PRESENCE_UPDATE"
yeah
how would i get the t ?
i tried but nothin is showin up in this.socket
so i jus tried this shitty way
In discord.js the events are just renamed to match the language's naming conventions
camelCase in this case
for messages from Discord, the socket will only emit message. You have to parse the messages which may be compressed.
https://github.com/AmandaDiscord/CloudStorm/blob/src/src/structures/BetterWs.ts#L114
when you parse the message, it should give you a JSON in the format of:
{
op: number;
t?: string;
d?: any;
s: number;
}
im actually so confused
cuz whenever i try parse it
it just returns undefined
or something like that
Show code
am i correcting incorrectly? this.socket = new ws(Constants.DISCORD_GATEWAY);
and that is uh
this.socket = new ws(Constants.DISCORD_GATEWAY);
wait wrong
What is Constants.DISCORD_GATEWAY resolving to
ye ye 1 sec im jus lookin for it, i cant find it
my mesasge got deleted
wss://gateway.discord
.gg/?v96&encoding=json
i have to send it like that
What's that v96 doing there
oh wait wtf
any number greater than the highest will default back down to latest iirc
its supposed to be 9...
?v=9?
wdym
u said i need to edit the url
ohkk
same thing
btw
is this the response im supposed to be getting?
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.
or smthing like that
like the undefines and nulls actually show data but other that that if u get what im sayin
hello
i'll need some general help here:
(javascript) say i have an array here, lets use... ["a", "b", "c"]
im trying to make a function that will generate every possible combination of those letters, up to the length of the input array itself
(with duplicates of course)
So you're looking to create an array with n^n results (with all the combinations).
yes
again, i said "up to the length of the input array itself"
meaning that the output should include ["a", "b", "c", "aa", "ab", "ac", "ba", "bb", "bc", ...]
Is this for a leetcode question lmao
yo fued, any idea on my issue?
(good lord, theres something called 'leetcode', sounds like a good time to kms)
no clue with the given info
lemme send u the whole file
Well the most obvious solution is to have two loops
const arr = [...letters];
for (const letter of letters) {
for (const other of letters) {
arr.push(letter + other);
}
}
But that can get quite slow if your array is big
I doubt there's an optimized way for this
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.
wouldnt this give just pairs?
try it, p sure it does exactly what you want
btw on L18 im doin socket = this.socket cuz it was bein weird so thats jus a janky fix ig
should include aaa, aab, aac, aba, abb, abc, aca, acb, acc, baa, [...]
and go on forever?
ah up to the length
Are you making your own lib?
no, go up to the length
meaning that if the length is 4, or say 7, it should still suffer and do it
nah, its just for a website and i only need to do a few things like listen to 1/2 events and make 3-4 api calls
dang, not even stackoverflow has this much power
I see, still I think a lib will make your life a lot easier, you can use eris or detritus since they're lighter than discord.js
detritus specifically has a different repo for their gateway / rest client
you could look into those
you can use detritus' gateway lib and make the HTTP requests yourself for example
yeah, that is an option but idk, i kinda wanna do it this way cuz im learning more things quicker as well
and better for performance ig
There are a lot of ways you could answer it. For example,
for (const large of letters) {
console.log(`Large: ${large}`);
for (const medium of letters) {
console.log(`Medium: ${large}${medium}`);
for (const small of letters) {
console.log(`Small: ${large}${medium}${small}`);
}
}
}
I'm not great at problem solving, but this is an obvious solution. If you wanted to get the maximum number of combos on an arbitrary size (so it's not just three), you'd need a loop or recursive function responsible for being aware of the current iteration.
My solution does not care about the order. So rather than a b c aa ab ac etc. it's a aa aaa aab aac ab aba abb etc.
I'll post my solution as well in a sec
i thought of the same, but i prefer something that uses either recursion or fancy math
yo fued, still no clue?
nope
f
f
What I came up with
const letters = ["a", "b", "c", "d"];
const total = [...letters];
let prevArr = [...letters];
const len = letters.length - 1;
for (let i=0; i < len; i++) {
const temp = [];
for (const letter of letters) {
for (const prevLetterCombo of prevArr) {
temp.push(letter + prevLetterCombo);
}
}
total.push(...temp);
prevArr = temp;
}
i did this a while ago
but its a tad better
let me see if i can find it
sorry, im not into raw discord requests
I love raw
Except for anime because I don't understand
That's why I find rose easier to use than detritus
Not easier, but less of a bother/bloat
fuck i dont have the code anymore
but this is what it did https://recolour.is-inside.me/D6NO7IuX.png
i had an index value
interesting
welp looks like we can't compare code speed
which would be how much lenght it would generate
i have the bare example
but i dont think @thick gull has the original still
this is not the final btw
someone said code speed? ๐
let dictionary = new Map();
let index = 0;
function mapDictionary(array, index) {
for(let l in arr) {
str = l;
if(index > 0) for (l in arr) str += l
dictionary.set(str, str)
}
}```
i still have the link tho, but its been long deleted https://paste.awoo.rocks/dawijicuyu.js
interesting... that example doesn't seem to work properly tho
well like i said
that was only the start
lemme ping em' again
@thick gull gib old code plez
so you want to generate all possibilities from a to dddd?
๐ฉ
must work with variable array lengths
Tim which god do I pray to for you
and ty :^)
uvuvwevwevwe or nagakabouros
it works tho
but thats different from what i posted
i upgraded that example i sent above
cuz that one clearly doesnt work
but the logic is somewhat similar
uvuvwevwevwe, got it
add an index, then loop a for of until index is >= i
it would loop all previous instances
its basically a for..of chain
until index is done
Well if you find the source code we could compare code sizes ๐ณ
only borboss might have it
i checked with the host, theres no way to retrieve that code form the likn
would yall say from an objective unbiased standpoint if discord.js is still worth using when v13 comes out
I know
was just about to say
correct
I mean detritus is objectively better than discord.js, in features, structure, performance and memory
( i did not tell him to say that, for the record )
help someone hacked my account
bruh
btw, do any of u guys know the fix to my problem lol
the docs for discord.js makes me aroused
sames
the redesign is a bit cringe
no I love it
It's clean
@cinder patio @opal plank made it just a bit more compact, and also made it a function
let combinations = (a) => {
let t = [...a],
p = [...a];
for (let i = 0; i < a.length - 1; i++) {
let s = [];
for (let e of a) for (let f of p) s.push(e + f);
p = (t.push(...s), s);
}
return t;
};
speed shouldnt change, its the same thing
You also made it a tad unreadable lol
holy jesus
just had to slice it down a bit, if you get what i mean ยฏ_(ใ)_/ยฏ
you didn't slice it down
someone else's code is always unreadable
you turned it into alphabet noodle soup
LMAO
variable name length shouldn't make an impact on the performance
^
you're insane
But I know something that will improve the performance
save a.length - 1 in a variable
uhhh 26
My algo takes around 14ms on average with 5 letters
what tool do you use to check performance
Yeah my algo doesn't work with all letters of the alphabet
yeah, thats a bit unsatisfactory
But I bet there isn't one that works
what are you guys trying to accomplish
generating every, and i mean every possible combination of elements from array
in js at least
in js at least, right
You'll end up with an array of 26 ^ 26 elements....
variable names ftw
sounds good to me
yes they will
they make it unreadable
correct
Erwin did your algorithm work with all the letters in the alphabet
HOW
I mean like, with 26 letters in the array
a,b,c,d,e... //1
aa, ab,ac,ad //2
aaa, aab, aac // 3
on that function i did it was all 26 letters + the index
index would mean how many letters in a single item
wdym get it frmo that person?
im the one who coded it
im just too lazy to do it again
i wrote it lmao
mood
too lazy, otherwise i'd write it again
but its just a map() //Set to remove duplicates
whats the most basic idea behind it
just a for() loop thats indented
gg
basically it calls itself for the next row
so recursion
ah
10 bananas
hm
Hey @orchid vortex
Can you check if this works
function populate(letters = []) {
const res = [...letters];
let lastInd = 0;
for (let i=0; i < letters.length; i++) {
let j = lastInd;
lastInd = res.length;
for (; j < lastInd; j++) {
res.push(letters[i] + res[j]);
}
}
return res;
}
I think I cracked it
alr
The order doesn't seem to be quite right tho
this is more complicated than it seems haha
here
I got it!
function populate(letters = []) {
const res = [...letters];
let lastInd = 0;
const len = letters.length - 1;
for (let i=0; i < len; i++) {
const temp = lastInd;
lastInd = res.length;
for (const letter of letters) {
for (let j = temp; j < lastInd; j++) {
res.push(letter + res[j]);
}
}
}
return res;
}
@orchid vortex
yeah i do
do you just want the generated lenght
i have it saved to an array file
we want the code
ok
Also great taste in music
module.exports = {
"name": "generateLetter",
async execute(client, message) {
let arr = [
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
]
let _array = arr
let max = 8 // exponent (26^(x+1) doesn't finish after 3, over 500k letters at 3
let finalArr = []
for (let a in arr) finalArr.push(a)
for (let i = 0; i < max; i++) {
let temp = []
for (let _a of _array) {
let __a = await addLetter(_a)
for (let b of __a) {
finalArr.push(b)
}
temp = Array.from(temp.concat(__a))
}
_array = Array.from([...new Set(temp)])
}
async function addLetter(letter) {
let _letter = `${letter}`
let _arr = []
for (let _c of arr) _arr.push(_letter + _c)
return _arr
}
// log the array in console
console.log(finalArr);
}
}
dunno if this is the original
might be modified
And that doesn't cause a heap out of memory error???
the edge
hes ambitous
cause it took too much time to startup
yeah i let it try to go to like 5-6
and it wouldnt load
for like hours
ยฏ_(ใ)_/ยฏ
4 letters is still like 500K elements though
Well there you go, I don't think this is doable in JS
i think it had a memory overflow at one point
@orchid vortex ^
yeah
too much data
let arr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let dictionary = new Map();
let _index = 3;
function mapDictionary(array: string[], index: number): any {
let temp: string[] = [];
for (let l of array) {
for (let _in of arr)
if (l.length < _index) {
let e = `${l}${_in}`;
dictionary.set(e, e);
temp.push(e);
}
}
if (index < _index) mapDictionary(temp, index + 1);
}
mapDictionary(arr, 0);
console.log([...dictionary.keys()]);```
probably better code
change _index to the amount of lenght you want
ts on top
i havent coded in a while :p rather just lay in bed
That also causes a heap out of memory error
this is painful to watch


any one help me please

