#development

1 messages · Page 1500 of 1

earnest phoenix
#

what in the literal fuck are you on about lOL

haughty vortex
#

super great way of having good testable code

#

you said that C# has DI as a forerunner

#

I'm saying that that's .NET core

sudden geyser
haughty vortex
#

whoa

earnest phoenix
#

.net is just a family name

#

visual basic, sure, doable

#

f# not so much

haughty vortex
#

F# has decent DI due to .NET

earnest phoenix
#

you and i both know that the dependency injection and host builder packages were built for c# and with c#

haughty vortex
#

it was built for C#, and with C#, but it's not part of C#

#

unfortunately

#

anyways the point I'm trying to make is that it's not focused on one language only; if a language has OO capabilities, you can do DI easily

crimson vapor
#

turns out Maps have a max

#

2^24

#

or somewhere around there

#

I think its just 2^24 where js will error

coarse topaz
#

discord.js
My bot doesn't answer when I try to use this command.

liveGames, liveModels, liveAvatars, brGames, brModels and brAvatars are arrays.

For example, 12345 is in the liveAvatars array, so when I run "!check abc12345def", the bot should answer with "The sent creation is in my database.", but as I said, it's not answering. Am I doing something wrong?
if (message.content.startsWith(`${prefix}check`)) { let args1 = message.content.split(" "); let creationID = args1[1]; if (creationID.includes(liveGames[i] || liveModels[i] || liveAvatars[i] || brGames[i] || brModels[i] || brAvatars[i])) { message.channel.send(`The sent creation is in my database.`); } }

#

No errors in the console, by the way.

misty sigil
#

what is i

#

that code is a mess

#

it'd be cleaner to have it in a command handler

#

now from what i'm understanding i is the creationID

coarse topaz
#

that code is a mess
lol
now from what i'm understanding i is the creationID
And yes

misty sigil
#
let args1 = message.content.split(" ") // This is a terrible approach for args. You should really trim off the command and prefix before splitting off args. But, it works
let creationID = args1[1] // Why not just use args1[1], also, why use numbers in a variable name. Do you already have args defined?
if (creationID.includes(liveGames[i] || liveModels[i] || liveAvatars[i] || brGames[i] || brModels[i] || brAvatars[i])) { // What is this even supposed to do? Check if the string contains an array element using an undefined variable?
  message.channel.send(`The sent creation is in my database.`); // This is the only line I don't have feedback on.
}```
#

the ideal way of checking an array for an element is <Array>.includes(thing) or for an object Object[key] and if that returns undefined you return an error message

coarse topaz
#

Well, I just tried my best lmao, I'm not that good at programming, so I firstly need to see examples and adapt them to my needs. Thank you so much for your feedback! I've taken into account everything you mentioned and now it's working perfectly well. ^^ if (message.content.startsWith(`${prefix}check`)) { let args = message.content.split(" "); if (liveGames || liveModels || liveAvatars || brGames || brModels || brAvatars.includes(args[1])) { message.channel.send(`The sent creation is in my database.`); } } Maybe it's still a total mess, but that mess works, and that's what matters

misty sigil
#

Ah, that's looking a lot better now!

#

there's 1 mistake still

#

you should do .includes(args[1]) on each of the arrays

#

your indentation could be changed from js } } to ```js
}
}

lyric mountain
#

Ctrl + alt + L will do that for u depending on the ide

#

Indentations depite being purely visual, will save u tens of hours finding erros in bigger codes

#

My teacher used to say "you must write codes for people to read not computers, computers will see it in binary anyway"

craggy pine
#

01010100 01110010 01110101 01100101

misty sigil
#

hmm

grizzled raven
#

84 114 117 101

odd stratus
#

Anyone have experience with Lavalink clients here?

#

I have node: set as "1" by default. If a bot has more guilds should there be more nodes?

fervent goblet
#

anyone know how to get the id of the nitro booster role on a server?

#

discord.js btw

sudden geyser
#

Loop up the role by name and see if it’s managed is my guess

fervent goblet
#

thats actually a good idea ty

sudden geyser
#

Actually is the role name editable?

fervent goblet
#

yes

#

might not work

sudden geyser
#

Then that’s no good

fervent goblet
#

because of bot roles

#

hmmm

sudden geyser
#

I’m not sure if there’s a reliable way of seeing if a role is Nitro Booster.

misty sigil
#

mmm

feral aspen
sudden geyser
#

Yeah, but you can’t check what the Nitro Booster role is

unkempt cove
#

good

shrewd creek
#

thx maan it finally worked

sand condor
gilded olive
earnest phoenix
#

does djs implement role tags?

#

role tags are the only reliable way to identify a booster role

sand condor
#

i'm not sure about the master version of it, but pretty sure it's not on v12

oak cliff
#

i got it

drifting wedge
#
@app.route("/api/profile/edit/<bio>/<uid>/")
def api_profile_edit(bio, uid):
    if not current_app.discord.authorized:
        return(f"401 - unauthorized | API |", 401)
    else:
        user = discord.fetch_user()

        authid = user.id

        if authid == uid:
            collection5.update_one({"_id": uid}, {"$set":{"bio":bio}}, upsert=True)
            return("200 - ok | API |", 200)
        else:
            return(f"401 - unauthorized {authid} | API |", 401)```

resp:
```401 - unauthorized 393171225838354433 | API |```
url
```/api/profile/edit/pog/393171225838354433/```, the 393171225838354433 in the resp, is the id of the logged in user
the 393171225838354433 is the id of the user i "say" i am, and its the id i am
rocky hearth
#

Can anybody tell me, which database system does discord use?

solemn latch
#

oh oh i know this one

pale vessel
#

Scylla

solemn latch
#

awh, i knew it just couldnt remeber how to spell it pandasad

gilded olive
slim void
#

What's a better idea, giving my bot a error message saying, "Your bot needs embed links permission", or saying "Your bot needs embed links permission in this channel", grading it by overall or/channel?

earnest phoenix
#

first one

sacred trout
#

yo

drifting wedge
#

wait wadda fuck

#

anyone help?

#

this is me btw, so not like im leaking anything

mellow kelp
#

@drifting wedge the id is a number

#

you're searching with _id as a string

drifting wedge
#

oh lmfao

#

thats so annoying

mellow kelp
#

lmao yes

#

how about storing them as strings?

drifting wedge
#

yes

#

i will

#

thats so stupid

mellow kelp
#

o

#

aight

drifting wedge
#

ty

mellow kelp
#

np

solemn leaf
#

I'm trying to make an array that is filled with random bytes or hex, then turn it into an image buffer into discord

sacred trout
mellow kelp
#

how bout using crypto

narrow marten
#

ello

#

how do I collect messages in discord.js
command = s.game
bot = memorize these words - words 1 words 2. words 3 etc
if other person in the same channel talks and collector collects it, check if its the original author that said s.game, if not, ignore.

solemn leaf
#

Bot.on(message

narrow marten
#

nooo not that

#

collector ig

solemn leaf
#

Unless of you mean a collector

narrow marten
solemn leaf
#

Which just google bcs I'm on my phone

narrow marten
#

ah kk

solemn latch
#

docs show how to use collectors.

narrow marten
#

can't seem to find it tho

#

I can't find how to if other person in the same channel talks and collector collects it, check if its the original author that said s.game, if not, ignore.

solemn latch
#

thats what the filter is for.

narrow marten
#

yes ik but

#

what do I have to write

solemn latch
#

const filter = m => conditional statement here;

narrow marten
#

if (collect.first().author != message.author) return ?

#

kk got it

solemn latch
#

you should probably use the filter

narrow marten
#

const filter = m => m.author === message.author

#

right?

solemn latch
#

yeah, should work

narrow marten
#

alrighty

#

thanks

drifting wedge
#

so like EVERY thing in my db is int/str

#

its not uniform

#

so i just left it lmfao

narrow marten
#

!message.author.bot for non bots only right

mellow kelp
#

yea

narrow marten
#

alrighty

drifting wedge
#

<input type="submit" class="btn btn-outline-success" style="margin-top: 25px;" value="Save" onclick="edit_bio()"> this runs the func right?

solemn leaf
#
const width = 400, height = 400, buffer = new Uint8ClampedArray(width * height * 4);

for(var y = 0; y < height; y++) { for(var x = 0; x < width; x++) { var pos = (y * width + x) * 4; buffer[pos ] = 254;
buffer[pos+1] = 10;  buffer[pos+2] = 1;
buffer[pos+3] = 255;}}

message.channel.send("loading", {files:[buffer]});

It isn't sending the image but no errors are shown

pale vessel
#

try it and see amandathink

sacred trout
#

hey

solemn leaf
#

Flazepe

#

Cans yours helps mes

sacred trout
#

@pale vessel py @client.command() @commands.has_permissions(kick_members=True) async def kick( ctx,member: discord.Member,*, reason=None): try: embed = discord.Embed(title=f"User Kicked!",colour=discord.Colour.green()) embed.set_thumbnail(url=member.avatar_url) embed.add_field(name="**user Kicked**",value=f"**{member}**", inline=False) embed.add_field(name="**Kicked by**" ,value=f"**{ctx.author}**", inline=False) embed.add_field(name="**Reason:**",value=f"**{reason}**", inline=False) await ctx.send(embed=embed) await member.send(embed=embed) except Exception as eror: print(err) await ctx.send("You can use that") await member.kick(reason=reason)

#

is his correct

drifting wedge
mellow kelp
#

if it doesn't exist, create it

drifting wedge
#

It does

#

So the func

mellow kelp
#

you sure

drifting wedge
#

Does 2 things

mellow kelp
#

send code or something idk

solemn leaf
#
const width = 400, height = 400, buffer = new Uint8ClampedArray(width * height * 4);

for(var y = 0; y < height; y++) { for(var x = 0; x < width; x++) { var pos = (y * width + x) * 4; buffer[pos ] = 254;
buffer[pos+1] = 10;  buffer[pos+2] = 1;
buffer[pos+3] = 255;}}

message.channel.send("loading", {files:[buffer]});

It isn't sending the image but no errors are shown

drifting wedge
#
  1. It gets the values of input boxes
mellow kelp
#

what the function does doesn't matter

#

what matters is that it doesn't exist

drifting wedge
#
  1. It makes a p tag be something
#

Does it have to be on the head or body?

#

Bottom of body?

mellow kelp
#

not really sure

#

i think the script should go on the bottom of the body

drifting wedge
#

Well the function does exist

solemn leaf
#

Can I get help

earnest phoenix
#

whats the issue @solemn leaf

#

@drifting wedge is your script accessing objects in the dom

drifting wedge
#

Yes

#

@earnest phoenix

#

Even after I put in in the bottom of the body

#

It still says func doesn't exist

earnest phoenix
#

@drifting wedge send your script

drifting wedge
#

Nrn

drifting wedge
#

Tmr

slender thistle
drifting wedge
#

I don't have backticks on mobile

#

So here u go

#

====
function edit_bio() {
let bio = document.getElementById("bio").value;
let id = document.getElementById("id2").value;
let edit = await fetch(https://domain.com/api/profile/edit/${bio}/${id}/);

let resp = edit.status;

if (resp === 200) {
    document.getElementById("status").innerHTML = "Worked"
}

if (resp === 401) {
    document.getElementById("status").innerHTML = "Nope"
}

document.getElementById("status").innerHTML = "No1pe"

}

#

@earnest phoenix

#

The === is just so u know what's the code itself

pale vessel
#

that function isn't async?

#

you should check the browser console for errors

drifting wedge
#

The func has to be async?

#

@pale vessel

pale vessel
#

You're using await

pale vessel
drifting wedge
#

Mhm alr

#

Prob the func doesn't exist cuz it's not async

#

Do I need to call the func differently? @pale vessel

pale vessel
#

Check your console

#

Press F12

drifting wedge
#

I didn't make it async yet

#

I'm on mobile

frank oasis
#

What is the reason it gives this error? When I vote, I want the command to run.

lament meteor
frank oasis
lament meteor
#

whatever let triggered is... isnt returning a buffer

scarlet stratus
#
import json

def get_prefix(client, message):
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f) 
    return prefixes[str(message.guild.id)] 

bot = commands.Bot(
    command_prefix= (get_prefix),
    )

@bot.event
async def on_guild_join(guild):
    with open('prefixes.json', 'r') as f: 
        prefixes = json.load(f) 
    prefixes[str(guild.id)] = '?'
    with open('prefixes.json', 'w') as f: 
        json.dump(prefixes, f, indent=4) 

@bot.event
async def on_guild_remove(guild): 
    with open('prefixes.json', 'r') as f: 
        prefixes = json.load(f)
    prefixes.pop(str(guild.id)) 
    with open('prefixes.json', 'w') as f: 
        json.dump(prefixes, f, indent=4)

@bot.command(pass_context=True)
async def changeprefix(ctx, prefix): 
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f)
    prefixes[str(ctx.guild.id)] = prefix
    with open('prefixes.json', 'w') as f: 
        json.dump(prefixes, f, indent=4)
    await ctx.send(f'Prefix changed to: {prefix}') ```
slender thistle
#

ok

scarlet stratus
#

First time running library

#

Hope it works

slender thistle
#

Firstly you might wanna use an actual database

#

Secondly just use r+/w+ open mode instead of opening the file twice

#

Possibly even add caching for prefixes

scarlet stratus
#

Uhhhh

#

Seeesh :/

#

My python book is 3.7 idk dude lol

slender thistle
#

Yeah, and I've used Python from 3.5 to 3.8 😛

#

Feel free to Google it

scarlet stratus
#

Oh

#

Okay

slender thistle
#
scarlet stratus
#

Thanks

slender thistle
#

As for caching, the general idea is a dictionary that's attached to your bot object as a property and then used in commands to actually get the prefix

scarlet stratus
#

appreciation

slender thistle
#

So, instead of pulling prefix out of a file every time a command is run, you pull it from cache, which is faster and more reliable. Changing prefix still works via database, but this time you also edit it in cache

#

As for actual databases... eh, you'll get there if you put a bit of time into it

scarlet stratus
#

Kay i gues

#

Thanks for the link :)

slender thistle
#

👍

vale garden
#

hi

@staticmethod
  def user_join(access_token, userr):
   try:

    url = Oauth.discord_api_url + f"/guilds/768019392596017164/members/{userr}"

    headers = {
      "Authorization": "Bearer {}" .format(access_token)
    }

    user_object = requests.get(url = url, headers = headers)
    user_json = user_object.json()

    return user_json

i have this function
for discord oauth2
im trying to add people to a server
but im getting a {'message': '401: Unauthorized', 'code': 0} error
plz help

#

idk if i should really use json there

#

but i tried

#
@staticmethod
  def user_join(access_token, userr):
   try:

    url = Oauth.discord_api_url + f"/guilds/768019392596017164/members/{userr}"

    headers = {
      "Authorization": "Bearer {}" .format(access_token)
    }

    user_object = requests.get(url = url, headers = headers)

    return user_object
#

as well

#

and that got the same error

lament meteor
#

im not rlly a py expert but i think u are supposed to just replace {} with the access_token

vale garden
#

that does the same thing tho

#

and the header worked in another function

#

so i dont think thats causing the error

earnest phoenix
#
    at async TextChannel.edit (E:\ON\node_modules\discord.js\src\structures\GuildChannel.js:355:2``` Text channel edit requires what permission? for channel?
#

Th is the reason for this?

sacred trout
#

Is there any doc on how to make music bot in py

#

Mine only plays when we add he url

earnest phoenix
#
    at RequestHandler.execute (E:\ON\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (E:\ON\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
    at async TextChannel.edit (E:\ON\node_modules\discord.js\src\structures\GuildChannel.js:355:21) {
  method: 'patch',
  path: '/channels/795936099989979146',
  code: 50013,
  httpStatus: 403
}```
#

ANY clue or suggestion?

#

You’re missing something in your coding I think

earnest phoenix
#

Is that a part of the coding or is that like the whole coding?

#

Its not bot issue it channel permission err

earnest phoenix
#

How to check channel perms

#

Oh

#

Hm

#

Oh do you have a command handler?

#

any clue?

haughty mirage
earnest phoenix
#

I am trying to check if channel has permission or not to run that command

silver lintel
#

how can i add an image on top of another image with sharp npm? i looked at the docs but its confusing

haughty mirage
earnest phoenix
#

i am cloning the chhanel then deleting the channel then recreating

near stratus
#

Can someone explain what this means

SyntaxError: Cannot use import statement outside a module```
It's JS btw
earnest phoenix
#

it doesnt works with channel which doesnt has permisions

haughty mirage
#

you bot will need the 'MANAGE_CHANNELS' permission then

earnest phoenix
haughty mirage
#

i reccomend you check out promises to catch errors like that

earnest phoenix
#

already used

haughty mirage
earnest phoenix
#

at async TextChannel.edit

fossil canyon
#

ok, small progress in discord login
How to fix error invalid_grant?
Code vvvv

tight plinth
#

I want to store a variable called "m.av" with the value "{user_avatar}" in quick.db, I want something like { guild_id: { "ar": { "m.av": "{user_avatar}"}}} but due to how quick.db works it converts it to { guild_id: {"ar": {"m": {"av": "{user_avatar}"}}}}. is there a way to prevent that?

#

replacing . with \. does not work

hallow glacier
#

yo can someone help me
i run npm start
which compiles my typescript bot to js and runs it using node build/index.js
npm starts runs npm run build && node build/index.js

#

how can i create a pm2 process

#

with my ts code

#

.-.

tight plinth
#

create the pm2 process but it launches the npm start command

hallow glacier
#

how

#

idk about pm2 that much

#

nvm found out how

earnest phoenix
#

Hi

willow mirage
#

the site is not exist .

earnest phoenix
willow mirage
earnest phoenix
willow mirage
earnest phoenix
#

bots

willow mirage
#

._.

earnest phoenix
#

yea ik

#

how to get token

haughty vortex
#

you could have just said top.gg

willow mirage
#

https://top.gg/bot/YOUR_BOT_ID/webhooks

#

just go there

#

replace YOUR_BOT_ID with your bot's ID

earnest phoenix
#

how do i get it

willow mirage
earnest phoenix
willow mirage
#

Is your bot approved? @earnest phoenix ?

#

Click Generate first

haughty vortex
#

put the is behind the your :3

tight plinth
#

@earnest phoenix click generate

rustic nova
#

generate one there

earnest phoenix
willow mirage
#

._.

rustic nova
#

oh then you cannot do it yet

willow mirage
#

You have to wait brb

tight plinth
#

@rustic nova it also works on the webhooks pagz

rustic nova
#

your bot needs to be approved first in order to use the api

#

Yeah but the docs one is better sure

tight plinth
#

eh

#

I don't use the docs

willow mirage
#

xD

haughty vortex
#

lmfao

#

rtfm

willow mirage
#

???

haughty vortex
#

read the f*ckin manual

#

(basically means read the docs)

slender thistle
#

rtfd

earnest phoenix
#
During your development you will likely run into DiscordAPIError: Missing Permissions at some point. This error can be caused by one of the following:

Your bot is missing the needed permission to execute this action in it's calculated base or final permissions (requirement changes based on the type of action you are trying to execute).
You provided an invalid permission number while trying to create overwrites. (The calculator on the apps page returns decimal values while the developer documentation lists the flags in hex. Make sure you are not mixing the two and don't use the hex prefix 0x where not applicable)
It is trying to execute an action on a guild member with a role higher than or equal to your bot's highest role.
It is trying to modify or assign a role that is higher than or equal to its highest role.
It is trying to add a managed role to a member.
It is trying to remove a managed role from a member.
It is trying to execute a forbidden action on the server owner.
It is trying to execute an action based on another unfulfilled factor (for example reserved for partnered guilds).
It is trying to execute an action on a voice channel without the VIEW_CHANNEL permission.
WARNING

The ADMINISTRATOR permission being granted does not skip any hierarchical check!```
haughty vortex
#

thank you

earnest phoenix
willow mirage
#

but why?

#

why u have to spend time to do that

earnest phoenix
#

who ? me?

willow mirage
#

yes. you

earnest phoenix
#

I didnt spent any time

willow mirage
#

ur just copy paste ._.

#

right?

earnest phoenix
#

yeah

willow mirage
#

but why

#

nobody didn't ask for the Missing permission

earnest phoenix
#

Look someone already got helped

willow mirage
#

uhm, ok . .

bright osprey
#

Hey, I'm having tons of lag when my bot is in many servers. I've tested my bot in both a small bot in one server, and another in approx. 850 guilds. When in the smaller one, it is fast, and the lag is close to zero. However, in the large bot, the bot responds sluggishly, almost a delay of 2 seconds+. The ws ping exceeds over 2000ms (2 seconds) to 200ms. Any tips on that?

ps (if related): my bot is split into different files, and makes a request to a db on every message sent.

past needle
#

oes anyone have a black and white ID emoji?

haughty vortex
#

@young crag here

#

@bright osprey sounds like a badly made bot?

bright osprey
#

does splitting into different files help?

slender thistle
bright osprey
#

No. I've tested this on both a remote server and my own computer.

slender thistle
#

Why does it send a request to your database on each sent message? CatThink

bright osprey
#

It grabs a prefix from a db (MongoDB to be precise).

slender thistle
#

Why not do that with cache?

haughty vortex
#

do you have any idea how much cash that is

bright osprey
slender thistle
haughty vortex
#

it helps to have a db cache layer

#

so you don't have to do two steps each time you update

bright osprey
#

thanks

young crag
#

@haughty vortex god damn it it works locally

haughty vortex
#

yep

young crag
#

i got server count posted successfully

#

not on heroku though

haughty vortex
#

if it's not the environ, it's something to do with a dependency

#

you really gotta tell me the error message lol

young crag
#

man i have that

haughty vortex
#

can

young crag
#

there is no other error

haughty vortex
#

you actually not do that

young crag
#

not do the environ?

haughty vortex
#

not hide the error

young crag
#

but there is no error

#

mate

#

i dont have any error

#

it just doesn't load

haughty vortex
#

?

#

there's no error because you're hiding it

young crag
#

where do i hide it lol

haughty vortex
#

"Couldn't load cog X" but no details about why it doesn't load

slender thistle
#

then print e

haughty vortex
#

eh

young crag
#

ohhh you mean that

#

dude

#

lmao

haughty vortex
#

or just import traceback

#

and traceback.print_exc()

slender thistle
#

exc

haughty vortex
#

i use windows ok

#

smh

#

no bulli

slender thistle
#

I use Windows too UwU

haughty vortex
#

heretic

young crag
#

oh boi oh boi now we are talking

#

dude that's what you get when you don't touch something in half a year

haughty vortex
#

finally

#

details

young crag
#

lmao

#

gonna

haughty vortex
#

i knew it

young crag
#

update requiremtnt

young crag
#

requirements

haughty vortex
#

lmfao

young crag
#

english is hard alright

#

lmao

haughty vortex
#

true

young crag
#

eureka

#

thank you dude i'm forever grateful ❤️ @haughty vortex

haughty vortex
#

no issue

#

pro tip: never hide exceptions

young crag
#

lesson learned

slender thistle
#

unless you are 2000% sure you aren't doing it wrong

haughty vortex
#

you could do this: print(f"Couldn't load cog {filename[:-3]}: {e}")

#

just as effective, usually

earnest phoenix
#

Why is this not working?

teal egret
#

WAIT

#

lol

#

if (deletecount or whatever) {
message.channel.send('no')
}

#

@earnest phoenix

#

and come on, this is basic JavaScript

zenith terrace
#

imagine forgetting the () when doing if

earnest phoenix
#

Wha?

#
if (deletecount > "99"){
return message.reply(`I Can't Delete More Than 99 Message`);
}
#

Can this work?

teal egret
#

nope, buddy, you should try to learn basic JavaScript before jumping to a discord bot

earnest phoenix
#

@teal egret the thing is that, lmfao it worked before now it’s not

teal egret
#

how the

#

that's impossible

earnest phoenix
#

Not really

teal egret
#

it's improper syntax

earnest phoenix
#

Then why did it work?

teal egret
#

did it work tho?

earnest phoenix
#

Ye

#

But now it’s not...

#

I mistakenly deleted some of the coding then yea.. now it’s not working

teal egret
earnest phoenix
#

Lol

#

Bruh..

#

That’s the original coding

teal egret
#

Mhm, that looks about right.

earnest phoenix
#

Hm

#

So what’s wrong with this you see?

teal egret
#

yOu NeEd a () iN uR iF

#

and why tf are you coding on mobile

earnest phoenix
teal egret
#

Ye

earnest phoenix
#

Ipad* @teal egret

teal egret
#

mobile

#

same thing

earnest phoenix
#

Not reall

#

I have a large screen I mean it’s fine

teal egret
#

alr I'm done here, this is dumb

earnest phoenix
#

How-?

#

@teal egret bruh it’s showing error...

#

Hm?

marble juniper
#

what is the error

#

also please use a formatter

pale vessel
#

Nah, minify all your code xD

rocky hearth
#

Is it possible to recursively call an anonymous function in js?

#

I want to return the anonymous function, within itself!

haughty vortex
#

what in the heck

dreamy stirrup
#

😱

crimson vapor
#

how in ts would I efficiently check if something is in the type I included

#

so I have type, lets say its type x = 'a' | 'b'

#

how would I check if value: string is included in x

quartz kindle
#

but you can give it a name even if its self-executable or in a callback

earnest phoenix
#

Can Anyone Help Me With 24x7 Hosting ?

rustic nova
#

read pins for 24/7 hosts

quartz kindle
#

try using arguments.callee

crimson vapor
#

what is arguments?

#

in this use-case?

quartz kindle
#

arguments is a reserved variable that exists inside functions

crimson vapor
#

oh

quartz kindle
#

it contains an array of function arguments and information about the function itself

#

it only exists in normal functions, not in arrow functions

crimson vapor
#

What is the best way to add more to a string if it already exists, if it doesn't set it to another value?

quartz kindle
#

strings are immutable, no matter how you add/change/edit them, it will always create a new string

crimson vapor
#

I would do js str = ''; str = str ? str + x : y

pale vessel
#

huh

crimson vapor
#

that does what i want to but it seems inefficient

quartz kindle
#

from my tests, the fastest way to add stuff to a string was to use +=

crimson vapor
#

what about if the string is empty?

pale vessel
#

it works

quartz kindle
#

you can still use +=

pale vessel
#

since it's still a string

crimson vapor
#

but I need something different if its empty

quartz kindle
#

if(!str) str += initialData
str += data

#

assuming str is "" and not null or undefined

crimson vapor
#

no im defining it before the loop

quartz kindle
#

take a look at my FTSet lib, i did a ton of micro-benchmarking on it lmao

crimson vapor
#

oh

#

lmao

#

good point

quartz kindle
#

slice is faster than substring

#

but substr is faster than slice

crimson vapor
#

actually?

quartz kindle
#

however substr is mostly deprecated

crimson vapor
#

oh

#

thats strange

quartz kindle
#

but you'll only see difference if you loop them like 99 million times lmao

crimson vapor
#

like the difference between using an object or a map

#

so small it basically wouldn't matter

quartz kindle
#

ye

#

str += str is also faster than str = str + str

crimson vapor
#

is that because you are reassigning it?

quartz kindle
#

most likely because of some internal micro optimization in v8

crimson vapor
#

oh ok

quartz kindle
#

also, then you add stuff to strings, they are not actually concatenated in v8

#

v8 creates a sort of binary tree to keep pieces of floating strings

#

so concatenating strings in js is super fast

#

but when you try to read this string, that binary tree is lazily concatenated

#

so the first read is much slower

willow mirage
#

damm Tim, how did you know so much from optimizing code

quartz kindle
#

because im weird

willow mirage
#

xD

crimson vapor
#

testing I assume

quartz kindle
#

i like performance testing random stuff

willow mirage
#

like there are no Docs for these thing

earnest phoenix
#

there are

willow mirage
#

but hard to find

restive furnace
#

nodejs docs

earnest phoenix
#

^

#

and N-API

crimson vapor
#

Tim how much ram do you have?

restive furnace
#

how this is connected to development or this discussion?

quartz kindle
#

on my pc or on my vps?

crimson vapor
#

what do you test on mostly?

earnest phoenix
#

In .replit file
language = "go"
start = " "
What should I write in start?

quartz kindle
#

i test on my windows pc mostly, 8gb ram, i5 7400hq cpu

crimson vapor
#

do these test max your ram?

quartz kindle
#

no

crimson vapor
#

oh

quartz kindle
#

these are cpu tests

#

just measuring how much time to complete X loops of something

crimson vapor
#

oh

rocky hearth
quartz kindle
#

yes

neat loom
#

Hi

rocky hearth
# quartz kindle yes

TIM , you're so good in js. I wonder why you have not yet got your hands dirty in typescript.

earnest phoenix
#

So why in the world is this not working?

#
    let kkanal = await db.fetch(`kayıtK_${member.guild.id}`)
    let kgr = await db.fetch(`kskgrol${member.guild.id}`)
    moment.locale("tr");
    if(!kkanal) return 
    if(!kgr) return 
    client.channels.cache.get(kkanal).send(`Hi`,
      new Discord.MessageAttachment(
        "https://media.giphy.com/media/3ov9k1J6jahVhiev0Q/giphy.gif"
      )
    );
  });```When I extract the Discord attachment it works with the command but when I put it it doesn't work. Where's the error?
#

Log is clear

quartz kindle
earnest phoenix
rocky hearth
#

But what is the need to control the final js representation. The ts files can look good.

earnest phoenix
#

Bru-

quartz kindle
#

the final js code usually has a ton of safeguards put there by ts, which can make the overall code slower

earnest phoenix
#

Help..

rocky hearth
# earnest phoenix

u need to fetch all the messages first.
For that the bultDelete takes a 2nd argument

quartz kindle
#

you dont need to fetch first

#

2nd param is optional

#

and bulkDelete accepts a number

earnest phoenix
#

So why is this not working?

quartz kindle
#

what does "not working" mean? any error?

earnest phoenix
#

It’s just not working nor showing errors

#

@quartz kindle

quartz kindle
#

show your command handler

earnest phoenix
#

Alr

willow mirage
#

maybe you have to resolve the promise

earnest phoenix
#

It worked before @willow mirage

willow mirage
#

hmm

sacred trout
#

yoi

cinder patio
#

I'm pretty sure ts doesn't add any type-guards to the final js code

tardy hornet
#

i have a question guys, not a code

#

is this a good host?

#

anyone know?

quartz kindle
#

doesnt look bad

#

the "festive discount" makes it not bad

#

looking at the vps offerings of course

#

i wouldnt go for "discord bot hosting"

tardy hornet
#

ty tim

#

i will finally use something that isnt heroku lol

#

heroku is the worse

quartz kindle
#

2gb ram for less than 4 usd is very good indeed

earnest phoenix
#

i need help

pale vessel
#

ok

earnest phoenix
#

heroku

crimson vapor
#

add .json

pale vessel
#

why

crimson vapor
#

I assume config is a json which needs the file extention in order to be required iirc

pale vessel
#

nope

crimson vapor
#

hmm

solemn leaf
#
const width = 400, height = 400, buffer = new Uint8ClampedArray(width * height * 4);

for(var y = 0; y < height; y++) { for(var x = 0; x < width; x++) { var pos = (y * width + x) * 4; buffer[pos ] = 254;
buffer[pos+1] = 10;  buffer[pos+2] = 1;
buffer[pos+3] = 255;}}

message.channel.send("loading", {files:[buffer]});

It isn't sending the image but no errors are shown

earnest phoenix
#

Help please? It’s showing no error and it’s not working and yes I have a command handler

crimson vapor
#

what is it not doing?

earnest phoenix
#

It’s not working

#

My bad it’s this

#

Why is this not working?

#

It’s not showing error too

#

debug it then

quartz kindle
#

bold to assume they know what debugging is

quartz kindle
earnest phoenix
#

oh i didnt see who was asking the question

#

lol

quartz kindle
#

lmao

earnest phoenix
#

@earnest phoenix wow you just offended them

#

Debugging? Wow

timber fractal
#

Why if i try to use this code it says "cannot send messages to this user"?

opal plank
timber fractal
#

oh sorry

quartz kindle
opal plank
#

theres nothing in that link

#

oh, nvm it loaded

timber fractal
#

lol

earnest phoenix
#

My uh screen isn’t that bug lol. @quartz kindle

#

in order to dm a user two conditions have to be met
share a guild with the user
the user needs to have dms enabled

quartz kindle
#

like hastebin

opal plank
timber fractal
opal plank
#

so the bot cant dm them

timber fractal
#

with dms open

sage flower
#

But if someone else's DMs are disabled, you'll get an error

earnest phoenix
#

literally read my message

opal plank
#

if thats a discord error being thrown, its clear

#

that user dont have dm's open

earnest phoenix
#

when you kick or ban a user there's a high chance that you won't have a shared guild anymore and you cannot message the usee

#

user

timber fractal
#

but his dms are open im sure

earnest phoenix
#

literally read my message

opal plank
#

discord disagrees

earnest phoenix
#

lol

sage flower
timber fractal
solemn leaf
#

Can I get help with making my buffer valid

timber fractal
sage flower
#

It's not like the error is lying to you

earnest phoenix
#

you're not sure that the timeout is going to execute after dming

opal plank
#

show your privacy settings on the guild on your ALT's account

earnest phoenix
#

dm first, then kick/ban

timber fractal
#

let me try it

opal plank
#

also that

earnest phoenix
#

which is what ive been saying from the start

opal plank
earnest phoenix
#

🙄

opal plank
#

i assume its being sent first

#

await it at least

quartz kindle
#

you cant chain promises like that

timber fractal
quartz kindle
#

your promises are being executed concurrently

sage flower
#

It at least provides comfort that a message will maybe probably be sent.

timber fractal
#

@earnest phoenix i did this now js member.send(dmEmbed).then(message.delete()).then(member.ban({timeout: 100})) and it still says the same error

quartz kindle
#

again

#

you cant chain promises like that

timber fractal
#

oh

quartz kindle
#

let me show you an example

timber fractal
#

how than?

opal plank
#

await/async

timber fractal
#

ah good 1

#

@quartz kindle can u show me a example?

sage flower
#

Give him a moment.

quartz kindle
#

look at the timestamps

timber fractal
#

okay

quartz kindle
#

you are doing the first option, giving the promise itself to .then(), like this: .then(Promise)

#

that makes the promise execute instantly

#

in the second example, the promise is awaited correctly, like this: .then(() => Promise)

sage flower
#

That's actually helpful, I didn't know that tbh.

timber fractal
#

lol

quartz kindle
#

its like passing functions as an argument

#

its the same principle as this:

earnest phoenix
quartz kindle
#
function bla(arg) { console.log(arg) }

bla(something) // pass something function to console.log
bla(something()) // execute the function and pass its result to console.log
#
.then(Promise) // execute the promise and pass it to the function
.then(() => Promise) // pass a callback function that when called will execute the Promise
earnest phoenix
#

@quartz kindle what’s the problem you see?

quartz kindle
#

add this

#

that will make it show in your console if the command is actually being found

earnest phoenix
#

Alr

quartz kindle
#

are other commands working?

sullen trout
#

Hello i have a webSocket server with socket.io like this

io.on('connection', function(socket){

        console.log('New user is connected, Body :', socket.request.body.token);

        socket.on('disconnect', function (){
            console.log('a user is disconnected');
        })

        socket.on('chat message', function (msg){
            console.log('message recu : ' + msg);
            io.emit('chat message', msg);
        })

    })

but i want that when a user connect to the webSocket he pass a token in his body request is it possible ? i tryed to do this in my client side but it didn't work i can't acces to the body

var socket = io('localhost:3000', {
        token: 'token'
      });

Ping if you can help me pleaze

earnest phoenix
#

Hello please help me.
How to check "if (args[0]) youtube ID is invalid"?

#

someone understand :D?

sullen trout
#

How ?

cinder patio
#

localhost:3000?param=something

socket.request.query.param
sullen trout
#

Ah ok

dusky sundial
earnest phoenix
#

@cinder patio love your profile picture remind me of my childhood

cinder patio
#

thanks

#

I guess

earnest phoenix
cinder patio
# sullen trout Ah ok

Actually I am not sure if that works on socket.io I've only used ws. I read that it's socket.handshake.query, not socket.request.query

earnest phoenix
#

@quartz kindle oh ok

dusky sundial
#

@earnest phoenix do you know what type of error it gives you? You could try catching it with a try/catch statement

earnest phoenix
#

How can i use the try()?

dusky sundial
#

What language are you using?

earnest phoenix
#

discord.js

#

node.js

quartz kindle
#

then you did something wrong

earnest phoenix
#

try {} catch?

dusky sundial
#

You can do something like this

try {
  //Do the things you want here
} catch (err) {
  await message.channel.send("Something went wrong")
}
earnest phoenix
#

try { //code } catch(e)}

#

Bruh

dusky sundial
#

Don't trust that code to 100% lol, I'm not good with js

earnest phoenix
#

I think its fine but why did you put await

crimson vapor
#

because it returns a promise

sudden geyser
#

It's correct.

dusky sundial
#

I've never made a bot with js lol, I just assumed that the send method had to be awaited

quartz kindle
#

your assumption is correct

dusky sundial
#

Cool Bunnyuwu

earnest phoenix
#

hm, the same error

crimson vapor
#

its not required

#

unless you are doing something with the message

earnest phoenix
#

script

  if(command === 'subs'){
      var request = require('request')
      if(!args[0]) return message.channel.send(`${message.author}, please add a youtube channel ID`);
      var id =  args[0];
      var key = '-------------';
      var url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + id + "&key=" + key;

      try {
        request({
          method: 'GET',
          url: url
      }, function (err, response, text) {
          if(err){
              return;
          }

          var json = JSON.parse(text);
          console.log(json)
          var subc = json.items[0].statistics.subscriberCount;
          message.channel.send(`Youtube ID: **${args[0]}** Subscribers : **${subc}**`)
      }
      )
      } catch (err) {
        message.channel.send(`Error: Invalid youtube channel ID`)
      }
  }```
#

@crimson vapor

crimson vapor
#

ive got school, can't read through it rn

earnest phoenix
#

ok

#

@dusky sundial 👀

dusky sundial
#

Try printing the error and see what it says with console.log(err)

#

Or see if it even enters the catch statement

earnest phoenix
#

emm

#

nice!

#

working

#

@dusky sundial thanks buddy for the help

#

@quartz kindle my whole coding is ruined now nothing is working :(.

#

Finally after long time new update pushed. https://top.gg/bot/783594136741609533

quartz kindle
earnest phoenix
#

@quartz kindle no, when I removed it then I pasted it back nothings working :(...

quartz kindle
#

that just confirms you did something wrong

earnest phoenix
#

I don’t see it, be honest you don’t see any error neither

#

computers don't lie

quartz kindle
earnest phoenix
#

if there's an error, then there's an error

#

computers don't lie about errors because they want to make your life hard

#

errors are errors regardless whether you can identify them or not

sudden geyser
#

Party on a scale from 1 to 10, how well would you say you understand JavaScript?

dusky sundial
#

It's usually a terrible idea to copy and paste code that you can't understand

earnest phoenix
sudden geyser
#

negative numbers are accepted too

earnest phoenix
dusky sundial
quartz kindle
#

wasnt partyman called santa claus before?

earnest phoenix
#

its not terminal error

dusky sundial
#

Oh, I see

earnest phoenix
#

err variable

earnest phoenix
#

they're a help vampire

dusky sundial
#

The Party guy offered me $50 to finish his bot with 67 commands in DMs lol

#

that's $0.74/hour, assuming every command takes an hour to finish. Which is being generous

earnest phoenix
#

.-.

dusky sundial
earnest phoenix
#

underpaid labour

#

yum

crimson vapor
#

oh wait actually?

earnest phoenix
#

okay

crimson vapor
#

partyman was santa clause?

earnest phoenix
#

wait till they find out the actual salary of a senior dev

quartz kindle
#

thats even worse than an offer i got once, 200 bucks for a bot with 100+ commands

dusky sundial
#

People seem to think that making an entire bot takes two hours

crimson vapor
#

honestly its inexcusable if you are told multiple times to learn something, and then just come back and ask the same question

earnest phoenix
#

help vampirism

dusky sundial
#

Programming isn't for everyone shrugging

crimson vapor
#

its worse

crimson vapor
#

help vampirism is not as bad as what this is

misty sigil
crimson vapor
sterile lantern
#
const Discord = require("discord.js")
require('dotenv').config();

const axios = require('axios');
const discord = require("discord.js")
console.log("count init");
let wid = process.env.wid 
let wtoken = process.env.wtoken
let GROUP_ID = a
let GOAL = 28000
let count = 1
let webhook = new discord.WebhookClient(wid, wtoken)
async function updateCount() {
    let response = await axios.get(`https://groups.roblox.com/v1/groups/${GROUP_ID}/`)
    let response_count = parseInt(response.data.memberCount) 
    //console.log("got request")
    
    if (count < response_count) {
        console.log(response_count, count) 
     const embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setThumbnail('cool link')
.setAuthor('Member Counter', 'link')
.addFields(
        { name: 'Current Count:', value: response_count, inline: true },
    { name: 'Members left till 28k:', value: GOAL - response_count, inline: true },
    //    { name: 'Goal', value: GOAL, inline: true },
    )
.setFooter("Member Counter")
.setTimestamp()
webhook.send(embed).catch(async err => {
    console.log(chalk.red('Issue with posting: ' + err));   
});  
  if (count == 0) {
            count = response_count
            return;
        }
        count = response_count
}
}

setInterval(() => {
  updateCount().catch(async err => {
    console.log(chalk.red('Issue with posting in: ' + err));   
});  
    
}, 33000);```
#

how come this only sends

#

every like

#

15 mins?

#

like someone leaves the group and it doesnt send the embed

earnest phoenix
#

you 👏 cant 👏 code 👏 if 👏 you 👏 cant 👏 think 👏

i cant stress this enough, if you cannot logically think and resolve problems, then this is not for you, find another hobby like knitting

it's like forcing myself to be a surgeon but i don't like blood

misty sigil
#

lmao

#

that’s a great comparison

crimson vapor
#

there is this cool fancy keybind in vsc, SHIFT ALT F, its not that hard to do

sterile lantern
#

huh?

dusky sundial
#

@sterile lantern maybe there's a rate limit on the api you're using? Just a guess

misty sigil
#

I’m on mobile

#

but that code looks terrible

quartz kindle
#

it only sends if response_count is bigger than count

sterile lantern
#

oh

#

well

#

count is 1

#

but it changes

#

so hm

quartz kindle
#

when a person leaves, is response_count decreased?

sterile lantern
#

yep

misty sigil
#

oh that’s alright

quartz kindle
#

so thats your problem

sterile lantern
#

oh oof

dusky sundial
#

Indents get messed up on mobile, it's terrible lol

quartz kindle
#

if you want to send whenever the response_count changes, then check if response_count is not equal to count

misty sigil
#

I don’t like that it does } } tbh

quartz kindle
#

instead of checking if its bigger or smaller

crimson vapor
#

yeah it makes code so confusing for me when everything is

{
}
}```
not ```
{
  {
  }
}```
sterile lantern
#

so != right

crimson vapor
#

!= is never used is it?

sterile lantern
#

isnt that not equal

misty sigil
#

not really

crimson vapor
#

ive only ever seen it used in java for null

misty sigil
#

no

sterile lantern
#

o

sacred trout
#

What do I need to do to add my bot

quartz kindle
#

!= is used yes

crimson vapor
#

!== or !===

misty sigil
#

!== or !===

sterile lantern
#

oh two

#

alright

#

ty

quartz kindle
#

!=== doesnt exist in js

crimson vapor
#

oh

#

right

sacred trout
#

What do I need to do to add my bot

pale vessel
#

!===============

sacred trout
#

In top. Gg

crimson vapor
#

top dot gee gee

misty sigil
#

!=========================

#

strict

quartz kindle
earnest phoenix
#

!!=

crimson vapor
#

what is != tim?

dusky sundial
#

Make the bot useful, finish it before uploading to top.gg

quartz kindle
#

!= is the opposite of ==

crimson vapor
#

oh

earnest phoenix
#

! is always an inverter, NOT operator

crimson vapor
#

so value is not equal but doesn't care about types

quartz kindle
#

yes

#

you can use != for 1 != "1" for example

sacred trout
#

Is there any requirement?

#

Like only a bot with a specific thing gets verified

quartz kindle
sacred trout
#

And how much time does verification takes

quartz kindle
#

idk whats the current waiting time, about a week i think?

sacred trout
#

Thanks

dusky sundial
#

Yeah, like 5 days at least I'd say

sacred trout
#

BTW js Dev or py dev

#

@quartz kindle

quartz kindle
#

im a js dev, if thats what you're asking

earnest phoenix
#

Why isn't working?

  if(command === 'subs'){
      var request = require('request')
      if(!args[0]) return message.channel.send(`${message.author}, please add a youtube channel ID`);
      var id =  args[0];
      var key = 'AIzaSyAZknfjAzmK0wsKUc2sm-DDwFPbUj18OC0';
      var url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + id + "&key=" + key;

      try {
        request({
          method: 'GET',
          url: url
      }, function (err, response, text) {
          if(console.error()){
            message.channel.send(`${message.author}, Error: Invalid youtube channel ID (${args[0]})`);
            message.channel.send(`https://cdn.discordapp.com/attachments/785126372515381251/796026765243056158/unknown.png`);
            return;
          }

          var json = JSON.parse(text);
          console.log(json)
          var subc = json.items[0].statistics.subscriberCount;
          message.channel.send(`Youtube ID: **${args[0]}** Subscribers : **${subc}**`)
      }
      )
      } catch (err) {
        message.channel.send(`${message.author}, Error: Invalid youtube channel ID (${args[0]})`).catch(err => console.log(err))
      }
  }```
quartz kindle
#

what about it is not working

pale vessel
#

that's always false

earnest phoenix
#

how can i fix that?

pale vessel
#

it's probably if (err) {}

earnest phoenix
#

yes but it wrong again

#

try not copypasting

pale vessel
#

you shouldn't be using a deprecated lib

#

use node-fetch

#

and callbacks, ugh

crimson vapor
#

how many if statements is too many?

pale vessel
#

Check yanderedev code

dusky sundial
#

That's a worst-case scenario lol

earnest phoenix
#

game not slow just get better pc!!! 🤬🤬🤬😡

pale vessel
#

app not unresponsive, just get bigger screen!!! 🤬🤬🤬😡

dusky sundial
#

He's not a bad programmer it's just not hIs ArEa Of ExPeRtIsE

crimson vapor
#

but realistically how many if statements should you stay under?

cinder patio
#

I'd say 3

dusky sundial
#

Pretty hard to say, I guess it depends on how much is in the actual statements. But yea, 3 sounds reasonable

crimson vapor
#

but thats just preference

#

how many if statements do you need to actually make code slower

quartz kindle
pale vessel
#

"blood", "insanity" seems like it yeah

dusky sundial
#

Allegedly, I know some people say it's fake

#

but I wouldn't be surprised

quartz kindle
#

who wants to make BetterYandereSimulator

pale vessel
#

It's a thing

earnest phoenix
#

there's a decompiled version on github, it isn't the original code because it was processed by unity but there's still some traces of his horrid code

dusky sundial
#

The guy seems to spend more time arguing with people over the game rather than developing the actual game

earnest phoenix
#

this tbh

#

spends more time justifying why he cant work on the game rather than working on it

crimson vapor
#

cry do you know how many if statements are too many?

#

I know its more personal preference

#

but when is it just inefficient

earnest phoenix
# quartz kindle who wants to make `BetterYandereSimulator`

ironically enough every single person who tried to make a rival game to yansim turned out to be mentally retarded and dropped the project, the most recent being love letter

attention seeking furry allowing staff to sexually harass people then having a dramatic exit 👁️👄👁️

#

@crimson vapor it really depends on the context

crimson vapor
#

how so?

quartz kindle
#

lmao

earnest phoenix
#

for example in the above code, sure switch can be used, however you can also use a bit mask and if else that, which is arguably the most performant way

quartz kindle
#

it really depends on what kind of data you need to if about

earnest phoenix
#

this

crimson vapor
#

an else if is only the amount of if statements as the first if that was true right

quartz kindle
#

if you're doing something like "if the sun is yellow, else if the moon is blue, else if the ocean has water", then use if else

#

if you're doing something like "if the sun is yellow, else if the sun is red, else if the sun is blue", use switch

crimson vapor
#

ok that makes sense

#

another question

quartz kindle
#

then you can further expand it by what each of those options is supposed to do

crimson vapor
#

how slow is if

#

like realisticaally?

earnest phoenix
#

it isn't

#

whats inside of it is slow

#

the comparisons you're doing affect performance

quartz kindle
#

a comparison is one of the fastest possible operations in computing

earnest phoenix
#

that's why i mentioned bit masks

#

they're a super fast way to check for a specific flag on a bunch of properties

quartz kindle
#

what you should think about is not "how to compare faster" but "how to reduce the number of comparisons needed"

#

for example if you have 100 if elses in a row, and you want to match the last one, you will do 100 comparisons for nothing

#

so you should split your code in a way, that you reduce the number of comparisons needed, by grouping options or something else

crimson vapor
#

but realistically since if statements are generally very fast, as long as you are using if else and switch case when applicable, code would be fine

quartz kindle
#

yes

#

however then you must also factor in code maintainability

crimson vapor
#

is that why functions are generally chained?

quartz kindle
#

stuff like assembly is the fastest possible thing you can get, but nobody realistically uses it because its overly complex and complicated

#

in js, 500 if elses will probably be faster than array.find(), but you need 500 lines of crap when you could have 1 that does the same thing

earnest phoenix
#

a compiler will always optimize more than a human in asm

crimson vapor
#

oh I see

#

so people really don't like lots of if statements because its ugly and hard to maintain

#

assuming it was used correctly

quartz kindle
#

the rule i follow is prefer code readability and simplicity, except in places that are expected to be used multiple times, for example in loops

crimson vapor
#

that makes sense

#

object[key] is just about instant right?

quartz kindle
#

mostly yes

#

it depends on how v8 is running it behind the scenes

crimson vapor
#

oh that makes sense

quartz kindle
#

since a js object can be backed by different c/c++ structures depending on size, key types, data types, etc

crimson vapor
#

I also assume bigger object require memory allocation which takes more time

cinder patio
#

everything requires memory allocation

crimson vapor
#

yeah but an object with 1 entry takes more than an object with 2^24 entries

cinder patio
#

well by everything I mean data

true ravine
#

Not entirely applicable here, but when I try to cd on my vps it says that the private ip of the vps is unavailable - is that firewall or something else?

cinder patio
#

I guess it depends on the types of the entries - if they are other big objects then sure...

quartz kindle
#

all data structures have a certain overhead, for example if your key size is 10, your data size is 100, an object containing this key and data will likely use more than 110

#

this overhead includes indexing, hashing and other stuff to keep information about the object

crimson vapor
#

Tim is it more memory efficient to export classes or just raw objects for commands and stuff?

#

I assume raw objects

cinder patio
#

you won't see a difference

quartz kindle
#

there is likely no difference

#

that kind of stuff is only relevant of you have a million commands

crimson vapor
#

oh

#

so it would just be personal preference at that point

cinder patio
#

yea

quartz kindle
#

however, classes for commands only make sense if you have a base class that all commands extend

#

otherwise singleton classes for commands dont make much sense

cinder patio
#

classes for commands is super unnecessary

crimson vapor
#

I mean an extention of the main base command

cinder patio
#

what would you extend?

misty sigil
#

the base command

#

but what would the base command be

quartz kindle
#

the base command class could have methods to access a database for example

misty sigil
#

oh that makes sense

cinder patio
#

to me it sounds pointless & overcomplicated

misty sigil
#

db is my least favourite but favourite thing

crimson vapor
#

I don't mind db

#

but I really need to create good functions for the DB to have better caching

misty sigil
#

in db, working in prod is something that you don’t do

crimson vapor
#

not an issue if you store nothing

misty sigil
#

aye, fair enough

earnest phoenix
#

it would be smarter to take a module based approach

a singleton class that contains all your command functions, that allows you to split into different categories etc

#

this is by far the best approach

#

dpy does it with cogs

#

dnet & dsharp with modules

crimson vapor
#

when you create instances of different classes, does each class require the same amount of memory for functions, or are all of the classes using the same functions in memory?

cinder patio
#

I'm pretty sure they use the same function with a different this

crimson vapor
#

so properties declared as this. are unique while functions are not?

cinder patio
#

mmm

crystal yew
#

Does the widget not work on google sites?

crimson vapor
#

what is it showing?

umbral zealot
#

You'll have to be a lot more precise. What widget? What site? What are you doing exactly?

#

Hint: no one can see your screen so we have no idea what you're talking about.

cinder patio
crimson vapor
#

so this is showing that a.get and b.get are the same in the memory?

cinder patio
#

yes

crimson vapor
#

ok

#

pog

mellow kelp
#

they're the same method in the same instance

#

so ye

cinder patio
#

not the same instance

mellow kelp
#

oh wait

#

panik

#

now im the one whos confused

#

anyways

#

✨ the magic of javascript ✨

#

imma head out now

cinder patio
#

not really... making a different function for each instance would be super wasteful

umbral zealot
#

The code is in the class, the instance is only basically the properties that you have.

crimson vapor
#

is that why Object.keys() on a class only shows the this. properties?

umbral zealot
#

yes.

mellow kelp
#

that makes sense

earnest phoenix
#

everything is in the same memory, not everything has the same pointer

mellow kelp
#

i guess thats why its necessary to use this on classes

umbral zealot
#

Of course if you modify one of those methods with your own then it'll remove the point and it'll no longer be equal.

mellow kelp
#

so methods are the same for every instance, but they are executed with different
this context?

cinder patio
#

think of this as an function argument passed by the V8 engine that points to the instance of the class

#

yeah

mellow kelp
#

hm aight

crimson vapor
#

V8 engine is written in what language?

cinder patio
#

c++

crimson vapor
#

we should all just take c++

mellow kelp
#

the this keyword is easier to understand than i expected

quartz kindle
#

js classes are built on top of prototypes

#

so basically when you do ```js
class A {
something() {}
}

#

you're doing ```js
A.prototype.something = function() {}

#

the prototype is like a blueprint