#development

1 messages · Page 1528 of 1

earnest phoenix
#

What

sudden geyser
#

doubt

zenith terrace
#

only like 0.01% of whitenames here are good whitenames

#

code?

earnest phoenix
#

Brutally ignores what i said and links the question again

#

150% brain cells lost so far

zenith terrace
earnest phoenix
#

Uh guys what about me?

dusky sundial
zenith terrace
#

elaborate better?

#

thats kinda confusing

dusky sundial
earnest phoenix
#

Wtf, did I just say..

#

175% brain cells lost so far

solemn latch
#

you know it helps to put your question and your code in the same message right?

earnest phoenix
#

Wait, I’m dumb I explained wrong

#

Like one part embed, and one part not-embed so how do I do that

#

I.e

#

So the message both has a content and an embed?

zenith terrace
#

message.author.send("text", embed)

#

iirc

earnest phoenix
#

Mhm, like it’s 1.19AM and I also my brain cells at -0 @earnest phoenix

#
<TextChannel>.send('content', {
   embed: <your embed here>
});```
#

Why does autocorrect make my damn sentences not make sense..

zenith terrace
#

does message.author.send("text", embed) not work @earnest phoenix ;-;

earnest phoenix
#

It doesn't since the second parameter needs to be an object

#

And, I need one without embed

#

Already have the embed one

#

Uhh

#

Umm

#

[Visible Confusion]

#

Hm, like look at this

zenith terrace
#

change <TextChannel> to message.author

earnest phoenix
#

One is not embed, and one is embed

dusky sundial
#

Isn't that what he told you how to do?

earnest phoenix
#

I literally sent the right code to do that

#

No, it’s a dm help command not a channel one

#

DM channel is also a text based channel

#

<TextChannel><Message>.author

#

Alrighty, thanks

#

But, I don’t want it embed

zenith terrace
#

I just said that smh

earnest phoenix
#

300% brain cells lost so far

dusky sundial
#

Oh man this guy is going to die tonight lol

earnest phoenix
dusky sundial
#

He legit just told you how to send text and an embed

#

Scroll up

earnest phoenix
#

Like, a none embed one

dusky sundial
#

This is exactly what you want

earnest phoenix
#

It’s embed...

dusky sundial
#

so replace content with the thing you don't want in the embed

earnest phoenix
#

..

dusky sundial
#

I understand why people don't want to become teachers now

zenith terrace
earnest phoenix
#

You guys are not understanding what I mean...

#

Yes, one embed and one not

zenith terrace
#

yea so

earnest phoenix
#

I’ve already made an embed one

dusky sundial
#

Yes, and that's exactly what the code above does

earnest phoenix
#

That's literally what i said

crimson vapor
#

voltrex

earnest phoenix
#

Now I need the one without embed

zenith terrace
#

message.author.send("content", embed)

earnest phoenix
#

500% brain cells lost so far

crimson vapor
#

how should I turn 'x.x.x.x.x' into ['x']['x']['x']?

#

so its a nested object

#

kinda

earnest phoenix
zenith terrace
#

it sends content outside and inside an embed at the same time in the same command

earnest phoenix
#

Thanks

#

Also thanks @earnest phoenix

zenith terrace
earnest phoenix
#

Thank you

earnest phoenix
#

OMG, AUTO CORRECT I SWEAR

zenith terrace
#

lol

earnest phoenix
#

Damn, he just completely ignored what i said at first tho

dusky sundial
#

Yeah lol

#

Or didn't bother to read it

earnest phoenix
#

No I was a bit confused and my eyes are red rn and from what I’m seeing it’s kinda blurry for me

crimson vapor
earnest phoenix
#

Oh

#

I see what you mean

crimson vapor
#

ye

earnest phoenix
#

So like

#

Are the x the inputs?

crimson vapor
#

yes

#

say 'response.first.url' or 'response.second.delete_url'

#

its all different

#

but my code needs to work

earnest phoenix
#

@zenith terrace do I put it under message.author send help or line 12?

zenith terrace
#

message.author.send("content", help)

earnest phoenix
#

Yes, but under message.author... or do I replace it?

lucid prawn
# zenith terrace code?

here is my new code

   if(message.content.startsWith(prefix + "level")) {
        message.channel.bulkDelete(1)
        if(!xp[message.author.id]){
            xp[message.author.id] = {
                xp: 0,
                level: 1
            };
        }
    let curxp = xp[message.author.id]
    let curlvl = xp[message.author.id]
    let nxtlvl = curlvl * 300;
    let difference = nxtlvl - curxp;

    const lvlEmbed = new Discord.MessageEmbed()
        .setAuthor(message.author.username)
        .setColor("#FFC0CB")
        .addField("XP", curxp, true)
        .addField("Level", curlvl, true)
        .setFooter(`${difference} XP  until next rank!`, message.author.displayAvatarURL);
    message.channel.send(lvlEmbed)
    }
earnest phoenix
#

Try it :)!

zenith terrace
lucid prawn
#

it send this

!Corizya
XP
undefined
Level
undefined
NaN XP  until next rank!
zenith terrace
#

so it will be message.author.send("content", help)

earnest phoenix
#
const args = <String>.split('.');

args.reduce((T, A) => (T = <Object>[A], T), null);``` @MILLION#1321
#

Thanks discord

#

Alrighty, so it’s almost like replacing it right? @zenith terrace

zenith terrace
#

@crimson vapor

earnest phoenix
#

750% brain cells lost so far

crimson vapor
#

thats pog if it works

lament rock
#

All brain cells lost

queen needle
earnest phoenix
#

Yep, true lol

#

message.author.send("content", help); @zenith terrace won’t I need the ; at the end?

zenith terrace
#

if u want

earnest phoenix
#

I’ll just add it

lament rock
#

The ; is optional and is more just a development style choice

earnest phoenix
#

BRUH, AUTO CORRECT

#

It's not optional when it comes to doing

const bruh = 'moment'
(SomeExpression)```
#

@zenith terrace ayyyy congrats it worked and thanks again mmLol

zenith terrace
#

mhmm

earnest phoenix
#

Because if you don't end it with a semicolon it will decide to call the string as a function

zenith terrace
#

@earnest phoenix this boy thought it wouldnt work but I proved the qt wrong

lament rock
#

Well. Obviously, strings are not callable

earnest phoenix
#

And also you're the qt not me

zenith terrace
#

you are the qt yes

earnest phoenix
#

They're prone to corruption

queen needle
#

They usually corrupt more often when they get written to a lot and an XP system would write to it a lot (anyone correct me if I'm wrong)

earnest phoenix
#

It would corrupt if it tries to read and write to a huge chunk of JSON data

queen needle
#

yra

earnest phoenix
#

It would most likely corrupt if it tries to read and write and the process exits before it's complete

#

That's why atomic read and write exists

queen needle
#

if you do use json make sure you use jason.db

pale vessel
#

LOL

#

@crimson vapor

#

look at what you've done

earnest phoenix
#

We already discussed about that package like an hour ago

pale vessel
earnest phoenix
#

KEKW This is a certified bruh moment

crimson vapor
#

smh

#

who is using a json db?

#

oh I see

lament rock
#

time to implement json as the back end of my database implementation instead of being smart and implementing chunked files

#

I already lost all my sanity from trying to make a NodeJS backed db anyways

crimson vapor
#

lol

earnest phoenix
#

Man, JSON is only good for read purposes, not read and write, time to find a way to stop Node.js from allowing to write to JSON files KEKW

lament rock
#

mutate the state of the fs write methods

earnest phoenix
#

Yes

crimson vapor
#

I just use .txt

#

but save JSON format

queen needle
#

Tomorrow I'm going to see in tech news "Node.js but you can't write to Json by voltrex master"

lament rock
#

Node is already turing complete

#

just detect if string is a JSON object then throw a ShitCodeException

earnest phoenix
#

Why is it doing this..

#

Just make a long ass error name

YouNoobWritingToJSONfilesPleaseStopAndUseARealDatabaseInstead()```
#

The bot inv btw

lament rock
#

text can only be done in embeds unless sent by a webhook

earnest phoenix
#

Jason, reminds me of the creator of discord

lament rock
#

Yes?

earnest phoenix
#

Aw man..

earnest phoenix
crimson vapor
earnest phoenix
crimson vapor
#

what link?

earnest phoenix
#

Yes, put it in the embed

crimson vapor
#

oh

lament rock
#

Make a web server and have a handler to redirect either sub domains or paths to the bot invite URL

#

or just put it in the embed and don't worry about it

crimson vapor
#

we are learning webservers today?

earnest phoenix
#

Ain't no learning from this channel

#

900% brain cells lost so far

lament rock
#

it's over 9000!

earnest phoenix
crimson vapor
#

I learned a bit

#

mostly I just pick up on what people say not to do

#

sometimes

lament rock
#

Time to finish reading this c++ book. Idk when I'm supposed to get to the part where programmer socks are completely necessary

crimson vapor
#

are they not always needed?

lament rock
#

They are absolutely necessary. I just need affirmation from "an expert"

earnest phoenix
#

Bro, don't forgot the "Good programming chair" that gives you the ability to write good code for an eternity

lament rock
#

it's all in the socks

crimson vapor
#

I think so

#

which is why im so bad

#

I don't wear socks

lament rock
#

That's kinda gay bro

crimson vapor
#

its all coming together

earnest phoenix
#

Bro

#

gaming

crimson vapor
#

indeed

dusky sundial
#

My programming teacher at uni literally told us that we shouldn't use google, it's better to look in books and at their fucking slides

crimson vapor
#

idk

lament rock
crimson vapor
#

@earnest phoenix how do you use your function help

earnest phoenix
#

If you don't look at StackOverflow you're not a real programmer

lament rock
#

Yes. Stack Overflow is virus. Please read book

crimson vapor
#

oh wait

#

fuck ik what I did

#

fucking fuck

lament rock
#

God. Why did that remind me of that video that crashes chromium

#

"Hello. Your computer has virus"
crash

dusky sundial
#

Might aswell write code by hand in a notebook then

earnest phoenix
#

The indian accent guy? @lament rock

crimson vapor
#

I use fucking text instead of fucking rurl

lament rock
#

Baljeet

crimson vapor
#

phineas and ferb?

lament rock
#

Yeah. Wanna see the video?

crimson vapor
#

sure y not

earnest phoenix
#

Saw it like 500 times lmao

crimson vapor
#

I need a break from this fucking pain

#

FUCK FUAIDHWDIUAOGWDIPYAGDWYU

#

IT WORKED

#

FUCK YES

earnest phoenix
#

Loggers

crimson vapor
#

ive been working some code that telk made

#

trying to make it work with pyrocdn

lament rock
#

Telk kinda cute ngl

crimson vapor
#

lol

earnest phoenix
#

🗿 Bro

crimson vapor
#

this took way to fucking long

#

how do I see errors on electron

earnest phoenix
#

Million

crimson vapor
#

that would have saved like 30 minutes

earnest phoenix
#

Did what i showed work?

crimson vapor
#

indeed it did

earnest phoenix
#

Loggers

lament rock
#

Doesn't control shift i bring up the chromium dev tools

crimson vapor
#
          const [...args] = rurl.split('.');
          const url = args.reduce((T, A) => (T = json[A], T), null);```
#

command option i on mac

#

idk on windows rn

earnest phoenix
#

Also you can just name it args

crimson vapor
#

makes sense

#

since you are making an array of the spread results

lament rock
#

If args was an IterableIterator, that would make sense

#

Then again, could always just do Array.from

crimson vapor
#

honestly fuck thinking rn

#

I want to eat again

lament rock
#

Pretty sure spread duplicates the memory

crimson vapor
#

memory go brrrr

lament rock
#

memory optimizations are all my brain is swelling with

earnest phoenix
#

Memory leaks are fun

queen needle
#

I got one earlier

crimson vapor
#

voltrex what happens if the object doesn't have the fucking shit

#

like

#

{ '1': { '2': data }}

#

but

#

I do 1.2.3

earnest phoenix
#

I can make it return

trail edge
#

._.

crimson vapor
#

checking for selfbot smh

earnest phoenix
#
const args = rurl.split('.');
const url = args.reduce((T, A) => (T = (json[A] ?? {}), T), null);```
crimson vapor
#

ty

lament rock
#

@crimson vapor has been banned. Reason: bad language

Error: I need the ADMINISTRATOR permission to work

solemn latch
#

most bots miss the second line

#

@crimson vapor has been banned. Reason: bad language

crimson vapor
#

FUCK

lament rock
#

I know. Sometimes, I have seen messages sent right after detailing the error but eh

earnest phoenix
#

You need Node.js v14

crimson vapor
#

14.15.2

#

can I just use ||

#

since its a json response from an api it shouldn't matter right

lament rock
#

You could use logical or

earnest phoenix
#

|| would also skip it if it's 0 or an empty string

crimson vapor
#

hmm

lament rock
#

You'd have to check for if it === undefined

crimson vapor
#
(json[A] === undefined ? {} : json[A])```
#

actually

earnest phoenix
#
const args = rurl.split('.');
const url = args.reduce((T, A) => (T = ([null, undefined].includes(typeof json[A]) ? {} : json[A]), T), null);```
crimson vapor
#

no empty strings responses should happen

#

since its a file path response

earnest phoenix
#

We're not checking for the string that's trying to access the property

lament rock
#

@earnest phoenix typeof null === "object"

earnest phoenix
#

We're checking for the value

earnest phoenix
#

JS please explain

lament rock
earnest phoenix
#

Why is null an object

#
const args = rurl.split('.');
const url = args.reduce((T, A) => (T = ([null, undefined].some(K => K === json[A]) ? {} : json[A]), T), null);```
queen needle
#

why is NaN a type number

crimson vapor
#

LOL

#

its type number

#

not a number

lament rock
#

why is null >= 0 when null is not greater than, less than, or non strict comparatively equal to 0

queen needle
#

why is js

crimson vapor
#

js do be js

earnest phoenix
#

Brain damage

#

🗿

gilded olive
#

LOL

modern sable
#

-atmods

gilded plankBOT
#

@earnest phoenix

Please do not mention (ping) more than one or two moderators for help, unless there is an emergency.

Here are some examples of emergencies:

  • Raids / Multiple members mass spamming.
  • Severe disruption of Discord's ToS (NSFW content, etc)
  • Anything that requires more than 2 moderators to handle.
crimson vapor
#

LOL

queen needle
#

lmao

earnest phoenix
#

BRUH

crimson vapor
#

he forgot the CMs

earnest phoenix
#

I just left the fucking channel for 1 second

modern sable
#

We generally dont give bot recommendations

crimson vapor
#

WHAT THE FUCK

#

json.url doesn't start with json.

#

reeeeeeee

#

coding sucks

lament rock
#

. is a funny character in regular expressions

#

don't use unless you escape it

crimson vapor
#

im using .startsWith('json.')

#

oh fuck

#

my bad

lament rock
#

check the string index [0]

crimson vapor
#

spelled starsWith('json.')

#

not startsWith

lament rock
#

LOL

earnest phoenix
#

I fucking hate spelling errors

zenith terrace
earnest phoenix
#

🗿

crimson vapor
#

fast edit

#

ngl

#

impressive

lament rock
#

self bot

crimson vapor
#

YES

#

it worked

#
      fetch(conf['custom_settings']['url'], {
        method: 'POST',
        headers: headers,
        body: formData
      }).then(async (res) => {
        const text = await res.text();
        const rurl = conf['custom_settings']['rurl'].toString();
        settingsWin.webContents.send('log', rurl);
        settingsWin.webContents.send('log', rurl.startsWith('json.'));
        if (rurl === 'response') {
          clipboard.writeText(text);
          notif_upload.show();
        } else if (rurl.startsWith('json.')) {
          rurl.replace('json.', '');
          let json;
          try {
            json = JSON.parse(text);
          } catch (err) {
            customError(err.toString());
          }
          const args = rurl.split('.');
          const url = args.reduce((T, A) => (T = (json[A] || {}), T), null);
          clipboard.writeText(url);
        } else {
          customError('Response URL not acceptable');
        }
      }).catch(e => {
        customError(e.toString());
      });```
earnest phoenix
#

Loggers

#

What

lament rock
#

Good job

earnest phoenix
#

Why still use ||

lament rock
crimson vapor
#

?? didn't work and I cba to use anything else

#

realistically no need

#

no response is gonna be an empty string or 0

#

since anyone who uses this code will have to compile it

#

so they will likely understand it

#

and realize not to do json.status and return 0 or smth

lament rock
#

always assume the end user is actually stupid

lament rock
#

In a perfect world, we wouldn't have to error check, but we don't live in a perfect world

crimson vapor
#

im the end user tho

#

LOL

earnest phoenix
#

We live in a society

#

🗿

quartz kindle
#

we live

crimson vapor
#

hi tim

zenith terrace
#

loggers

crimson vapor
#

you missed my realization that I can't spell

lament rock
#

Logical errors happen all the time

quartz kindle
#

hardly a realization

crimson vapor
#

lol

quartz kindle
#

:^)

earnest phoenix
#

Aight, gn chat

quartz kindle
#

gn

lament rock
queen needle
crimson vapor
#

alright later ima clean up telk's code

#

but rn ima go play games

quartz kindle
#

anyone wanna do tedious work for me?

zenith terrace
#

hi tim you sexy

#

uwu

quartz kindle
#

hi thank you owo

lament rock
#

Yo Tim. How much would you say you know about databases

quartz kindle
#

thats kind of a wide question lul

lament rock
#

Okay. I guess I could be a lot more specific but I don't wanna retype the long message I already typed here: #development message

opal plank
#

i know they store data

earnest phoenix
#

hey guys

zenith terrace
#

Tim.IQ = 0

earnest phoenix
#

can I ask a quick question?

#

Im trying to make a command that stores something after the command

#

like if /test test, it stores test

opal plank
#

you could just have redis NOT lose cache after your bot restarts

earnest phoenix
#

I try to store the thing in a variable

opal plank
#

from the quickl glimpse i saw, i didnt read all of it, but that seems like the issue

lament rock
#

It's not

#

Redis stores data beyond restarts of my bot. Storing guilds and voice states in redis is a bad thing

opal plank
#

hmmm

#

let me read the whole thing

earnest phoenix
#

wait redis can store the data?

#

oh wait that might actually help me

lament rock
earnest phoenix
#

nvm

#

Im just trying to make variables distinct for each server

#

but stay a general variable

#

not sure how

opal plank
#

i still dont get the issue though, why you bothering updating redis when you mentioned redis has the non mutable data? why does it need to be updated on restart?

#

also how did you set your stuff, cuz redis has an index, it should not be slow at all to find an index

#

unless you're filtering

#

which you shouldnt need in most scenarios

#

@lament rock

quartz kindle
#

yeah im confused as to why GUILD_CREATES would be starving redis if you're not storing them in it

lament rock
#

I was previously

#

there are also separate indexes that I do store such as channels and roles

#

I keep all of the data separate

opal plank
#

why not keep it simple and keep everything under a single index for guilds?

#

but that doesnt really tell us why redis would have any change whatsoever when your READY state is fired

lament rock
#

overhead with fetching data

opal plank
#

WHAT data?

lament rock
#

Guild data just to access role data or channel data

opal plank
#

those shouldnt be updated nearly as often to be causing a clog at all on redis

quartz kindle
#

how are you storing it?

#

redis has hashmaps

opal plank
#

^^

lament rock
#

define "how"

quartz kindle
#

as a json string using get/set?

lament rock
#

storing all of the Objects as stringified version of the Object and storing using SET

#

I guess the real overhead with that is that it routes through a method which gets the old resource to Object.assign new data to

quartz kindle
#

well that makes it very inefficient to attempt to get any data from inside the object

opal plank
#

on updates, be it roles, members, channels and all that, they'd need to be re-written no?

quartz kindle
#

why not use hashes?

opal plank
#

though you did mention you had them separate

lament rock
#

I don't know how to effectively use Redis, if I'll be honest

quartz kindle
#

hashes

#

lol

opal plank
#

correct

lament rock
#

Is there a resource I can look at to learn about this

opal plank
#

ngl i should be using redis a lot more than i am

#

its such a pain to install on windows though

lament rock
#

so then how does this apply to what I need

quartz kindle
#

instead of storing stringified ojects

#

store them as hashes

#

with keys and values

#

for example

opal plank
#

iirc hashes work just like objects/map

quartz kindle
#

HSET guildidhere name abc membercount 999 channelcount 777

opal plank
#
let newMap = new Map().set('hash', {field1: 'value1' , field2: 'value2'})

i remember someone explaining it somewhat along these lines

crimson vapor
#

hello Erwin

opal plank
#

map being redis, hash being your index, field1/2 being the key/pair inside the hash

lament rock
#

Let me find the current redis cache wrapper I use

opal plank
#

hello million

lament rock
#

I think it does offer HSET and HGET specifically, but I was using default options

quartz kindle
#

dont use a cache wrapper, use a redis driver directly

opal plank
#

scaling is a bitch, i had to scale my twitch app to support 500k streams, it was a bitch and a half

quartz kindle
#

if you want to scale, you need to directly interact with databases, you wont get far with wrappers and abstractions

opal plank
#

and that

lament rock
opal plank
#

discord cache?

#

i'd highly avoid those pre-made things btw

#

and working like tim said, directly with redis

quartz kindle
#

the thing with redis

#

is that its kind of a low level database

#

it offers you the possibility of designing your own data structures

#

but it doesnt give you built-in stuff like other dbs do

opal plank
#

i'd personally run with pg, its been an amazing companion to me even at high end web-scale projects

lament rock
#

I do dislike that it doesn't offer native filtering over the data although that's why I have the cache worker.

I really like Redis. I'll try to use the redis wrapper directly, unless you suggest something more suited for Discord related Object storage

opal plank
#

there isnt anything "discord" suited

lament rock
#

I meant something more suited for my use case

opal plank
#

any db should do

#

it seems you using redis as a db, not a mem db

lament rock
#

I tried using MariaDB and it was painfully slow, so no

opal plank
#

you just want persistent stuff from the looks of it, there isnt much point in using redis for just that

lament rock
#

I am using it as a memory database. Persistence is not my end goal

opal plank
#

then why use a memory database?

lament rock
#

?

opal plank
#

you're using redis as your persistent db from what you explained

lament rock
#

I said I don't care if there is persistence

opal plank
#

something that stays on while your bot restarts that the bot can fetch immutable info from

lament rock
#

I'm gonna flush the instance when I move to using hashes

opal plank
#

thats a database

#

im telling you, that use-case isnt necessarily the best case suited for redis

quartz kindle
#

the problem is likely not the tool but the design

opal plank
#

you should be using redis as a cache, and a high speed one at that, not for something persistent, which is what you've told us

quartz kindle
#

the way you are designing your data structures, storage and access patterns is inefficient, thats the only reason why its slow. it doesnt matter which databases you use, they can only be as fast as your storage design

lament rock
#

it is acting as a cache. It's just so happened to persist data across bot restarts. That doesn't mean I'm using it as if it was a persistent database. I patch data, delete old data which isn't sent by Discord anymore and do other stuff

#

I have other workers accessing the data

#

I can't just flush it when one of the clients disconnects

#

Alright. I'll look more heavily into my design

quartz kindle
#

a well designed storage will be fast enough even if it runs on json files

lament rock
#

Like I mentioned, I tried using Maria and creating relations, but the queries were very slow

#

And this was with selective data storage

#

not storing as just a string

quartz kindle
#

how slow?

lament rock
#

Minutes to filter to find a guild

quartz kindle
#

a query like that should take a second or two

#

what kind of filtering does it do?

opal plank
#

posgres takes roughly 30ms to run a query on my end

#

local db

quartz kindle
#

my sqlite3 takes around 500ms to do a full scan over 20k rows

lament rock
#

example query: SELECT * FROM Guilds WHERE name LIKE Poggers

opal plank
#

filtered, 150ms

#

indexed: 48ms

quartz kindle
#

is name indexed?

#

how many guilds are stored?

lament rock
#

3k guilds stored. I don't believe name is indexed. I only had the IDs as the PRIMARY

opal plank
#

then you should be fetching by ID

#

rather than name

#

any specific reason you are querying by name?

lament rock
#

My use cases were filtering over the data sets because of certain features I offered

quartz kindle
#

even if name is not indexed, it should never take 1 minute to run a full scan with only 3k rows

opal plank
#

not even 20 secs

#

doubt it'd even reach 5

quartz kindle
#

but indexing should be done regardless

opal plank
#

let me check a non indexed table

#

since i have logs, one sec

#

Non indexed

lament rock
#

It took significantly longer when I was querying over 100k users by username or discrim

opal plank
#

i think i got over 87k entries on this db

#

like we both said, it should NEVER take that long

lament rock
#

So, the solution was just to index the data

#

er. Those specific columns

quartz kindle
lament rock
#

Hm

#

Alright

quartz kindle
#

so yeah, i dont know exactly what you did, but something was likely terribly wrong

#

it should never be that slow

lament rock
#

Probably. I didn't feel like my query statements were unoptimized

#

Perhaps just the database layout

quartz kindle
#

i ran the above query a couple more times and it went down to 18ms lol

#

but its indexed

lament rock
#

That's some fast access time. I guess it's pointless for me to try to use a redis instance if I could also integrate my cache into my Maria instance?

quartz kindle
#

most likely

lament rock
#

Alright. Thank you for the help. I greatly appreciate this info

quartz kindle
#

if you're still getting slow queries, send code and stuff later

lament rock
#

Will do

snow tendon
#

so im adding a music feature to my bot

#

and im using ytdl

#

idk how to resolve this error tho

#

can anyone help?

opal plank
#

did you even read the error?

snow tendon
#

yeah I did

#

I have ffmpeg

opal plank
#

then?

snow tendon
opal plank
#

clearly it isnt installled

snow tendon
#

uhh

opal plank
#

use chocolatey

#

you surely isnt installing ffmpeg correctly

snow tendon
#

will pip do it?

#

im using python

opal plank
#

its not related to python

#

that'll install it on windows

#

you run it via shell, not with py

snow tendon
#

yeah but could I use pip

#

to install it

#

?

dusky sundial
#

Is it a good idea to have a separate SQL table for each guild your bot is in?

mellow kelp
#

probably not

dusky sundial
#

I'm very new to databases and I want to store information about each user, per server

#

and I'm not really sure how I would do that, other than making a table for each server containing the user data

opal plank
#

thats what relation tables are for, also you dont

#

just map user/guild/moredata

dusky sundial
#

So I store moredata in string json format?

opal plank
#

then query WHERE userid = '' AND guild = ''

#

why would you json format it?

#

its a table

#

use collumns

dusky sundial
#

I thought you meant moredata as a single collumn

opal plank
#

no, more data as in, whatever else other columns you want

dusky sundial
#

ah ye, sorry

#

it's 4am

#

I guess that makes more sense yeah

#

thank u

opal plank
#

np

earnest phoenix
#

@rustic meadow pogey

odd stratus
#

@snow tendon Are you still having issues with installing it?

slim void
#

Are casino bots hard?

solemn latch
#

yes and no.

earnest phoenix
#

if you know how to gamble, no
if you don't know how to gamble, yes

solemn latch
#

with mine, i played atleast a few hours of every game i added before even starting making that game.

#

totally for research 😉

sudden geyser
#

For every loss, cross off some method/function/variable from the library/standard library you’re using.

#

.users doesn’t return a collection

#

Check the docs because it’s under the cache

snow tendon
sudden geyser
#

See discord.js’ docs for client.users

misty sigil
terse berry
#

It was working perfectly yesterday

#

I'm getting total bot users from the cache

silver lintel
#

is there like a way to reduce emoji lengths? like insteqad of typing :small_orange_diamnd: can you do like a shorter aliase?

earnest phoenix
#

in your code?

neon heart
#

hi i want to ask, i'am using collection for save song data and in the repeat mode, how to auto set song if song has finished?

neon heart
lament rock
# neon heart i want to auto set this song if the song has ended and the music in repeat mode

before you remove the song from the queue, check for if the queue is in repeat mode, then just add it back to the end of the queue or set it next in the queue depending on if you want to implement repeat (one) or repeat (queue).
You should also keep track of if there was an error playing the song and if there was, destroy the song and do not loop or you will get stuck in an error loop and your bot will become unresponsive.

wanton knoll
lament rock
#

adding 26 event listeners to process 👀

lament rock
#

Don't do that

wanton knoll
neon heart
lament rock
lament rock
#

Extra disclaimer in case you don't see the comment in the code block. DO NOT DO THAT

wanton knoll
lament rock
neon heart
#
      const queueConstruct = {
        textChannel: message.channel.id,
        voiceChannel: channel.id,
        guildId: message.guild.id,
        songs: new Collection(),
        connection: null,
        loop: false,
        volume: 100,
        playing: true,
        timeout: null
      };
lament rock
#

That's not the logic I'm looking for. How do you handle where the song plays and then on end, go to the next track

neon heart
#

ah wait

#
    let streamtype = song.url.includes("youtube.com") ? "opus" : "unknown"
    let dispatcher;
    try {
        if (song.url.includes('youtube.com')) {
            dispatcher = queue.connection
                .play(
                    await erityt(song.url, { filter: 'audioonly', quality: 'highestaudio', highWaterMark: 1 << 25, bitrate: 96000 }), { type: streamtype }
                )
                .on("finish", () => {

                    if (queue.loop) {
                        queue.songs.set(queue.songs.first().identifier, queue.songs.first())
                        queue.songs.delete(queue.songs.first().identifier)
                        module.exports.play(queue.songs.first(), message);
                    } else {
                        queue.songs.delete(queue.songs.first().identifier)
                        module.exports.play(queue.songs.first(), message);
                    }
                })
                .on("error", (error) => {
                    console.error(error);
                    queue.songs.delete(queue.songs.first().identifier)
                    // queue.songs.shift();
                    module.exports.play(queue.songs.first(), message);
                })

            dispatcher.setVolumeLogarithmic(queue.volume / 100);
        }
drowsy grail
lament rock
#

If it is, it's adding more event listeners to the dispatcher which may not be intentional

neon heart
silver lintel
fair axle
#

I have a question, for example I have an forEach loop. I want to wait until forEach loop end (I mean async - await). I know I need to use Promise but I don't know how to resolve. There is example code below.

const a = [1,2,3];
const list = [];
a.forEach(e => {
  list.push(a);
})

console.log(`${list.join(" ")}`)
#

I can use promise but I don't know where to resolve?

await new Promise(resolve => {
  a.forEach(e => {
     list.push(a);
  })
})
fair axle
lament rock
#

use a for loop instead of forEach. for respects async

lusty quest
#

try a different loop, iirc you can have for as example async

fair axle
#

What changes if I use for loop instead of forEach?

lusty quest
#

it respects async

lament rock
#

Only key differences is that for loop respects EOL (end of line) execution unless a continue statement is used. continue is basically return but for for loops. return returns out of the scope above any for loops you may be in.

#

forEach is on it's own internal loop which just iterates over all of the entries and calls the provided callback fn which means it'll execute much faster on all entries since it doesn't wait like for does.

#

Now that I think about it, I don't think you can even Promisify forEach

earnest phoenix
#

forEach is much slower than a native for loop regardless

wanton knoll
lament rock
#

Why would you want to do that

fair axle
#

Thanks so much

#

I did this too. I took a error mesage. You reached maximum event listeners.

umbral zealot
#

You should never have to raise the number of listeners

#

That's the wrong solution to the wrong problem.

fair axle
#

What is solution?

umbral zealot
#

Depends on the problem

#

why are you trying to raise the number of listeners?

lament rock
umbral zealot
#

This usually means that you're creating new event listeners inside another one - or in a loop

#

OR you just literally have a lot of event listeners because you don't know how to use conditions.

wanton knoll
#

Me and my friend made this bot he added this and I don't know what does even mean and when I checked the server I saw this message and when I was checking I founded this

lusty quest
#

common issue is that a message event listener is created for each command

wanton knoll
#

Should I remove this?

umbral zealot
#

Take a look at the whole code and try to spot any file that has an event listener inside of it. For example, an event listener added inside a command, or inside another event

#

Yes, it should be removed.

wanton knoll
#

Ok than I will take a look than I will remove it

#

Thanks For the help

umbral zealot
fair axle
#

how to iterate on collections with for loop. For example, I have 3 channel reference. How can I iterate with for loop?

summer torrent
#

what lang

fair axle
#

node.js

summer torrent
#

something like js for (const item of collection) { // do something with item }

fair axle
#

Thanks

neon heart
#
                .on("finish", () => {
                    if (queue.loop) {
                        queue.songs.delete(song.identifier)
                        queue.songs.set(song.identifier, song)
                        play(queue.songs.first(), message);
                    } else {
                        queue.songs.delete(song.identifier)
                        play(queue.songs.first(), message);
                    }
```i am try with this and work, thank you @lament rock
fair axle
#

How can I sort json object by value. Example below

const data = [
{1: 15},
{2: 5},
{3: 19},
]

const sortedData = [
{2: 5},
{1: 15},
{3: 19}
]
lament rock
#

data.sort((a, b) => a[0] - b[0])

slender thistle
#

Why index in a json

fair axle
#

it was just example

slender thistle
#

Eh, if you understand it, I'm not gonna say anything

fair axle
#

it didn't worked

earnest phoenix
#

because you're indexing the object as it if were an array

#

except it isn't

#

you need to index by property name

#

that structure looks very wrong though

#

what are you actually trying to do

fair axle
#

I fixed this by typing

invites.sort((a, b) => Object.values(a)[0] - Object.values(b)[0]);
earnest phoenix
#

i don't believe in god but may the lord be with you

#

you're adding unnecessary complexity to your iteration

silver lintel
#

so i have a pacman command with a grid, but the grid is slightly too big and is over 2000 chars, it is only missing 1 line, but is it even possible to like reduce the emoji length or somthing? if there isnt i can just reduce the grid

fair axle
#

Object.values(a)?

earnest phoenix
#

In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform. Thus,...

earnest phoenix
silver lintel
earnest phoenix
#

oh

#

also

fair axle
earnest phoenix
#

are you sending the emojis in colon notation or their unicode variant

earnest phoenix
silver lintel
fair axle
#

I am making top invite list.

earnest phoenix
silver lintel
#

ok

earnest phoenix
fair axle
#

Yes, I am storing their user id with invite use count

#

Sorting by use count

earnest phoenix
#

you really shouldn't use json in the first place

#

it isn't built for this

fair axle
#

what do you suggest?

#

How can I store their id with count data?

earnest phoenix
#

take a look at this
<#development message>
there's some suggestions for a proper database in that message

fair axle
#

There is no json file

earnest phoenix
#

...but you're storing in json

fair axle
#

as a variable*

earnest phoenix
#

🤔

#

that is only in memory, that data will be gone once your bot process shuts down

fair axle
#

I don't care

#
await message.guild.fetchInvites();
#

I don't store old data

earnest phoenix
#

🤔

#

why would you transform the objects then

#

why not just use the invite objects djs gives you

fair axle
#

Because djs gives me collections and I hate it

lusty quest
# silver lintel ok

maybe cheat the system and render it as a image, sure its slower but could help

fair axle
#

I don't know how to sort in collections

lusty quest
#

collections are just maps

earnest phoenix
#

^

fair axle
#

yes it is but it contains too much data

#

invite*

lusty quest
#

? how

#

you just navigate to the stuff you need

fair axle
summer torrent
#

isnt collection data structure of discord.js

lusty quest
#

you dont have to use it all, just use the stuff you need.

fair axle
#

it might be sensible

#

I will try to sort collections

silver lintel
earnest phoenix
#

it might be a rendering bug with the discord client then

#

i remember this being an issue

#

the client just refuses to render emojis when there's too many of them

silver lintel
#

oofe, oh well thanks for ur help

terse berry
lusty quest
#

how did you get the users?

terse berry
#

From the cache

#

Wait a sec

terse berry
lusty quest
#

why to string?

earnest phoenix
#

won't really affect anything

terse berry
#

Idk I usually do that

earnest phoenix
#

are you doing this in/after the ready event

terse berry
#

In

#

ready event

earnest phoenix
#

hm

#

it should work

terse berry
#

It was working until yesterday

lusty quest
#

restart the bot. maybe it helps

earnest phoenix
#

try using a native for loop instead of reduce

terse berry
#

I already did

prime glacier
#
client.on("guildCreate", guild => {

  if(guild.memberCount < 50) {
    guild.owner.send("You Must Have 50 Member's To Make Me Stay In Your Server")
  }
});```

is this function is correct?
lusty quest
#

also did you use normal d.js or something like d.js light?

terse berry
terse berry
lusty quest
#

do the loop

wanton knoll
#
  console.log(`Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`);```

Is this correct?
summer torrent
earnest phoenix
terse berry
#

oh

#

Thx Im trying

wanton knoll
earnest phoenix
#

enable intents

#

both in your code and on the developer page

#

otherwise you won't receive member related events

#

and your cache will be empty

wanton knoll
#

Ohh

earnest phoenix
#

🤔

terse berry
#
let totalMemberCount = 0;
    for(const guild of client.guilds.cache){
        totalMemberCount += guild[1].memberCount;
    }

    //Bot status
    setInterval(() => {
        client.user.setActivity(`${totalMemberCount} Users 
        | ${client.guilds.cache.size.toLocaleString()} Servers | -help`, {type:"WATCHING"});
    }, 10000)
earnest phoenix
#

try console.logging totalMemberCount and the guild's memberCount

#

and seeing what it outputs

terse berry
#

hm

#

UGH

#

Literally

terse berry
#

BRUV

golden condor
#

Why do you use guild[1]

earnest phoenix
#

what is NaN though

golden condor
#

It's just guild

earnest phoenix
#

it isn't

terse berry
#

lol

earnest phoenix
#

.cache property is a collection

#

which is an extension of a map

golden condor
#

I use code to do that, and I use guild.memberCount

earnest phoenix
#

for...of on a map returns an array, first element is the key, second element is the value

golden condor
#

A collection doesn't

earnest phoenix
#

bitch a collection is a map

golden condor
#

A collection works differently

earnest phoenix
#

👁️ 👄 👁️

golden condor
#

They changed that

terse berry
#

why no work Thonk spongery

rose warren
#

guild.memberCount should work...

terse berry
#

breh

digital wagon
#

a

golden condor
#

Can you try remove the [1] and see if that changes anything, just try it at least

terse berry
earnest phoenix
#

it won't

#

actually

#

i'm just going to check the source

terse berry
#

error

golden condor
#

Show code

terse berry
#

oh wait

#

just a sec

#

NaN

#

lol

golden condor
#

I think I know the problem

#

This happened to me

earnest phoenix
#

djs' collection does not change iterator behaviour

terse berry
#
    let totalMemberCount = 0;
    for(const guild of client.guilds.cache){
        totalMemberCount += guild.memberCount;
    }

    //Bot status
    setInterval(() => {
        client.user.setActivity(`${totalMemberCount} Users 
        | ${client.guilds.cache.size.toLocaleString()} Servers | -help`, {type:"WATCHING"});
    }, 10000)```
removed the [0]
golden condor
#

One of my server's returned undefined as a memberCount

earnest phoenix
#

console.log guild and you'll see that it's an array

wanton knoll
#

Is there any difference between setPresence and setActivity

rose warren
#

Console log guild.memberCount in the loop maybe just for science

golden condor
#

setPresence sets status as well as activity and setActivity is just activity

terse berry
#

undefined

wanton knoll
terse berry
#

for every single one

rose warren
#

Ah

golden condor
#

try just log guild

#

Like cry said

terse berry
#

guild not defined

rose warren
#

Hm

golden condor
#

Inside the loop?

terse berry
#

oops lmao

golden condor
#

What does it say?

terse berry
#

oh wtf

#

it spammed the console

golden condor
#

with?

terse berry
#

wait

golden condor
#

Can you send an example

terse berry
rose warren
#

Ok good

golden condor
#

Can you show a longer thing

rose warren
#

Full object

golden condor
#

Is there any []?

terse berry
#

No, not in the loop

golden condor
#

Try this

#

log

#

Array.isArray(guild)

terse berry
#

hmm

golden condor
#

just console.log that

terse berry
#

true
true
true 100s of times lmao

rose warren
#

How true is it?
Console log: YES

terse berry
#

now what ._.

#

lol

earnest phoenix
#

index guild like i told you

signal estuary
#

I have problems on defining this on Unix
const { badwords } = require('../swearwords.json')
On windows, all is working fine

earnest phoenix
#

guild[1]

terse berry
earnest phoenix
#

do something like this

if(!guild[1].memberCount)
  console.log(guild[1]);
rose warren
#

Log guild[1]

terse berry
#

console log now we wait for console to spam

#

ah god

#

what have you made me do

#

lol

earnest phoenix
#

the snippet filters out guilds which have a defined member count

#

so you'll only see guilds that don't

#

lmk what it outputs

terse berry
#

example

#

of the 100's of times it has outputted this

#

lol

earnest phoenix
#

🤔

#

share your code

terse berry
#

same as before

#

._.

earnest phoenix
#

you need to add the if check

terse berry
earnest phoenix
#

and there's your problematic guild

#

leave that guild

rose warren
#

Yep

terse berry
#

wdym

#

leave that guild

rose warren
#

available: false

terse berry
#

hmm

earnest phoenix
#

oh actually

#

available set to false just means that there's some api issues

#

you don't have to leave it then

terse berry
#

But what did you mean by 'leaving' it

#

oh

earnest phoenix
#

anyway, you can just add an if check now

#

and it'll work

rose warren
#

You could filter through guilds using available: false before adding to totalmembercount

terse berry
earnest phoenix
#

nah

#

that'd make it slower

#

since O(n^2)

#

a simple if check to see if memberCount is defined is enough

rose warren
#

True

earnest phoenix
#
const g = guild[1];
if(g.memberCount)
  //addition here
else
  //if you want to handle unavailable guilds here or something
terse berry
#

Can't there be multiple problematic guilds

earnest phoenix
#

sure

terse berry
#

Can I do if(guild.memberCount) in the loop then

earnest phoenix
#

yes

#

that snippet is meant to be used in the for loop

terse berry
#

Oh ye

earnest phoenix
#

congrats, you made your code O(1) now

#

and it's fast

terse berry
#

xD

#

umm lol

#
    for(const guild of client.guilds.cache){
        if(guild.memberCount) {
            totalMemberCount += guild[1].memberCount;
        }
    }
    console.log(totalMemberCount)

    //Bot status
    setInterval(() => {
        client.user.setActivity(`${totalMemberCount} Users 
        | ${client.guilds.cache.size.toLocaleString()} Servers | -help`, {type:"WATCHING"});
    }, 10000)```
#

oh wait

#

bruh

lament rock
#

can't you just use Collection.reduce

rose warren
#

I wonder if I had to do that in my code now. I can't remember. Seems odd.

terse berry
earnest phoenix
#

share your code

earnest phoenix
#

guild is an array

terse berry
#

yey

earnest phoenix
#

first element is the key (the id of the guild)
second element is the value (the actual guild)

terse berry
#

worked xD

rose warren
#

Not that memberCount actually means anything anyway 😂 they dont all use your bot

terse berry
#

lmao

rose warren
#

I have 600k memberCount but 30,000 lifetime users

terse berry
terse berry
rose warren
#

I would do toLocaleString() on that personally

#

Same way you did to server count

#

In setActivity

#

But that's details

terse berry
#

Oh yeah

slender thistle
#

Quite curious how that's O(n^2)

earnest phoenix
#

you would have to iterate over it to filter the guilds out

#

and then iterate over it again to use memberCount

#

i think

slender thistle
#

Well, unless we do that in one loop?

earnest phoenix
#

yeah

slender thistle
#

Oh, actually

#

I see where you're getting at

#

Yeah. Makes sense to me now, thanks man

wanton knoll
terse berry
#

You can take it xD

silver lintel
#

so i am confusion, heres my code:

let output = "";
for (let i = 0; i < 11; i++) {
        for (let j = 0; j < 20; j++) {
          output+=":ox:"
        }
        output+= "\n"
      }
message.channel.send(output);
``` and it returns this
#

which is only a 10 * 20 grid missing one

#

but it works as its suppposed to when i remove the output += "\n"

earnest phoenix
#

like i said before

#

it's a client rendering bug

silver lintel
#

o

earnest phoenix
#

there's not really anything you can do except try to find workarounds

#

well, not until discord devs decide to fix it

#

which is probably... never

earnest phoenix
#

you're not doing it in/after the ready event

wanton knoll
#
    for(const guild of client.guilds.cache){
        if(guild.memberCount) {
            totalMemberCount += guild[1].memberCount;
        }
    }
    console.log(totalMemberCount)

    //Bot status
    setInterval(() => {
        client.user.setActivity(`${totalMemberCount} Users 
        | ${client.guilds.cache.size.toLocaleString()} Servers | -help`, {type:"WATCHING"});
    }, 10000)
};```

I just copied this I don't know how to fix
earnest phoenix
#

🙄

rose warren
#

Cry literally just told you

wanton knoll
#

But I don't know how to fix...

rose warren
#

Put it in the ready event

wanton knoll
#

Ok wait

#

PC crashed....

tribal siren
#

how to check if the voice channels size in a category is not above 10?

#

i tried like this

#

if(oldState.channel.parent.channels.filter(c => c.type === 'voice') > 10) return message.channel.send('Sorry, you cannot create the channel.')

earnest phoenix
#

size?

#

oh do you mean the user limit

prime glacier
#

can someone tell me how to do it
when bot become online it start noting time on embed liek uptime but live on embed

earnest phoenix
#

...huh?

terse berry
#

Like the uptime of the bot keeps updating every second?

#

It's possible but it would be API abuse

#

lol

prime glacier
terse berry
#

Yeah I guess

#

But I suggest against it

#

Because many people will use the embed and the bot will have to update every embed

#

Every 10s

#

If I use the command 10 times, the bot wil have to update 10 embeds every 10 seconds

#

lol

terse berry
#

Hmm

prime glacier
#

so it will be only in 1 server with 1 embed

terse berry
#

Yeah well you can but I ws just saying

#

It can be API abuse not sure

prime glacier
#

i think api abuse is for 3-5s

earnest phoenix
#

Where’s the best place to design a bot on mobile?

#

a pc

tribal siren
#

how to make a bot create a category?

#

message.guild.category.create?

pure lion
#

I have a string of text, can I send it to a person (express http) in a file without having to actually write any files locally?

cinder sandal
tight plinth
#

is there a way to check with discord.js if a server has member screening enabled or not

quick ridge
#

Which operating system do you recommend for dicord bot? I was using widows server 2012 R2 before

pure lion
#

Doesn't matter too much but use Debian 😏

tribal siren
#

i can'

#

t find

#

nothing ther

tribal siren
quick ridge