#development

1 messages Β· Page 1537 of 1

earnest phoenix
sturdy flower
#

How can i get bot developer role?

opal plank
sturdy flower
#

Ok thanks

earnest phoenix
opal plank
#

html* ?

earnest phoenix
#

you can't use relative paths for images

earnest phoenix
opal plank
earnest phoenix
opal plank
opal plank
earnest phoenix
shut spear
#

does anyone know what the rate limit for fetching is

modern sable
#

fetching what

earnest phoenix
#

what

shut spear
opal plank
#

so, fetching messages

earnest phoenix
#

ratelimits are dynamic

opal plank
#

reminder that ratelimits are dynamic

#

check request headers

shut spear
#

discord.js 😦

earnest phoenix
#

why do you need that information anyways

#

djs should handle ratelimits for you

shut spear
#

was wondering, anyway, thanks

earnest phoenix
#

almost all discord ratelimits are dynamic

#

an example of why not to hard code them is that a fuckton of bots got api banned when the ratelimit for changing channel names switched to a much more restrictive ratelimit

#

discord can change and adjust them anytime without notifying you

#

i think they even warn you not to hardcode it in the docs

hallow grove
#

104 105

earnest phoenix
#

Is it bad to use sqlite3 for a public discord bot in around 50,000 servers.
The sole purpose of the database is to allow for a simple economy, such as storing balance and bank balance?

solemn latch
earnest phoenix
#

Mb mb

#

Wait

#

...

neat hearth
earnest phoenix
#

Lmao

opal plank
#

@hallow grove what do you want?

earnest phoenix
#

yes it's bad

#

Why

#

sqlite is usable up until a 100 guilds

#

because it's a single file embedded database

#

it isn't powerful

#

Concurrency issues?

#

it isn't meant to handle so many connections

neat hearth
#

json is da best

earnest phoenix
#

no it is not

#

Lol

#

Alright ty

neat hearth
#

simple and easy to use

earnest phoenix
#

easy to corrupt

#

no data protection

neat hearth
#

thats true

earnest phoenix
#

Was just wondering since I read that a website will be fine when using SQLite if it has around 200k views per day, that’s the threshold

#

and access time compared to a normal db is super slow

hallow grove
#

@hallow grove what do you want?
@opal plank

Why

earnest phoenix
#

Nu

#

Mongo

#

πŸ™‚

#

ew

#

but sure whatever floats your boat

#

What’s bad about mongo eh? πŸ˜‚

#

nosql is nasty to me

#

I keep getting an error tho

#

Saying topology is closed please reconnect

opal plank
hallow grove
#

I may have something to tell you in private

#

πŸ‘€

neat hearth
#

what about me

hallow grove
#

I tend to be curious hmm

earnest phoenix
hallow grove
#

I sent a bunch of you a friend request I await your acceptance

#

😌

earnest phoenix
#

Dm ads most likely πŸ™‚

hallow grove
#

No

earnest phoenix
#

Yup

hallow grove
#

I'm not an idiot I don't send dm ads to developers

#

πŸ˜‘

earnest phoenix
#

Yessir

hallow grove
#

Hmm

earnest phoenix
#

Ofccccc

#

Jk

hallow grove
#

Don't be annoying now

earnest phoenix
#

Anyways imma dip, this Warzone game ain’t gonna play itself

hallow grove
#

Hmm

#

Have fun

#

πŸ‘€

earnest phoenix
#

Tyvm

fierce ether
#

dont understand?

earnest phoenix
#

you're using optional chaining in the wrong place

fierce ether
#

wdym?

earnest phoenix
#

nvm

#

i just noticed it's a messageDelete event

fierce ether
#

yeh

#

is there a better way to not logs the bots events?

solemn latch
#

not log?

#

just dont log it

fierce ether
#

wdym?

#

its logging all message delete? using ids it would not return if the author is the client

compact olive
#

hello

#

i need help

#

I would like my bot to send a message to the channel of id 272764566411149314 when it joins a server

solemn latch
#

theres no need to ping random users.

compact olive
#

@opal plank

solemn latch
#

please stop pinging people

compact olive
#

you are

#

developper

opal plank
compact olive
#

so i ping developper

solemn latch
#

please dont

compact olive
#

because i need help

#

pls

mellow kelp
#

wtf

opal plank
#

read channel topic

solemn latch
#

you are not entitled to help

compact olive
#

sorry

#

ok ok

opal plank
#

Channel for chatting about (bot) development. If you have questions, ask the questions and wait for someone who can answer to help you. Do not ask to ask. Provide all possible information so people know what's up. Just saying "I get an error" doesn't give us enough information on your problem. Do not @mention people randomly.

compact olive
#

ok sorry

odd stratus
#

if(message.author.bot) return; @fierce ether

compact olive
#

Good evening, is someone available to help me?

odd stratus
#

?

compact olive
#

I would like my bot to send a message to the channel of id 272764566411149314 when it joins a server

odd stratus
#

What lib

compact olive
#

but I can not

odd stratus
#

How can you not

fierce ether
#

@odd stratus that rlly dosent help lol

compact olive
#
 const { Discord, MessageEmbed } = require('discord.js');
 const joinEmbed = new Discord.MessageEmbed()
 joinEmbed.title('Je viens de rejoindre un serveur !')
 joinEmbed.description(`\`\`\`Nom du serveur : ${guild.name}\`\`\`\n\`\`\`ID du serveur : ${guild.id}\`\`\`\n\`\`\`PropriΓ©taire : ${guild.owners.tag}\`\`\``)
 client.channels.cache.get("800523782673661953").send(joinEmbed);
        
});```
#

he don't work

earnest phoenix
#

how does discord determine the channel ID to assign to a channel?

odd stratus
#

You asked how to not make it log bot stuff, so I gave you the answer

#

Wdym

mellow kelp
compact olive
#

well I write it in the code

mellow kelp
#

also

#

your require function is invalid

#

actually i think that's the problem

fierce ether
#

@odd stratus ik how to not log bots events, if you read the error you would not reply with if(message.author.bot) return;

compact olive
#

How should I do

#

@mellow kelp

odd stratus
#

I did read the error

#

Would if(message.author.bot) return; not do the job

mellow kelp
fierce ether
#

if the id is null explain how message.author is going to work without optimal chaining?

mellow kelp
#

don't use destructuring

compact olive
#

which module?

odd stratus
#

@compact olive It should not be like that

mellow kelp
#

just use const Discord = require('discord.js')

compact olive
#

how then ? @odd stratus

#

@mellow kelp

mellow kelp
#

i just told you

compact olive
mellow kelp
#

don't ping me

compact olive
#

oh ok

#

sorry

odd stratus
#

It's under a guildCreate event, and you put guild as a parameter

Try guild.channels.cache.get("channel ID");

mellow kelp
#

you're destructuring discord.js

compact olive
#

why

#

ok thx Muhimur

#

i try

odd stratus
fierce ether
#

its trying to fetch old messages, which would return no author

odd stratus
mellow kelp
#

aight ima head out

fierce ether
#

optimal chaining?

mellow kelp
#

there's no need for optional chaining there

#

the message itself is always defined

fierce ether
#

optional chaining

#

no message isnt always going to be defined tho? otherwise it wouldnt return null?

mellow kelp
#

what?

fierce ether
#

message is returning null

mellow kelp
#

you mean the message is null?

fierce ether
#

deleted messages cant be fetched, its trying to grab the deleted message

#

idk why

mellow kelp
#

yea well deleted messages can't be fetched because they don't exist

fierce ether
#

u can fetch ids thats it

mellow kelp
#

yeah the only thing you get is the message id

#

unless the message was in the cache, but that might not always be the case

formal vine
#

So I'm barely learning how to code discord bots, and I had one up and running for a good amount of time (hosted off of my PC) and all of a sudden its not working anymore. The bot appears to be online in discord, but commands don't work. It shouldn't be online as I have closed the CMD prompt. But its online, with no responses to commands...

#

Any fixes?

mellow kelp
#

did you close the terminal just a few moments ago?

formal vine
#

It's been closed all day

mellow kelp
#

o

#

panik

formal vine
#

I'm assuming its open in some background somewhere

#

but Its no where in task manager

mellow kelp
#

regenerate the token slick

formal vine
#

I'll try that lol, thanks!

mellow kelp
#

np

formal vine
#

can someone explain this, It was fine yesterday but this is what is messing everything up

mellow kelp
#

a package.json name needs to be lowercase

formal vine
#

lmfaoo is that all it was?!

mellow kelp
#

there are other rules but that one's the problem here

#

yea KEKW

#

you probably wanna use something like philosophy-bot

formal vine
#

would that stop the entire thing from working?

mellow kelp
#

nope

#

its just a display name

#

but it's better to have it match the regex

formal vine
#

now its just not going online lmfaoo

#

Idk if something updated or what

#

but now I run it and nothing happens

#

no error just nothign

mellow kelp
#

well

#

did you use your package.json name somewhere?

formal vine
#

not that I see

mellow kelp
#

hm

#

no idea

formal vine
#

alrighty lmfao

#

thanks again ❀️

mellow kelp
#

np

earnest phoenix
#

Would a simple economy SQLITE3 database be fine for a private discord server with 5000 members?
Will just store balance and bank balance

#

Should be fine right?

#

Ping with response, ty

odd stratus
#

If you have a big bot with shards then sqlite probably isn't a good choice

#

But for private servers ye

earnest phoenix
#

it isn't fine on that big of a scale πŸ‘οΈπŸ‘„πŸ‘οΈ

#

it's going to struggle

#

i mean

#

it depends on the amount of concurrent issues

#

but it's going to struggle

quartz kindle
#

it will be more than fine

earnest phoenix
#

are you sure? i worked on a kind of a big guild and migrated their bot from sqlite to postgres because people started experiencing bigger delays than usual

quartz kindle
#

disable synchroniztion, enable WAL mode

#

im getting average 0.3ms per query

#

sqlite can easily do 1k+ queries per second

distant cobalt
#

so i'm using djs.

let time = args[1]```
i made sure that `time` endswith d, h, m, s. Then i want to multiply the number included but before that, i gotta take away d, h, m,s from the args
#

like 1d

#

then take away the d

#

and make it just 1

quartz kindle
#

.slice(-1)

distant cobalt
#

ok

hoary crown
#

ye can someone help me

distant cobalt
hoary crown
#

I don't know why i'm getting undefined servers

distant cobalt
#

........

#

hmmmm

hoary crown
#

lol

distant cobalt
#

code?

ebon kelp
#

well because it's undefined

hoary crown
#
bot.on('ready', () => {
    console.log(`${bot.user.username} has started`);
    bot.user.setActivity(`!help -- on ${bot.guilds.size} servers`, { type: "WATCHING" }); // Set Bot Status & Presence
});
quartz kindle
#

.cache.size

ebon kelp
#

bot.guilds.cache.size

#

yes

distant cobalt
quartz kindle
#

reaction doesnt exist

distant cobalt
#

wdym?

earnest phoenix
quartz kindle
#

the message does not have that reaction

misty sigil
#

you cannot get a property of undefined

distant cobalt
#

it does

#
giveawayMsg.react('πŸŽ‰')```
odd stratus
misty sigil
#

its like doing undefined.count

quartz kindle
#

did you await it?

distant cobalt
#

uhh await the reaction?

quartz kindle
#

yes

distant cobalt
#

no

#

i just put

giveawayMsg.react('πŸŽ‰')```
earnest phoenix
#

Might include levels for that too then

distant cobalt
#
await giveawayMsg.react('πŸŽ‰')``` how about this?
quartz kindle
#

then you're trying to get the reaction before its added

#

you have to await it yes

distant cobalt
#

okay

odd stratus
#

Make sure you have async mmulu

quartz kindle
#

make sure you have brains :^)

odd stratus
ebon kelp
distant cobalt
#

i use set timeout

ebon kelp
odd stratus
#

Bro my eyes

distant cobalt
#
if (giveawayMsg.reactions.cache.get("πŸŽ‰").count <= 1) {
    return channel.send('**There is not enough people to end the giveaway! Cancelling...**')
}```
distant cobalt
quartz kindle
#

show more code

distant cobalt
#

ok

#
setTimeout(() => {
  if (giveawayMsg.reactions.cache.get("πŸŽ‰").count <= 1) {
    return channel.send('**There is not enough people to end the giveaway! Cancelling...**')
  }

  else{
    let winner = giveawayMsg.reactions.cache.get("πŸŽ‰").users.cache.filter((u) => !u.bot).random();
    channel.send(`**Congratulations ${winner.toString()}! You won ${prize}!**`)
  }
}, time)```
ebon kelp
quartz kindle
#

how is time defined

ebon kelp
#

time should be in ms

distant cobalt
quartz kindle
#

@_@

ebon kelp
#

multiple it by 1000

distant cobalt
#
time.slice(-1)

            if(time.endsWith('d')){
                time = time*86400000
            }

            else if(time.endsWith('h')){
                time = time*3600000
            }

            else if(time.endsWith('m')){
                time = time*60000
            }

            else if(time.endsWith('s')){
                time = time*1000
            }```
distant cobalt
quartz kindle
#

slice does not modify the original

#

also, you're checking if it ends with the letter, then multiplying it without removing the letter

#

so it becomes NaN

distant cobalt
opal plank
#

why you multiplying and slicing?

#

keep consistency

distant cobalt
#

wdym

opal plank
#

you got a number

#

in once case you're slicing it

#

rather that multiplying/dividing it

#

and the second you're multplying

#

why ?

distant cobalt
#

...

#

im confused

opal plank
#

you know what slice does, right?

distant cobalt
#

yeah

opal plank
#

okay, so what is slice doing there?

ebon kelp
#

"hello!".slice(-1) => "!"

distant cobalt
distant cobalt
opal plank
#

slice(0, thing.length - 1)

quartz kindle
#

slice(0, -1)

opal plank
#

does that work?

distant cobalt
#

what does 0 mean?

quartz kindle
#

ye

opal plank
#

onteresting

#

might upgrade to that

#

less chars

quartz kindle
#

one of the improvements that slice made over substring and substr are negative indexes

#

they basically wrap around

distant cobalt
#
time.slice(0, -1)``` what about this?
opal plank
quartz kindle
#

slice does not modify the original

#

do you understand what that means?

opal plank
distant cobalt
#

So, can i do js const time2 = time.slice(0, -1)

quartz kindle
#

yes

distant cobalt
#

k

ebon kelp
opal plank
#

whispers softly in ears : variables can be reassigned

quartz kindle
#

damn i want js to add pattern matching expressions asap

#

this is a perfect use case for them

opal plank
#

it does?

#

matchAll()

quartz kindle
#

not that

opal plank
#

then?

#

timmy furiously typing

distant cobalt
#

Thanks @quartz kindle @opal plank , it worked! happyblob

quartz kindle
#

new thing in php ```php
$result = match(a) {
"h" => time * 3600000,
"m" => time * 60000,
"s" => time * 1000
}

opal plank
#

no preblomo

quartz kindle
#

pattern matching expression

#

aka match expression

#

aka better switch

opal plank
#

hmmmm

#

i see what you mean but thats basically a match() + a switch and a for, no?

quartz kindle
#

it exists in rust, scala and F#

lyric mountain
#

And java

quartz kindle
#

and java

#

there is a proposal for c++

#

and a very early one for js with ugly af syntax

#

which i hope it doesnt pass

lyric mountain
#

Lul

opal plank
#

im not keeping up with upcoming changes tbh

#

nor proposals

#

though what i am trying to keep uo with is sharding

lyric mountain
#

Although it'd be be better than some chained ifs I see here

opal plank
#

but im probably gonna cry with it

quartz kindle
#

me neither, but i looked into php8 and saw that and though it was cool af

opal plank
#

im gonna have to somehow prevent racing against other shards

lyric mountain
quartz kindle
opal plank
#

thought about it, but they are REALLY slow

#

like, signigicantly

#

grammar is hard sometimes

lyric mountain
#

What about using locks then?

#

Like mutex

opal plank
#

thats an option, but i need to first check if its a necessity first

misty sigil
#

php lol

opal plank
#

this might be a rare case of race

#

all this is beacuse d.js sucks

quartz kindle
#

what are you racing against?

opal plank
#

shards presences

#

why not to literally like mine or all other libs and just reemit everything into a single client?

#

but no, lets have them have their own instances

#

cuz fuck you

lyric mountain
#

I think mutex will be the only way to do it without sacrificing speed

quartz kindle
#

what is the issue?

opal plank
#

presence triggers

#

shards may emit same presence if users are on different shards

quartz kindle
#

ah

opal plank
#

and them running simultaniously might trigger events twice in a race

#

in some VERY rare cases

#

i have checks

#

but my concern is that they run before the variable is set

#

and locks it

quartz kindle
#

never tested that, but im pretty sure it would happen also with internal sharding

#

where are you setting the variable?

opal plank
#

well, i got user object(not d.js's)

#

which has 2 keys

#

well, improtant to this matter at least

#

reminded and playing

#

reminded is a bool

#

if user is playing x game, it runs a reminder function and then sets that reminded as true

#

though, if they are run in pararell, shit might happen

#

and the reminder is ran twice before the reminded is set to true

quartz kindle
#

so the variable is set in memory in process?

opal plank
#

correct

quartz kindle
#

y not a db

opal plank
#

cuz that'd add even more latency and allow for even more stuff to pass by

#

await shouldnt stop the thread, and possibly add even more gap for another race promise to fulfill

quartz kindle
#

are you using worker threads or child processes?

opal plank
#

currently, neither

#

im still thinking of the logic behind it

#

wondering if i should use d.js sharder

#

or not

#

or make my own, for that matter

quartz kindle
#

you can use worker threads with a sharedArrayBuffer and implement it as a circular buffer

opal plank
#

did not understand half of what you said

quartz kindle
#

worker threads

opal plank
#

i know those

quartz kindle
#

sharedArrayBuffer

opal plank
#

sharedArrayBuffer and circular buffer

lyric mountain
#

Let's say I have guild A on shard 1 and guild B on shard 2, both shards on separate VPSs.

Can I retrieve guild A inside shard 2?

quartz kindle
#

sharedArrayBuffer = ArrayBuffer that is shared across worker threads

opal plank
#

okay that makes sense

quartz kindle
#

aka thread 1 changes first byte to 1, thread 2 reads first byte and sees 1

#

all writes on sharedArrayBuffer are atomic

opal plank
#

alright

#

what about circular buffer?

quartz kindle
#

sharedArrayBuffer has a constraint that its limited to a fixed size

#

you cannot resize it once you create it

opal plank
quartz kindle
#

so a circular buffer is a way to implement a sort of an infinite data stream

opal plank
#

since there are thousands of users

quartz kindle
#

you write until the end of the buffer, then you continue writing from the beginnign again

opal plank
#

and they are added removed dynamically

quartz kindle
#

and you use two pointers to control boundaries

opal plank
#

that sounds more complicated than doing my own sharder to be completely honest

#

specially when i already have my twitch framework

quartz kindle
#

well, your only other option is a db, redis, or lockfile or mutex

#

or a central process with ipc

opal plank
#

wouldnt a db or redis still imply the same issue and allow race between calls?

quartz kindle
#

no because they are atomic

opal plank
#

hmmmm deadlocks might trigger though

quartz kindle
#

well, the process thats accessing the db would need to queue it to ensure atomicity

#

so that would be a problem

opal plank
#

hmmm, this is all theorical btw, i havent ACTUALLY tested if i'll be getting double output

#

for simplicity sake i might run with queue

lyric mountain
quartz kindle
#

the database needs to have a conditional write operation

opal plank
#

and see how that performs

lyric mountain
#

Like, I'm still at 1k servers, but I'm near a total rework of the code

#

Just waiting discord's menus

quartz kindle
#

and you can send requests to the api

lyric mountain
#

Ok, I'm safe then

#

I thought guilds were locked to their shards

quartz kindle
#

only gateway commands

#

not rest

opal plank
#

but for now i got a lot of lee way

lyric mountain
#

Maximum I'd need to do is retrieve channel and send message

quartz kindle
#

you dont need the guild to get a channel

#

in fact if you have the channel id, you dont even need to retrieve the channel

opal plank
#

POST

quartz kindle
#

you can just post directly to it and handle the error

opal plank
#

channel_id/messages iirc

lyric mountain
#

Nice

quartz kindle
#

client.api.channels(id).messages().post({uvuvwevwevwe})

#

actually sending messages is PUT no?

opal plank
#

TYPE ERROR: API IS ONLY ACCESSIBLE INSIDE CLIENT CLASS

lyric mountain
#

I was afraid because I rely on message mirroring

opal plank
#

let me check docs

opal plank
#

client.api is private

#

not public

quartz kindle
#

dont use ts then

opal plank
#

TS will screech at u

#

nope, i think i was right

quartz kindle
#

ah

opal plank
quartz kindle
#

anyways

#

for your issue

opal plank
#

throw salt and lemon in eyes, gotcha

quartz kindle
#

the sharedArrayBuffer method would offer the best possible performance

#

the second best performance would be to have one of your worker processes keep the data, and have the other workers send messages to it

opal plank
#

the only reason why im bringing up that is because its presence realted

#

like

#

its a LOT

quartz kindle
#

ye

opal plank
#

that comes to show how much more data you receieve with presnces

#

234 mil presences parsed

quartz kindle
#

nice

opal plank
#

its too much

#

thats why im worried about performance in this case

quartz kindle
#

go for the worker thing then

#

have 1 worker keep the data

opal plank
#

IPC i assume?

quartz kindle
#

yes

#

ipc between worker processes is very efficient

#

and can send js objects without stringifying

opal plank
#

how does that fix the issue though?

quartz kindle
#

and functions and classes and shit

opal plank
#

cuz i already have a bool

#

i'd still need to queue it, no?

#

cuz the object containing the reminded bool is also the same thing, correct?

quartz kindle
#

yes, but you queue it in one process

opal plank
#

i just dont see how the worker solves the issue

#

they both try to change the bool, the issue is when they race it

#

and run while the bool is set

quartz kindle
#

they both change -> both send to worker -> worker changes 1, ignores the other, and returns responses -> worker who gets the successful response runs the function, the other does nothing

opal plank
#

thats not the issue though

#

actually

#

hmmm

#

lemme get my head straight

#

okay, yeah, no, i think im right on this one

#

so, the issue comes with whats happening WHILE the bool hasnt been set and its waiting

#

for example

#

actually, why am i giving example?

#

let me just dump code

#

see that for loop or await add new user?

#

those are my issues

#

while that await is running, user.playing might pass

#

twice before its been updated

#

its this code but ran twice

quartz kindle
#

if everything is inside the same process, this is not hard to solve

#

but if you have multiple process, then you literally cant solve it. you have to send everything to a single process to be executed synchronously and sequentially

opal plank
#

after presence is found i could just yoink into the queue, thats 100% a solution as it would, at the very least, massively reduce the queue, since it'd only be passed with that

#

rather than queuing every presence, i could run that check to find a specific presence(which i should be running by game id, not by name) and queue it

#

that MIGHT not prove too impactful

quartz kindle
#

this is how i would solve something like this:

opal plank
#

it boils down a lot to try and error, im not even sure a race would occur here at all, this is all assumptions

earnest phoenix
#

just brought a vps for my bot lol

#

i hosted in on my laptop

quartz kindle
#
// shard 1 and shard 2
client.on("presenceUpdate", bla => {
  let(a of bla.activities) {
    if(a.name === "yes") {
      worker.postMessage(bla)
      return;
    }
  }
});

// worker
let users = {};
process.on("message", async etc => {
  if(!users[etc.user.id]) {
    await addNewUser(...)
  }
})
opal plank
#

wouldnt runnig it async completely fuck ti up though?

quartz kindle
#

nope

opal plank
#

hmmm it seems i dont quite understand how js async works internally

#

sometimes i get the idea that it doesnt halt the code, but sometimes it does

#

the rest keeps on going, which is kinda odd

quartz kindle
#

js is 100% synchronous, everything is blocking

opal plank
#

that specific script halts while the await is runing until its fullfilled

quartz kindle
#

even if you make an async function, the code is still sync

misty sigil
#

javascript is confusing and stupid at times

opal plank
#

well yeah, thats where the confusion comes

#

that allows for other scripts to be ran meanwhile

#

which could be annoying when they are touching the same things

#

like this where it might create a rare race condition

quartz kindle
#

what it does is that if you make a function async, you "prepare" it for a possible async operation

#

and the code only stops being sync then the actual async operation begins

#

the actual async operation begins the moment there is no more sync code to execute

#

for example a callback

#

or an I/O request

opal plank
#

so if i run a 2 functions

#

one async and one sync

#

when the async one hits an await

#

the sync one (pararell) should still be going, no?

#

until the await finishes

#

then it continues on the one that was halted(awaited)

#

did i get it right?

quartz kindle
#

if the sync one starts after the async one, the sync one only starts when the async one hits an async code

#

await does not guarantee its actual async code

#

because you can still await sync stuff for some reason

#

also

opal plank
#

in the case of a promise though

quartz kindle
#

when you await an async function, like a promise

opal plank
#

actually i might be able to try this real time

quartz kindle
#

its still sync code until the code inside the promise hits something it cant continue

#
async function bla() {
  // sync
  return new Promise(r => {
    // still sync
    doSomething(() => {
      // async starts here, js cannot execute this without waiting
      r(10)
    });
    // this is still sync
    console.log(20)
  })
}

console.log(await bla()) // 20, 10
opal plank
#

async function a() {
console.log('start')
console.log(await db.get('something'));
console.log('end')
}
function b() {

for(let i, i < 1000, i++) console.log(i);
}

My probably flunked logic states that, if ran simultaneously, the async functions will run first with start, then function b will spam console log, i'll get the returned value of the await and end, and then the rest of the console log i's will end

#

am i correct to say that?

quartz kindle
#

correct

#

but if db.get() has a console.log inside it before the actual db call, that console.log is executed before function b

opal plank
#

so its kinda like blocking? where it'll run async until it hits a block, then i'll run the rest until the promise is fullfiled, which then it gets back to the async, and once it finishes, comes back to the sync code?

quartz kindle
#

yes

#

under the hood this is all done with timers

#

the same as setTimeout

opal plank
#

interesting

quartz kindle
#

when the js code hits an await, it sets a timer and continues the rest of the code

opal plank
#

default is 15 or 30 seconds to auto reject promise, no?

quartz kindle
#

the only difference is that the timer is based on signalling instead of time counting

opal plank
#

maybe thats axios i think

quartz kindle
#

promises dont auto reject

opal plank
#

i thought promises had a maximum life ebfore they were rejected

quartz kindle
#

not afaik

opal plank
#

hmmmm

#

i see

#

okay that makes a lot more sense now

quartz kindle
#

in the case of the worker receiving messages, or any event emitter

#

js cannot ever handle two messages or two events simultaneously, it will always process them sequentially

#

so before the second message has a chance to be processed, the first message already checks if the user exists in the object, and if it doesnt exist, it creates it, before proceeding with the async call

#

so while the async call is waiting, and the second message comes, the user is already in the object so it does not proceed anymore (which i actually forgot to add in the previous examples)

#
let users = {};
process.on("message", async etc => {
  if(!users[etc.user.id]) {
    users[etc.user.id] = true
    await addNewUser(...)
  }
})
opal plank
quartz kindle
#

thats the idea behind using the worker process

opal plank
#

where we have two processes handling two events simultaniously(and likely echoed)

quartz kindle
#

have all shards redirect the events to the same worker to be processed sequentially

#

like a funnel

opal plank
#

which is what i began whining about

quartz kindle
#

well

#

its more efficient than a database and more efficient than a lock file

#

just less efficient than sharedArrayBuffer

quartz kindle
#

you dont need to emit everything, only that specific thing

opal plank
#

well yeah

#

could queue it, which should do almost the same thing

#

no?

quartz kindle
#

you have to queue it in the same process

opal plank
#

hmmm, IPC it is then

quartz kindle
#

another option is using a database that can do conditional updates

#

something like db.setIfNotExists

opal plank
#

does d.js spawner allow me to bind each shard ?

#

i would assume its all used by process.send()

quartz kindle
#

if you're using djs, just use broadcastEval

#

but yes you can use process.send() if you set it to worker mode

opal plank
#

oh

#

how would broadcastEval be used here? that would just eval something on all shards, no?

quartz kindle
#

process.send() with the sharding manager in worker mode will basically send a message to the sharding manager

opal plank
#

and return them

quartz kindle
opal plank
#

using an emitter would be the proper way no? that way i dont have to run setInterval

#

cuz otherwise i risk losing positions

#

hmmmm

quartz kindle
#

djs has client.shard.send()

opal plank
#

and i assume i can easily access sharding manager and re-emit that to my main code no?

#

shard => process.send('presence', presence)

manager.on('presence') => client.emit('event', presence)

client.on('event', presence => stuff and things)

#

that SHOULD work i assume?

#

while the client part isnt teoretically necessary, i like to keep client related stuff binded there

quartz kindle
#

sure

#

but yeah its not necessary

#

do you have a client in the sharding manager?

opal plank
#

its just for consistency, shouldnt add to much strain to just re-emit it

quartz kindle
#

or a pseudo client

opal plank
#

im not sure

#

like i said, i ahvent even started with sharding

#

so im not sure how it works

quartz kindle
#

the sharding manager doesnt have a client

opal plank
#

i'd probably need a pseudo then

#

actually

#

ACTUALLY

#

can i not do the same that i did with my library then?

#

and just do EXACTLY what i did but with EVERY incoming event?

#

and emit it to the manager, and re-emit to client?

#

that would literally require no update on the code whatsoever, no? just adding the sharder

#
//shard 1
client.on('message', process.send('message', (message)));

//shard 2
client.on('message', process.send('message', (message)));


//index
manager.on('message', message => client.emit('message', message));


client.on('message', (message) => {/*actual code here*/})

#

for every event?

quartz kindle
#

i mean

opal plank
#

thats literally what i did to my twitch lib, but i needed the manager because there were custom events there that were internal and shouldnt be exposed to the end user, like Promises between the IPC pipes for connections and sync events, so only the events that the client originally had were re-emitted

quartz kindle
#

you can

#

but that will that client be?

#

surely not a discord.js client

opal plank
#

i can make a super shit client

#

should i not initiate a new client?

#

for each shard?

quartz kindle
#

you can instantiate it, but not login with it

#

in the manager i mean

opal plank
#

not sure i get it

quartz kindle
#

you're sending all events to the manager

opal plank
#

correct

quartz kindle
#

then process them with a client in the manager?

opal plank
#

but the client in the shard cant login?

quartz kindle
#

in the shard yes

#

but not the one in the manager

opal plank
#

well, yes

#

then whats the issue?

quartz kindle
#

nothing, just weird

#

i wouldnt do it like that tho, at least not without some basic filtering

opal plank
#
//shard 1
const Discord = new require('Discord').Client(require('./config.json').token);
client.login();
client.on('message', process.send('message', (message)));

//shard 2
const Discord = new require('Discord').Client(require('./config.json').token);
client.login();
client.on('message', process.send('message', (message)));


//index
const Discord = new require('Discord').Client(require('./config.json').token);
client.login();
manager.on('message', message => client.emit('message', message));
client.on('message', (message) => {/*actual code here*/})

Is this not valid?

quartz kindle
#

no because 1: the client in the manager will error with sharding required

#

2: the client in the manager will basically spawn duplicated shards

opal plank
#

hmmm manager uses its own client i assume?

quartz kindle
#

you have 2k guilds, shard 1 has 1k, shard 2 has another 1k

#

what would the manager have?

opal plank
#

or, rather, manager IS the client?

quartz kindle
#

the manager is not a client

#

the manager is just a process spawner

#

and ipc bridge

opal plank
#

hmmm so you are suggesting the manager doesnt exclude the initial client?

#

i would assume you could pass the client to the manager and it would shard it

quartz kindle
#

im suggesting that if you are gonna redirect all events to the manager, you are gonna have to process them with your own code, without a discord.js client

opal plank
#

but i need to login in order to recieve events no?

quartz kindle
#

you're receiving them in the shards

#

not in the manager

opal plank
#

im confused, how are they being recieved in the shards then?

quartz kindle
#

each shard has a discord.js client

#

it logs in

#

receives events

opal plank
#

how to you access events inside the shard?

quartz kindle
#

then if you send all events to a different process

#

this different process has no client

opal plank
#

hmmm i think i see what you mean

#

HMMMMM

quartz kindle
#

HMMMMM

opal plank
#

that would give a ton of troubles for me though

#

specially with caching]

#

d.'js cache, for that matter

quartz kindle
#

thats another issue

#

where do you want the cache to be?

opal plank
#

my main client wouldnt have all guilds cache

quartz kindle
#

in the shards or in the manager?

opal plank
#

the other cache is fine

#

manager would be best to have everything cetralized, the idea was to simply spawn shards to basically be event slaves

#

where they would recieve and re-emit to main

quartz kindle
#

yes

#

then you need to build your own handler and your own cache

summer torrent
#

anyone here using datadog

quartz kindle
#

the moment you redirect the event to another process, discord.js no longer has control over it

opal plank
#

couldnt i sync it?

#

i did syncs in my lib too

quartz kindle
#

yes but it can be really wonky

opal plank
#

every 30 seconds i would run an eval on every slave and return all cache

#

im not using message or anything of the sort

quartz kindle
#

thats basically gonna double your ram

opal plank
#

hmmm, theres that too

quartz kindle
#

i mean

opal plank
#

wait

quartz kindle
#

im pretty sure those uber big bots with millions of servers do that

#

a farm of slave shards

opal plank
#

actually

quartz kindle
#

but then again, they dont use discod.js

opal plank
#

what if i do it cacheless?

quartz kindle
#

thats even better

opal plank
#

not that way

#

cachefull but cacheless

quartz kindle
#

wat

#

lmao

#

basically your own cache?

misty sigil
quartz kindle
#

lmao

opal plank
#

each shard is cacheless, on recieving events i'd mimic the same that would happen when discord.js recieves an even nateively directly from discord, where it constructs the message, the guilds, all that

#

pass it to main and construct it there. Cache in the main client

quartz kindle
#

yes

opal plank
#

can i not mimic a sent even from the slave to my main client as it was coming from discord directly, so it handles the cache as normal?

quartz kindle
#

you probably dont wanna use discord.js for that tho

#

but you can

opal plank
#

okays thats at least a lot of options, but lets hear your best one, since im worried about performance

#

all those are DOABLE but probably shit

#

what do you have in mind?

quartz kindle
#

if i were to make a giant bot

#

it probably do something like this

#

lets say 1 million guilds

distant cobalt
#

Uhh so i made a drop command, but i need the bot to know when the first user adds a reaction

#

how do i do that?

quartz kindle
#

10 processes, in a 10 core vps
each process has 100 shards, using a raw websocket lib
each process receives raw events from 100 shards, and filters them based on some predefined criteria, like commands, prefixes, etc
once an event passes the criteria, it can be sent via IPC to a master process
the master process then does caching, handling, database, etc, and responds directly to the discord rest api

distant cobalt
#

....

opal plank
quartz kindle
#

yes

opal plank
#

let the spawner deal with the sharding by itself, it should be fine, but then re-emit everything into master, where the main client is, and simply have the client handle it like it would normally

#

like, for example

quartz kindle
#

you can trick discord.js into doing what you want

opal plank
#

though i could simply just attach it to the corresponding maps d.js has

quartz kindle
#
shard.on("message", (event, ...data) => {
  client.ws.emit(event, ...data)
})
opal plank
#

i dont think i can access a websocket connection to mess with that

#

thats the idea i was going for

#

use the websocket in a 3 way

quartz kindle
#

you will need to listen to the raw event in the shards

opal plank
#

and use the data recieved from the shard and emit into d.js's main client as a websocket event

quartz kindle
#

and forward the raw data

opal plank
#

yeah, that

#

the ONLY purpose of the slaves is to re-emit stuff

quartz kindle
#

then emit it in the websocketManager to trick discord into thinking it received it from ws

#

the thing is

opal plank
#

that seems, to me at least, the most efficient and less tricky solution, as it would mean i dont need to update my old code at all

quartz kindle
#

if the slaves dont do anything other than reemit

opal plank
#

oh shit

#

yeah

quartz kindle
#

then you will have a stupidly huge influx of events in a single process

opal plank
#

sending mesages

#

and that

quartz kindle
#

thats why the shards need to do some basic filtering

#

and hopefully drop at least 90% of irrelevant events

opal plank
#

the majority of it is used though

#

i would assume

opal plank
#

but i could filter them IN the shard

#

beefore reemitting

quartz kindle
opal plank
#

reactionadd/remove/presences/memberupdates/messages, the rest i dont hink i perticurlaly need

#

so voice stuff

distant cobalt
# quartz kindle code
const embed = new Discord.MessageEmbed()
  .setTitle('🎊 DROP')
  .setDescription(`**Instructions:**\nBe the first to           react!\n\n**Host:**\n${message.author.tag}\n\n**Prize:**\n${dropPrize}`)
  .setColor('BLUE')
 let dropMsg = channel.send(embed)
dropMsg.react('πŸŽ‰') ```
opal plank
#

and all that garbage could be voided

quartz kindle
#

for example

#

ignore all precences that do not include genshin

#

and if you need to listen for when a user stops playing it

#

keep a small cache of presences in the shards

#

containing only the ones currently playing

opal plank
#

those are the ones i need

#

which im fairly certain i could just remove intents for the ones i dont need

quartz kindle
#

else you're reacting to nothing

distant cobalt
#

how do you have the bot say something when a user reacts

opal plank
distant cobalt
#

btw, @quartz kindle you can dm me the solution, i gtg

#

cya

misty sigil
#

this is big serious dev stuff

#

source: my brain

quartz kindle
# distant cobalt how do you have the bot say something when a user reacts

if you're waiting for a single reaction, like an answer to a question, use message.awaitReactions()
if you're waiting for several users to reach for a period of time, use message.awaitReactions()
if you're waiting for users to react and want to do something for each reaction while waiting, use message.createReactionCollector()
if you want to do something everytime someone reacts, use messageReactionAdd event

#

its 3am

opal plank
#

chats like these are usualkly said in DAPI, its quite hard to find people here who can keep up with what discord does internally

quartz kindle
#

i need sleep

opal plank
#

all good tim

#

go sleep

misty sigil
#

its 3am and same

opal plank
#

ty a ton for the insight

#

i'll make sure to bother you tomorrow, so wait for my wake up call

quartz kindle
#

lmao

misty sigil
#

whats your wake up call

opal plank
#

jk, but for real, ty for the info

opal plank
quartz kindle
#

a rooster

misty sigil
#

hehe

opal plank
#

me neighbors dog

#

fucker starts barking at 5am starving for food

earnest phoenix
#

my intro with extra bass

zealous dew
#

Hi tim

#

Can I ask you some question relate to shard and discord.js-light

gilded olive
#

What are features noobie devs come looking to make

misty sigil
#

i can prob help

opal plank
opal plank
zealous dew
#
    manager.broadcastEval(
        `this.users.fetch('188242504670380033').send('Thanks for voting')`,
        0
    );
#

why this is not working

#

TypeError: this.users.fetch(...).send is not a function

misty sigil
#

you need to await the fetch

zealous dew
misty sigil
#

whats erroring

zealous dew
#

UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token 'this'

misty sigil
#

needs to be an async func.

zealous dew
#

don't get your point

misty sigil
#

...

zealous dew
#

can you give me more details

#
    manager.broadcastEval(
        `async () => {
            const userInfo = await this.users.fetch('188242504670380033');
            userInfo.send('Thanks for voting')
        }()`,
        0
    );
#

like this ?

misty sigil
#

i think that'll work

zealous dew
#

yeah it working

#

thanks you

#

Can I mix discord.js-light and discord.js together

#

Init client with discord.js-light

#

and using other remain discord.js

misty sigil
#

not really

#

sometimes stuff just dies

zealous dew
#

So how can I switch from using discord.js into discord.js-light completely in fastest way

misty sigil
#

most shit is the same really

#

if you have MessageEmbed, Collection, etc.

#

thats the same

zealous dew
#

const { ShardingManager } = require('discord.js');

misty sigil
#

sharding manager is fine

#

that can stay

zealous dew
#

like this I have to change all require('discord.js') -> require('discord.js-light')

#

right ?

misty sigil
#

yep.

zealous dew
#

and all .cache.get will move into using .fetch

#

and in .fetch(id,cache) there always option cache

#

So I want to make cache fetch on default without pass param is it possible

zealous dew
#
    manager.broadcastEval(
        `(async () => {
            const userInfo = await this.users.fetch('188242504670380033');
            userInfo.send('Thanks for voting')
        })()`,
        0
    );

why this emit shardCreate event and it have no shards.is but it value is

{
  _eval: '(async () => {\n' +
    "\t\t\tconst userInfo = await this.users.fetch('188242504670380033');\n" +
    "\t\t\tuserInfo.send('Thanks for voting')\n" +
    '\t\t})()'
}
crystal wigeon
#
          (u) => u.id == id
        )```
#

returns undefined

misty sigil
#

please dont

mellow kelp
#

you should just use client.users.cache.get('id')

misty sigil
#

^ that

restive furnace
#

actually, ur should be using client.users.fetch('id')

#

there's absolutely no point using fetch, since it checks cache BEFORE requesting

cinder patio
#

Pros do const user =new Discord.User(client, {id: "id"}) if you need the user object only for sending a message to them

solemn latch
#

πŸ€”

#

that actually works?

slender thistle
#

I mean, you're just creating a fake user object that the library gets .id of

shut notch
#

Help

#

I’m trying to make a bot that counts from a !start command to a !stop command?

crystal wigeon
#

ok so quick question, since i've sharded and the guilds get split, what if i have a setTimeout func that executes are a function finishes, something like refilling 8 mana every 3 mins, but because of shards it doubles the refill time refilling 9 mana every 3 mins.. im sure if i use shard.ids[0] === 0 it'll only work for the first shard and wont work for the second shard

#

@umbral zealot

timber fractal
#

hey if u still need that command i have a solution but im not sure if its your package https://sourceb.in/3yKjP4n2yC wait i will dm it since much people are gonna type over this message

rocky hearth
#
function isThisPossible(a, b = a) {
  return a + b;
}
isThisPossible(2, 8); // 10
isThisPossible(2);    // 4

I want to hv the 2nd parameter defaults to the value of first parameter. Is it even possible?

cinder patio
#

yes it is

cinder patio
#

bruh the code CuriousBesant sent is correct

#

there's nothing wrong with it

#

then why..

rocky hearth
#

If that is correct, then I wont check for b to be undefined. That is already good and clean

vapid girder
#
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //top.gg/api/bots/697463492457922571/stats (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000017FB7E6AC40>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))```
#

Getting this error

rocky hearth
#

That is in python, I guess?

vapid girder
#

Yes

#

How to fix this error ?

slender thistle
#

Show your code

tired panther
#

I saw mee6/arcane ... bot and they have a custom avatar and custom status for servers which have premium. After my knowledge they create a second shard for the guild and then they can change the status. But how do they spawn the shard that should contain the premium guild?

tired panther
#

if(client.shard.ids.includes(0)) return console.log("hello");

crystal wigeon
tired panther
#

no when its shard 0 then yes

crystal wigeon
#

tf?

#

if i have a timeout func which does something it should be doubling that

#

includes(0) will execute this twice if there is shard 0 and shard 1

crystal wigeon
#

so what will shards.ids[0] === 0 do?

#

same thing right

#

if shard is 0

#

only then

#

but what about the guilds in shard 1? it wont even work for that?

zealous dew
#

anyone using akairo here ?

crystal wigeon
#

@tired panther

earnest phoenix
#

i have a question

#

can anyone help me?

crystal wigeon
#

depends on your question

earnest phoenix
#

alright so

#

if i go to my server in top,gg there are all my server but the deleted ones stays aswell how can i get that deleted?

#

because its to many now

crystal wigeon
#

idk about that, maybe wait a while or something

earnest phoenix
#

i already did.

green kestrel
#

hmm, all my shards are at 82% capacity, time to add more soon ig

cinder patio
#

flex

tired panther
green kestrel
#

πŸ’ͺ

#

doesnt work like that @tired panther

tired panther
tired panther
green kestrel
#

adding more shards means restarting all the clusters

#

and i dont do that without manual intervention

#

disrupting that many servers would piss them off πŸ˜„

tired panther
green kestrel
#

65.6

tired panther
#

is this the trivia bot?

queen crane
#

lol sharding isn't that simple

green kestrel
#

yeah

tired panther
#

no its easy, use discord.js-light

green kestrel
#

not light enough for me thanks

tired panther
#

does discord-js light have cluster?

green kestrel
#

no idea

#

but i know it would take a ton more ram than i do atm

dreamy trout
#

do you know how to fix dbm

cinder patio
#

discord.js-light just removes the caching mechanism of discord.js, nothing more

green kestrel
#

fix it? why, is it broken @dreamy trout ?

queen crane
tired panther
dreamy trout
cinder patio
#

their bot isn't written in javascript

green kestrel
#

i host at ovh on a dedicated server, bare metal

tired panther
cinder patio
#

then why are you recommending discord.js-light

#

a node.js library

green kestrel
#

@dreamy trout unfortunately you cant really troubleshoot, DBM does everything for you, to the point of having no facilities to debug it. if you want to figure out whats going off, you need to learn to code your own bot really

#

@cinder patio i could turn off caching on aegis, and each cluster would use like 10mb... im actually tempted, but it would mean a ton more db queries

dreamy trout
cinder patio
#

Brain, what do you cache? I'd imagine you don't need to cache a ton of stuff for a trivia bot

green kestrel
#

users, guilds, roles and role memberships, channels

#

most of it is then written to sql for dashboard use when a user issues a command or successfully answers a question

#

if i turned off caching i'd have to write that data for dashboard use at the point where i see it, which means a HUGE number of INSERT INTO ON DUPLICATE KEY UPDATE for roles when a cluster boots

#

like literally millions

#

booting a cluster would go from 20 secs to minutes

#

the cache is small enough that i'd sooner sacrifice a bit of ram for the cache, than to do that and hammer mysql to death

#

each cluster is an independent native compiled process that manages 4 shards

dreamy trout
zenith terrace
#

you need the ID of the custom emoji

dreamy trout
#

oh how to get it

sacred aurora
#

try sending the emoji with \ before the emoji

#

u should get <:name:id>

dreamy trout
#

thx

sacred aurora
#

not the bot

dreamy trout
#

Ik

sacred aurora
#

oof

dreamy trout
#

I think I need to login from discord bot client

sacred aurora
#

nah

#

can u get a emoji from the bot cache?

#

i never do that

#

so i don't know exactly how

dreamy trout
#

now I've got it

#

thx

sacred aurora
#

noice

dreamy trout
zealous dew
#

I am using akairo and want to using all framework function
Example:
?cf h 3000
?cf 3000 h
my currently args
js args: [ { id: 'face', type: 'string', }, { id: 'betMoney', type: 'number', }, ],
it's working in case one but in second it swap position make anything messy so I there anyway we can do it working in both way without check it in exec() Anyone can help me?

dreamy trout
#

sorry I can't help u I'm not using akiro

zealous dew
#

it ok

fair axle
#

I have a problem. I don't know how to say it but I'll try.
I am making a twitch stream notification system for my bot on discord.js. I have problem about thumbnails. The question isn't about twitch. I am sending an embed with stream thumbnail image. But the original image and embed's image is different.

#

images are different but same link

wintry pier
#

!b invite

fair axle
#

When I make it .setThumbnail the problem solves but I want it to be .setImage

earnest phoenix