#development

1 messages · Page 670 of 1

onyx summit
lusty dew
#

Then how do I vote lock the commands that is what I'm trying to do

onyx summit
#

well, you have to listen on the vote event, then store every new vote anywhere, and then when someone is running the command you check if he is in your db

quartz kindle
#

^

winged thorn
#

don't vote

onyx summit
#

I can just setup the vote server for you xD

winged thorn
#

I didn't meant to send that

#

lol

onyx summit
#

Then delete it

lusty dew
#

I mean if you want

#

Lil

#

I'm struggling

#

A bit

quartz kindle
onyx summit
#

I'm seeing that

lusty dew
#

Heh

#

I've never worked with webhooks

#

Don't even know what they are or what they do

blissful wind
#

If it makes you feel better I'm trash at webhooks and API's, I usually try to avoid them omegalul

quartz kindle
#

neither have i, but they are not hard to understand lul

lusty dew
#

I haven't read up on em tbh

quartz kindle
#

i dont like vote locking

onyx summit
#

It's basically just a post request

lusty dew
#

I should but eh

blissful wind
#

JSON API's are a good learning point though. If you're a weeb, try setting up the nekos.life API or even random.bird if you're a bird lover like me

lusty dew
#

I'm only vote locking like 3 commands lol

#

I'm only vote locking like 3 commands lol

quartz kindle
#

yeah i have my own api as well

earnest phoenix
#

vote locking is nasty

onyx summit
#

Just stahp

#

It's his bot, his decision

earnest phoenix
#

ok

lusty dew
#

Thank you

earnest phoenix
#

no one is telling them to change it

onyx summit
#

I'm also vote locking a feature to prevent spamming lol

earnest phoenix
#

lol

lusty dew
#

I'm trying to get my bot the most votes ad possible

#

😂

blissful wind
#

Vote locking is also a good way to low-key promote voting, so I mean, why not haha

onyx summit
#

anyway, is level a file based db? Never used it

lusty dew
#

Idk

blissful wind
#

level?

quartz kindle
#

yeah leveldb is file based, but its very efficient

blissful wind
earnest phoenix
#

votelocking is bad in my opinion; it's turning away users from using your bot because people don't wanna bother, and it's equivalent of having to watch ads in mobile games in order to get something, except here the bot owner isn't even getting any money despite DBL putting ads on your bot page 🙃

#

Can I get help

#

Can I get help

#

Oops lag

quartz kindle
#

but level doesnt support multiple clients last time i checked, which is a no-no for sharded bots

onyx summit
#

Just ask what you want holy shit

quartz kindle
#

sqlite is a good solution for most discord bots

earnest phoenix
#

Yes for tickets

onyx summit
#

nah I'm just seeing that Haruna switched to level db

earnest phoenix
#

Tickety

blissful wind
#

I agree with Tim, SQlite, MySQL, mongoDB are all really good

earnest phoenix
#

When it joined what’s the prefix?

#

It says it’s: -

#

But doesn’t work

onyx summit
#

I don't think this is the right channel

blissful wind
#

I prefer SQLite and MySQL

tight heath
#

Postgres

earnest phoenix
#

Idk

#

Can I get help

#

Does it rlly matter

onyx summit
#

Not here

earnest phoenix
#

Where did

onyx summit
#

I don't give a fuck what that bot has as prefix

blissful wind
#

kun go to general if you wanna figure out a bot prefix, or just go into the testing channels and ask around there

onyx summit
#

Nothing related to developing

earnest phoenix
#

Chill

onyx summit
#

I'm chill

lusty dew
#

Try the support server @earnest phoenix

earnest phoenix
#

No ur not

#

they're chill, but toxic

onyx summit
#

@tight heath why mmmm? PostgreSQL good SmileBOYE

blissful wind
#

jesus christ we have a troll

lusty dew
#

Try the support server @earnest phoenix

#

This isn't the support server for that bot

tight heath
#

@onyx summit that's the point

earnest phoenix
#

I GOT TO HERE

tight heath
#

:)

#

postgres is best sql

onyx summit
#

Yas

earnest phoenix
#

THE SUPPORT SERVER IS HERE

#

?

lusty dew
#

No

earnest phoenix
#

this isn't a support server for any bot, this is simply a bot listing service

opaque eagle
#

postgres good

onyx summit
#

STILL WRONG CHANNEL

tight heath
#

cry stop crying

onyx summit
#

THIS HAS NOTHING TO DO WITH DEVELOPMENT

tight heath
earnest phoenix
#

yeah postgres is 💋 👌

#

;(

#

I am not talking to u

tight heath
#

@earnest phoenix no it isn't pls stop caps or i will eat all your pancakes

onyx summit
#

okay at least we all agree that psql is good

earnest phoenix
#

postgres is genuinely nice for big scale projects

onyx summit
#

No not the pancakes Angery

opaque eagle
#

@earnest phoenix Go to the bot's support server --> https://discordbots.org/bot/352854019934257156 (Click the white Join Support Server button, not the Join Discord one at the top of the page)
And ask for help there

earnest phoenix
#

I fucked up

opaque eagle
#

ye we know

blissful wind
#

definitely

opaque eagle
#

we've been trying to tell u

earnest phoenix
#

I said !help and now I got 100 DMs

opaque eagle
#

thats ur problem

tight heath
#

haha ur so funny and original noone ever did that

#

anyways back to dev

blissful wind
opaque eagle
#

is that enough proof that we're a bot listing service and not tickety support?

onyx summit
#

But this is the support server spongemycock

tight heath
#

@opaque eagle how is Excuse defined?

onyx summit
#

it says right there "Discord Bot List" spongemycock

tight heath
#

class Excuse { constructor() { return null; } }

earnest phoenix
#

you forgot to throw an exception

tight heath
#

class Excuse { constructor() { throw null; } }

opaque eagle
#
interface Excuse {
    reason: string;
    howLongItWillLastBeforeHavingToFindANewOne: Date;
}```
tight heath
#

thanks for the hint

onyx summit
#
class Me
{
constructor()
{this.sad = true;}
}
tight heath
#

reason: boolean;

#

"no"

onyx summit
#

kthx

tight heath
#

async unSad() { await this.getHappy(); this.sad = false; }

lusty dew
#

Why did this turn into talking about vote locking to this

onyx summit
#

because why not

tight heath
#

this is serious dev talk right here

earnest phoenix
#

weed lol

opaque eagle
#

@tight heath ReferenceError: getHappy() is not a function

tight heath
#

oh huh

sudden geyser
#
TypeError: Cannot read property getHappy of undefined```
opaque eagle
#

LOL

onyx summit
#
while(this.sad)
{console.warn('reeee kill meee');}
}
sudden geyser
#

they say console is slow

opaque eagle
#

That's identical to js while (true) { console.warn('reeee kill meee') }

onyx summit
#

Console is indeed slow

#

afaik console logging in an endless loop will fill ram very fast

opaque eagle
#

Also Unexpected token } @onyx summit

onyx summit
#

Maybe that's fixed

opaque eagle
#

You've got an extra one

onyx summit
#

ups

#

I'm on phone

opaque eagle
#

k

onyx summit
#

To lazy to turn my computer on lol

tight heath
#
const { promisify } = require('util');
const sleep = promisify(setTimeout);
async getHappy(time) { 
    await sleep(time);
    await this.city.stores.find(s => s.has('chocolate')).buy('chocolate')
        .then(c => c.eat);
    return true;
}
opaque eagle
#

u forgot the function keyword

tight heath
#

no it's in a class

opaque eagle
#

it's just async getHappy(time) rn

tight heath
#

i just cba to write that

opaque eagle
#

oh

onyx summit
tight heath
#

otherwise the this would be pretty pointless too lol

onyx summit
#

:)

opaque eagle
#
Error .buy()
       ^
No vendor will sell you chocolate```
tight heath
#

what

lusty dew
#

@onyx summit I'ma figure this voting thing out

onyx summit
#

but

lusty dew
#

But what?

onyx summit
#

I wanted to clone it rn

lusty dew
#

Clone what

opaque eagle
#

Clone what

onyx summit
#

the repo

#

so should I

#

or not

lusty dew
#

Sure to ahead

onyx summit
#

done, you need to edit vote-server/config.js

#

with your secret and stuff

lusty dew
#

Hm?

onyx summit
#

you need to edit the file

#

with ur token and all

lusty dew
#

Okay

#

What am I adding in or removing

onyx summit
#

auth

#

with your webhook auth

#

and token

#

with ur dbl token

lucid iris
#

Really noob question: how do you handle storage in node.js?
I don't need to persist data, I already use a DB for that. I want some runtime memory to introduce a cooldown on certain commands.

lusty dew
#

Okay added in the token and auth into my bot.json @onyx summit

mossy vine
#

just use a variable and pass it to other functions if needed @lucid iris

onyx summit
#

I think a Map is what you would need for cooldown

#

dude I said in vote-server/config.js

mossy vine
#

depends

onyx summit
#

but I will just get it out of there lol

lusty dew
#

Oh sorry

mossy vine
#

Map seems to be the best option

onyx summit
#

or Set might work too

#

dunno, I don't use it that often

lusty dew
#

@onyx summit do you want me to change it

onyx summit
#

I already did

lusty dew
#

Ah okay

#

Do I need to do anything else kind sir?

mossy vine
#

i use Sets and timeouts now. its a horribly inefficient method but i dont care enuogh to rewrite those 7 lines

onyx summit
#

yes, remove that stuff from your bot, bec port 30 001 is blocked xD

lusty dew
#

Okay

#

Removed

onyx summit
#

fixed it for you, but just saying: ' is not allowed in json

lusty dew
#

Oof

#

Thanks

#

Now what do I do

onyx summit
#

so basically you should be able to do

// your command stuff
if (! await client.voted.hasVoted(some user id)) console.log('that person didnt vote');
lusty dew
#

Okay thanks!

onyx summit
#

and you can spam it lol

#

doesnt matter how often you call it

lusty dew
#

Good

#

Lol

#

Didn't feel like adding a cooldown rn

#

@onyx summit Hm it's not working?

onyx summit
#

more info?

lusty dew
#

It just keeps sending the message that if they haven't voted

#

Won't send the embed if they already have

#

And I voted myself to test this

onyx summit
#

what cmd

#

wait when did you vote

lusty dew
#

NSFW_cosplay.js

#

5m ago

#

Or less

onyx summit
#

oh yeah

#

my bad

lusty dew
#

What?

onyx summit
#

change it to https://webhooks.chilo.space/clap/vote/

split hazel
#

When i upgraded to node 10, i am now getting
Error: Cannot find module '/root/node_modules/.registry.npmjs.org/sqlite3/4.0.2/node_modules/sqlite3/lib/binding/node-v64-linux-x64/node_sqlite3.node'

real helm
#

Hello

onyx summit
#

did you reinstall everything?

split hazel
#

Nope, i upgraded npm using the n package

onyx summit
#

then reinstall node modules

split hazel
#

should i just run npm install

onyx summit
#

you can press on "test" @lusty dew to vote again

#

on the edit page

#

I would first delete node_modules and then npm i

#

if you change node versions you normally have to recompile everything

split hazel
#

alright i'll try that

real helm
#
  player.brawlers.forEach(e => {
        var resultados;
       if(e.trophies > 500){
       let resta = e.trophies - 500
        let division = resta / 2
        let final = parseInt(division)
        resultados += final
          // message.channel.send(resta)
         
       }
       
       
     })
  message.channel.send(resultados)
}
#

Don't work

#

resultados isn't definied

#

why

lusty dew
#

@onyx summit it's still asking me to vote

onyx summit
#

bec you didnt define it @real helm

real helm
#

is define in the forEach

onyx summit
#

but its not defined xD

amber fractal
#

@real helm you're using it out of scope

real helm
#

But if put the message.channel.send the bots sends the results a lot of times

#

and I like that it only send the results 1 time

onyx summit
#

if you do var resultados; resultados will still be undefined

real helm
#

yes, i know

amber fractal
#

define it outside the forEach

#

oh I didnt see

inner jewel
#

scoping issue

onyx summit
#

he is not using it out of the scope

amber fractal
#

just set it to 0

#

or some other default value

onyx summit
#

its var

#

var is global

inner jewel
#

no

#

var is function scoped

real helm
#

i put now a let

onyx summit
#

at least in normal browsers

inner jewel
#
> function callIt(f) { f() }
undefined
> callIt(() => { var x = 1; })
undefined
> x
Thrown:
ReferenceError: x is not defined```
#

even in normal browsers that'd error

#

var isn't global

#

and never was

#

it's always been function scoped

onyx summit
split hazel
#

im getting npm ERR! path /root/node_modules/.staging/better-sqlite-pool-1347399d/node_modules/lodash npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall rename npm ERR! enoent ENOENT: no such file or directory, rename '/root/node_modules/.staging/better-sqlite-pool-1347399d/node_modules/lodash' -> '/root/node_modules/.staging/lodash-74c86b5c' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

onyx summit
#

uh yeah my bad

#

not function scoped

#

wasnt thinking correct

inner jewel
lusty dew
#

@onyx summit I even had one of my beta testers try the vote locked commands and have em vote then try it again it's not working for them as well

onyx summit
#

you did set the url in dbl?

#

but yeah

  1. wrong scope
  2. would still error, you didnt gave it a value
lusty dew
#

Yes

#

In the webhook section under edit bot right?

onyx summit
#

yeah

#

sigh

#

omg

#

found it

lusty dew
#

@onyx summit Have you checked the vote-server logs lol

onyx summit
#

yes

lusty dew
#

Ye same

onyx summit
#

https://webhooks.chilo.space/clap/vote
the slash at the end was too much

lusty dew
#

Ok

split hazel
#

now every module i try install i get errors

opaque eagle
#

block scoped !== function scoped

earnest phoenix
#

Socket hang up please help me :/

#

(glitch) i didn't fix

#

solution: don't use free hosting

onyx summit
#

solution: don't use bad free hosting

opaque eagle
#

^

earnest phoenix
#

but every free hosting is bad 🙃

onyx summit
#

well a public free service is bad

opaque eagle
#

I get free Azure for a limited time cuz of GitHub Student

onyx summit
#

but free doesnt mean bad mm

opaque eagle
#

so is Azure bad

earnest phoenix
#

azure isn't free though

#

they provide you a service without fees because you're a student and they can offer you education through that

inner jewel
#

gcp has a forever free vps

#

:^)

earnest phoenix
#

🙃

opaque eagle
#

aws free for a year

#

all those are bad i guess

earnest phoenix
#

aws (free trial) is limited

lusty dew
#

@onyx summit Still won't show anything

#

Just the vote embed

onyx summit
#

can you click on test again?

lusty dew
#

Ye

#

Clicked it

onyx summit
#

it works

#

on the vote server

lusty dew
#

Now will it work for everyone else?

onyx summit
#

yes

#

should

#

worked for me

lusty dew
#

Okay goos

#

Thank you!

split hazel
#

got everything working by deleting package.json aswell and instlaling every module one by one

#

i heard on discord.js master reactions are now seperate to the message object, how do i fetch the reactions object?

maiden mauve
#

tfw your power company needs a new bot dev

onyx summit
#

a bot dev?

maiden mauve
#

hehe

#

just made me laugh that we read syntax errors in here all the time

#

to get one from a website cracked me up

amber fractal
#

what syntax error?

earnest phoenix
#

İ fixed...

wooden lance
#

Hello. I'm trying to set up my bot to be configurable (with SQLite) but let's just say, the documentation isn't that helpful. I already have the connection set up

const connection = mysql.createConnection({
  host     : '#',
  port     : '3306',
  user     : '#',
  password : '#',
  database : '#',
  charset : 'utf8mb4'
});

how do I check to see if a server's value is marked as, let's say 1 then run code? Also, how do I set that value in a command? Thank you! (By the way, please ping me if you respond!)

stone dust
#

@wooden lance iirc you’ll generally be interacting with the DB via a “cursor” object in your language of choice

#

Fetching a value from the DB will generally be done w a “SELECT” query and assigning will generally be done with an “UPDATE” query

#

if you haven’t used SQL before the queries aren’t too bad but the general pattern is using the cursor to make a query, then fetching the results as needed and acting on them

wooden lance
#

I haven't used databases before. And, I don't know what a select or update query is.

stone dust
#

ah np

wooden lance
#

I've tried using a db before, it didn't work.

stone dust
#

SQLite as well?

wooden lance
#

I haven't successfully got SQLite to work before either.

stone dust
#

ah

#

do you have a way to interact with the server in the command line?

#

or otherwise*

wooden lance
#

yes

winged thorn
#

sqlite is quite easy

#

I've got it working rather well

stone dust
#

cool

winged thorn
#

With python at least

stone dust
#

@wooden lance and you haven't been able to get a response from it yet?

wooden lance
#

wait, the server (as in vps) or sql db?

stone dust
#

oh sorry

#

the sql db yeah

wooden lance
#

sadly not.

#

i do have all the login credentials though

stone dust
#

ah ok

#

what are you following to get it started up?

wooden lance
#

wym

#

lol im making myself look like such a noob

stone dust
#

lol don't worry about it

#

being insecure about asking for help won't serve any benefits, you've gotta do it once or so

wooden lance
#

yeah

stone dust
#

i guess like

#

what resource have you been using to start up the sql DB so far

#

and where are you hosting it from as well (local or online or)

wooden lance
#

start the my sql server?

stone dust
#

yeah

wooden lance
#

it's up 24/7

stone dust
#

ah cool

wooden lance
#

it's managed by a company with my domain name

stone dust
#

oh that's neat

#

uh

wooden lance
#

hosting it online

stone dust
#

is it mysql or sqlite?

wooden lance
#

mysql

stone dust
#

ah ok

#

do you have an interface like phpmyadmin that you can interact with it through or is it purely command line

wooden lance
#

wait, give me a sec, i do think i can get SSH access to it

stone dust
#

oh oh cool

#

additionally are there any errors that appear when you try to connect or is it just not responding at all

wooden lance
#

i haven't actually tried starting the bot up with that connection

stone dust
#

oh

#

you could try something like mysql workbench to access the DB

#

might be a good way to start fiddling around

wooden lance
#

okay

#

downloading that

#

right installing

#

@stone dust installed

stone dust
#

should be able to log into your database through that

#

and start creating tables and things

wooden lance
#

Okay

stone dust
#

if that works then would definitely suggest getting familiar with some common queries, select, insert, and update are the most common ones so knowing those is key

wooden lance
#

After I have done that, what code would I need to check to the db for a server's ID and a value? And if the value = 1 run code?

stone dust
#

that would most likely be a select query

#

you could build a table which tracks server ids along with a one bit flag

wooden lance
#

okay

#

@stone dust, this is gonna seem like a very stupid question, but what is the code for the select query? I have not used them before.

#

And the discord.js docs make no sense to me

stone dust
#

oh yeah np

#

IDK how DJS does it, is there something built in for handling MySQL?

valid frigate
#

how do i make the ShardingManager of the master process available to my sharded clients

wooden lance
#

@stone dust i dont know

stone dust
#

ah np

#

uh oh

#

do you have to whitelist your IP?

wooden lance
#

to connect to the server? dont think so

stone dust
#

assuming the credentials and port num are correct it’s that or the server is unresponsive

#

or something else

wooden lance
#

hmm

#

can i have mysql on my bot's vps @stone dust?

#

as in a local server? so just on the same vps?

stone dust
#

uh

#

I think so

wooden lance
#

or quickdb

stone dust
#

yeah any of those should be fine to host locally assuming the port isn’t occupied

wooden lance
#

okay

#

thanks for your help! 😃

stone dust
#

No problem, sorry I couldn’t get to the bottom of it but best of luck!

wooden lance
#

thanks!

wooden lance
#

I am having some problems with quick.db on javascript. Anyone know what I can do to fix this?
/root/DiscordBotApp/node_modules/better-sqlite3/lib/backup.js:9
return async function backup(filename, options) {
^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/root/DiscordBotApp/node_modules/better-sqlite3/lib/database.js:51:34)

sudden geyser
#

Does your Node.js version support async?

sage bobcat
#

One message removed from a suspended account.

stone dust
#

nothing is returned by the function so gold isn’t set to anything

#

or there’s no error so console.log just logs something falsy

split hazel
#

I noticed

let e = array[i]```
makes it loop over a non existant element aswell, so if have 3 elements, it will loop over a 4th one that doesnt exist
#

do i just add -1 to array.length?

earnest phoenix
#

or just

#

remove the operator that says to continue if i is equal to length

#

length starts with base 1

#

arrays with base 0

#

ergo length is always going to be +1

topaz fjord
#

just cange <= to <

#

like cry said

indigo geyser
#
@commands.has_permissions(manage_server=True)
```why it does not recognize the `manage_server`?
slender thistle
#

server -> guild

warm marsh
wooden lance
#

@warm marsh no, i didnt notice the response. do you know how to update node?

warm marsh
#

Depends, Are you on windows on Linux?

wooden lance
#

Linux

warm marsh
#

What version is currently running? node --version

#

I doubt node is the main issue behind that error but, If the distro of linux is Ubuntu try:
sudo apt-get purge node* then curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - change 12 to a version you want, 12 being the latest once chosen run sudo apt-get install -y nodejs

#

Although, I don't think you need to purge the old one.

split hazel
#

What is the best way of limiting memory usage of my bot and sweeping useless things from memory? My memory climbs to about 1.1gb (from 600mb per shard) when it was online for around a day. im using discord.js

#

master

west spoke
#

I restart mine daily if that helps

earnest phoenix
#

auto reboot every day

onyx summit
#

sweep messages, users, members etc

#

Not completely but some of them

split hazel
#

Is there a quick way of implementing that?

onyx summit
#

And as already mentioned earlier, you should limit the caching of messages if you don't really need them

#

You can define some cache options in the client constructor

split hazel
#

Will probably have to look at those in the docs then haha

#

And i really dont need to cache messages as i fetch them from api anyway

#

i also have a packet event that fires messagereactionadd, delete and remove if the message is uncached

onyx summit
#

messageCacheLifetime
messageSweepInterval
messageCacheMaxSize

#

I played a bit with those and my ram doesnt really rise anymore

split hazel
#

May i ask for your recommendation for the setting of those?

topaz fjord
#

It's all about trial and error

#

His settings might not work for you

onyx summit
#

I have ```js
messageCacheLifetime: 60,
messageSweepInterval: 61,
messageCacheMaxSize: 20,

(master)
but I think you will have to try your owns
#

tbh I just mixed some numbers I thought that might work

topaz fjord
#

lmao

onyx summit
#

and before I had that, it was always rising

split hazel
#

Are there also sweep options for users?

#

because i dont get users from cache anyway, i do it through the API

onyx summit
#

not that I know of, but you can sweep every collection. you would probably sweep them if their last message was like really old

topaz fjord
#

no

onyx summit
#

worked fine

#

removed 178667 cached users

split hazel
#

I should probably add user sweeping on an interval

onyx summit
#

you can define that sweeping in the client options

#

but you can sweep users yourself

#

so, theoretically you could sweep users if your ram gets too high (but prevent spamming it when your ram goes higher without the users fault)

inner jewel
#

i just keep everything cached

onyx summit
#

cool

quartz kindle
#

you can have it run with less than 100mb ram at 2k guilds if you know what you're doing

onyx summit
#

depends on what your bot is doing tho

#

xD

quartz kindle
#

yes

#

and even then, you can work around

inner jewel
#

also, "high" memory usage can be just the gc being lazy

split hazel
#

Should i sweep users every couple hours?

inner jewel
#

and not running all the time to avoid pausing frequently

onyx summit
#

its an option shrug

#

you could log how often the gc is running to confirm Natans theory

quartz kindle
#

for example, delete everything except guilds, then use the raw event for messages, and if message matches a command, you can optionally fetch the channel, the user, the member, and everything else you need

onyx summit
#

and how much its cleaning

split hazel
#

yeah i use the raw event for messagereactionadd, remove and delete

inner jewel
#

(that's over a week, so it might look like memory is always rising but it isn't)

quartz kindle
#

depends on how much memory that is

onyx summit
inner jewel
quartz kindle
#

if its 1gb ram at 1k guilds for example, then its not normal

inner jewel
#

but zooming out shows that's not the case

#

it goes from ~1.1GB to ~1.4 then drops back to 1.1

quartz kindle
#

the thing is that d.js caches a lot of things by default, most of them you might not actually need

inner jewel
#

out of 1.5gb allocated for the process

quartz kindle
#

so there is a lot of room for ram improvements

onyx summit
#

agreed, d.js is not bad, but without some tweaks it eats a lot of ram

quartz kindle
#

that you can do as the end user, even if they are techincally not suppoerted methods

#

with my method i could keep my bot stable at 80-90mb ram at 1.5k guilds

onyx summit
#

I actually think of doing that

#

but nah, I have enough ram

quartz kindle
#

my vps only has 1gb ram so.. xD

onyx summit
#

yeah I actually rented some overpowered shit

#

thought I would host some gameservers but sad

earnest phoenix
#

still can't run a minecraft 1.14 server 🙃

#

you need a server farm to run a mc 1.14 server at this point to be honest, they made it so heavy

onyx summit
#

I think it will

earnest phoenix
#

(i was joking)

onyx summit
#

but my old vps wasnt able to run 1.13 becs of some fcking fish path calculations

#

maxed the cpu out

earnest phoenix
#

yeah 1.13 has a fuckton of performance issues

split hazel
#

actually do i need users cached for anything? I only fetch users through API

onyx summit
#

yeah I'm unsure too xD

#

ask in d.js support

#

but I don't think so

#

only reduces api calls (afaik)

earnest phoenix
#

actually do i need users cached for anything? I only fetch users through API
if your commands require a user to be provided as an argument, it would be preferred to have the user cached

#

that way you don't have to nag the command executor to use their id, rather you allow them to use their username etc

#

though caching users is irrelevant in guilds which have less than 100 members

split hazel
#

Wouldn't i just get everything through the member object?

quartz kindle
#

if you need to do any operation on a user, like kick/ban/dm/roles/etc, then you should cache them

split hazel
#

yeah i need for roles and dm so i should probs keep them mmLol

earnest phoenix
#

Wouldn't i just get everything through the member object?
but how will you get the member object if you don't have the id

quartz kindle
#

yes, but what you can do is also cache them as needed

#

or simply sweep them regularly

onyx summit
#

I would make it like this:
sweep allows a method to decide if they should be sweeped or not. you could check the last message, if its not set, delete the user, if its set and already a few hours old (check timestamp) delete him

earnest phoenix
#

the issue comes where the caches between your bot and a user's client are mismatched. a user can have another user in their client cache, but your bot maybe doesn't have that specific user in cache, so the bot wouldn't recognize the user if it was provided as an argument through a form of a username lets say

quartz kindle
#

you mean like using mentions?

earnest phoenix
#

mentions are doable

#

you can extract the id

#

however, it will cost you an api call to verify if the user actually exists or not

#

because someone can provide a dummy mention

#

discord.js seems to be really heavy on caching and honestly i don't know why, i used to keep every single member in 2.2k guilds cached (even in here) and the bot wouldnt peak over 500 mbs on discord.net

quartz kindle
#

yes, but you can fetch it once and then keep it in the cache, it costs a few calls, but its still better than running with hundreds of cached users that are never used

#

slowly your bot will get populated with users that are actually relevant and used, instead of trash

#

lul

#

but i think djs's goal is to minimize hitting the api as much as possible

#

even if it costs half of your machine's resources

#

or more

onyx summit
#

its not that bad xD

#

okay for you it might

quartz kindle
#

well im still using the sweeping version in production, using around 200-300mb

#

but im gonna switch to the raw methods eventually

split hazel
#

I'm getting these when starting bot

0|shards   | [Error ../js/decoder.h:28] Bad version number.
0|shards   | [Error ../js/decoder.h:151] Reading sequence past the end of the buffer.
0|shards   | [Error ../js/decoder.h:117] List doesn't end with a tail marker, but it must!
0|shards   | [Error ../js/decoder.h:28] Bad version number.
0|shards   | [Error ../js/decoder.h:50] Reading a byte passes the end of the buffer.
0|shards   | [Error ../js/decoder.h:50] Reading a byte passes the end of the buffer.```
inner jewel
#

looks like discord sent a bad payload

#

or something in the middle sent garbage

#

removing erlpack might help

split hazel
#

i'll try that

quartz kindle
#

erlpack has issues with node v12

#

there is a pr to fix them, but its been pending there for 25 days and nobody seems to care so idk

#

im using the forked version from the guy who made the pr

split hazel
#

Now i'm getting

0|shards   |     at Timeout.setTimeout [as _onTimeout] (/root/node_modules/discord.js/src/sharding/Shard.js:137:31)
0|shards   |     at ontimeout (timers.js:436:11)
0|shards   |     at tryOnTimeout (timers.js:300:5)
0|shards   |     at listOnTimeout (timers.js:263:5)
0|shards   |     at Timer.processTimers (timers.js:223:10) [Symbol(code)]: 'SHARDING_READY_TIMEOUT' }```
#

but on a test version of bot that has same code (thats on glitch) works fine

quartz kindle
#

maybe the shard process is throwing an exception

split hazel
#

actually yes i got a rejection

#

(node:6603) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emoji' of undefined

#

will fix that myself

#

seems to be coming from
if(reaction.emoji.name !== "🎁") return;

#

does master not include emoji object in reactions?

onyx summit
#

they do

topaz fjord
#

reaction is undefined for that to happen

split hazel
#

That's weird, it's in the messageReactionAdd event

#

module.exports = async (client, reaction, user) => {

topaz fjord
earnest phoenix
#

following that, you're getting the .emoji.name prop from a User object

topaz fjord
#

no event in d.js passes client

split hazel
#

but im using a command handler

#

so i have to pass client

topaz fjord
#

why are you putting events in a command handler

#

they are two different things

onyx summit
#

he means a event handler

split hazel
#

yeah thats what i meant

#

i have events in their own files

onyx summit
#

stop being so specific, everyone uses event handlers and everyone passes a client

#

are you using the raw event?

split hazel
#

i am

onyx summit
#

I think I had a similar issue a year ago lol

#

can you show the part in the raw event where you define the things for the event and then emit it

split hazel
#
    if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(packet.t)) return;
    const channel = client.channels.get(packet.d.channel_id);
    if (channel.messages.has(packet.d.message_id)) return;
    channel.messages.fetch(packet.d.message_id).then(message => {
        const emoji = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name;
        const reaction = message.reactions.get(emoji);
        if (reaction) reaction.users.set(packet.d.user_id, client.users.get(packet.d.user_id));
        if (packet.t === 'MESSAGE_REACTION_ADD') {
            client.emit('messageReactionAdd', reaction, client.users.get(packet.d.user_id));
        }
        if (packet.t === 'MESSAGE_REACTION_REMOVE') {
            client.emit('messageReactionRemove', reaction, client.users.get(packet.d.user_id));
        }
    });

}```
onyx summit
#

can you try this:

module.exports = (client, packet) => {
    if (!['MESSAGE_REACTION_ADD', 'MESSAGE_REACTION_REMOVE'].includes(packet.t)) return;
    const channel = client.channels.get(packet.d.channel_id);
    if (channel.messages.has(packet.d.message_id)) return;
    channel.messages.fetch(packet.d.message_id).then(message => {
        const emoji = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name;
        const reaction = message.reactions.get(emoji);

        if (reaction) {
            reaction.users.set(packet.d.user_id, client.users.get(packet.d.user_id));
        } else {
            const emoji = new Discord.Emoji(client.guilds.get(data.guild_id), data.emoji);
            reaction = new Discord.MessageReaction(message, emoji, 1, data.user_id === client.user.id);
        }
        if (packet.t === 'MESSAGE_REACTION_ADD') {
            client.emit('messageReactionAdd', reaction, client.users.get(packet.d.user_id));
        }
        if (packet.t === 'MESSAGE_REACTION_REMOVE') {
            client.emit('messageReactionRemove', reaction, client.users.get(packet.d.user_id));
        }
    });
}
split hazel
#

i'll give it a shot

onyx summit
#

by the way that user thingy will rely on cached users

#

so if you really need that user it you would need to fetch that user

split hazel
#

i get the same error

#

its also preventing my bot from booting

#

i just noticed one shard booted but some of the others refuse to do so

#

hold on the error went away

#

now im getting discord is not defined

#

need to find that

#

now i'm getting

0|shards   |     at channel.messages.fetch.then.message (/root/events/raw.js![13](https://cdn.discordapp.com/emojis/521069905257431040.webp?size=128 "13")63)``` @onyx summit
onyx summit
#

uff okay that happens if you copy and paste code from another context

#

my bad

split hazel
#

now im getting "animated is not defined" and "data is not defined"

#

what i dont get is the exact same code works on glitch where i test the bot before i put it onto the vps

onyx summit
#

hm, I dunno why, but this worked good for me, sorry, then I can't help you

#

glitch good KAPPA

#

are the cache settings different?

split hazel
#

their the same

#

i guess i'll revert to my stable code until i figure out how to get it working

split hazel
#

thanks alot for trying to help though

#

our big master update must wait mmLol

sacred spade
#

When you add your bot on Discord Bot List, it automatically adds it to the Discord. How would I do the same?

split hazel
#

well first your bot needs to pass the submission process

#

it then appears publicly on the website and gets invited here

#

if not your submission gets deleted and bot doesnt get invited

tight forum
#

hi guys

#

im trying to make a custom prefix command, everything is ok

#

but i need to define the db.Fetch to functions.js

#

how can i do it ?

lusty dew
#

When would you use zlib-sync? When sharding or can you use it at any time?

ember atlas
#

Why is it saying my token is invalid when its not

lusty dew
#

Are you using a client secret instead of a token?

#

@ember atlas

ember atlas
#

no

lusty dew
#

Have you tried regenerating the token and using the new token?

ember atlas
#

yep

#

same thing

#

tried that abt 4 times

lusty dew
#

Okay show code of how you login

#

Without showing token

ember atlas
#

never had these issues

lusty dew
#

That looks like your json

#

What about your main file

#

Show how you login

ember atlas
#

i didnt make it

#

so idk how it works

#

but ive never had an invalid token error ever

lusty dew
#

Wait what language are you using

ember atlas
#

i think its js

lusty dew
#

You think?

ember atlas
#

like i just said

#

i didnt make it so idk how it works but ive never had an invalid token error ever

lusty dew
#

You shouldn't copy and paste code without understanding it first

ember atlas
#

are you-

#

its a fucking modmail bot..................

lusty dew
#

Okay?

#

I'm confused as to how that has anything to do with this? You're still making the bot and don't even know if it's js

ember atlas
#

and this is why i dont come to this server for hlep

#

no one understands that everyone just forks modmail and starts it

#

thanks for trying

lusty dew
#

Lmao

#

Okay

#

Thanks for wasting my time GWcmeisterPeepoShrug

pallid zinc
#
var ttt = new Discord.RichEmbed() 
.setTitle("TIC TAC TOE") 
.addField ("⬜⬜⬜ ", ) 
.addField ("⬜⬜⬜ ", ) 
.addField ("⬜⬜⬜ ", ); 

message.channel.send(ttt).then(function (msg) {

msg.react("↖️") 
msg.react("⬆️") 
msg.react("↗️") 
msg.react("⬅️") 
msg.react("↕️") 
msg.react("➡️") 
msg.react("↙️")
msg.react("⬇️") 
msg.react("↘️")

}).catch(function() {

})
 break;```
#

It's not reacting msg

#

No console err

sudden geyser
#

try logging it at .catch

pallid zinc
#

Ok

earnest phoenix
#

Someone know how if the user click on emoji reacted by a bot he get the user mentions or username?

#

Or something like this???

opaque eagle
#

What language and what library @earnest phoenix

amber fractal
#

Well considering he's in the Discord.js Official discord

#

I would assume d.js

#

Well the basic pseudo-code would be
listen/wait for reaction > if reacted mention user

valid frigate
#

how do i access the ShardingManager from a sharded client

#

this is in djs

earnest phoenix
#

@opaque eagle discord.js

opaque eagle
earnest phoenix
#

Ok thanks

#

:)

opaque eagle
#

How am I supposed to know he's in that server @amber fractal

#

np

valid frigate
#

ah fuck

earnest phoenix
#

Discord.js official site

idle hull
#

XD

amber fractal
#

@opaque eagle you arent

#

just saying that he is

#

I didnt mean to be passive aggressive, I guess.

opaque eagle
#

Ok

viral spade
#

Hi, i have a question.
I want my bot to run on multiple vps, but i have a big statistics database i cannot query remotely all the time from all shards. Each vps/shard should hence load and have only the information it neeeds for answering stats requests from the respective servers the shard is on. Each shard will also write new statistics into its local storage, andshoueld update the changes to the remote database perodically.
I was wondering, is there some known and beautiful solution to this? I am about to "manually" program this cache: An api for my remote database (mysql) to load and update saved records. Then some local storage solution (maybe some in-memory sql solution?) to load and run the actual queries on the vps machines.

carmine echo
#

is it a violation of tos to send people a dm once they've voted 3 times

trail dagger
#

no

carmine echo
#

epic

trail dagger
#

just dont spam down someones dm

short portal
#

anyone have know why my bot keeps changing its presence when the only time it changes it is when its ready. But it doesn't restart

#

i can send the code that does it

sour sage
#

Send it.

short portal
#
client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`)
  client.user.setActivity("people poke each other", { type: 'WATCHING' })
});
sour sage
#

Nothing wrong there

short portal
#

that is the only place i set the activity

quartz kindle
#

does it also spam the "logged in as"?

#

in the console

short portal
#

no

#

it crashes like every 5 mins

#

but not every 10 secs

quartz kindle
#

well then idk

#

show your code?

short portal
#

the whole thing?

quartz kindle
#

yeah

short portal
#

this is my first time coding in js

earnest phoenix
#

that is so messy and unreadable

short portal
#

i can understand it. but yh i see what you mean

quartz kindle
#

is it on glitch/heroku?

short portal
#

glitch

earnest phoenix
#

i can already see a few issues; you should only have one event handler, switch case your commands in one handler instead, and don't use json as a database as it's more prone to data loss and corruption

short portal
#

im gonna move over to sqlite

earnest phoenix
#

you should try catch sending a dm to a user as it oftens fails due to the user not having dms enabled

short portal
#

i thought i did

quartz kindle
#

yeah there is room for improvement, but i dont see why it would be resetting its presence every 10 seconds aside from crashing/disconnecting

#

maybe after a code cleanup it will also fix itself

short portal
#

ok

quartz kindle
#

join all your on("message") together into a single on("message") event

short portal
#

ok

quartz kindle
#

i g2g out now

viral spade
#

Hey Tim please help me out on this, noone seems to know.
So i have a statistics bot and my bot/3shards(discordjs) an data(mysql) lie on the same server. I am at 3500 servers and i think my current build will not make more than 20k, as a loot of complex database queries are done every second already and the response time is also not great.
At some point i need to be able to horizontally scale on multiple vps. I intend to have a remote backup database and a local "cache", that is populated at startup (with records of the servers the respiective shard has), and periodically saved. This local cache should be an in memory database to increase response time (for calculating statistics).

Do you know of any tools/dbms to automatically achieve this "persitant-remote-inmemory-chache-backup behavior? Or do i have to implemnt it "manually", meaning write an api for my remote mysql database to pull and update the records, and write controller in my bot for populating and updating the in-memory database from/to my remote api?

short portal
#

ty for the help

quartz kindle
#

@viral spade you will probably have to set it up manually to fit your needs, but try using sqlite for a local process-specific database, and then flush it do the remote db once in a while

unkempt moon
#

Or use a time-series database like InfluxDB for the statistics data. That can easily handle statistics for 20k servers

#

Classic SQL databases are the worst for storing statistics of stuff 🤷

viral spade
#

ok thank you.
but i really wonder, is there no in-memory database system that 1 . is able to load from a remote disk in its own memory only the reocrds it needs and 2. has a persistance mode that is able to save the stuff back remotely automatically?

#

like many people must need something like this, no?

quartz kindle
#

only thing i can think of would be redis replication

unkempt moon
#

Time-series databases are good for your use case. I suggest you look at those

#

They're optimized for that

quartz kindle
#

and yes, many people need something like that, but that is something that is very implementation-specific, and should mostly be done manually

viral spade
#

i see.
that redis replication looks interesting and sounds like what i was looking for.
I will still do it manually,, thank you

#

so you would suggest sqlite for this?
will i be able to use all my mysql sql statements with sqlite just the same?

split hazel
#

Whenever I boot the bot & shards, i always get cannot read property emoji of undefined and then the shards crash, and pm2 reboots them and the cycle continues, from my message reaction add event file, it seems that my raw event isn't working on master, can someone take a look? https://hasteb.in/nacayito.js

quartz kindle
#

are you sure the error is coming from there? not sure why would you be receiving an empty packet

#

if you're sure the problem is there, you could just add if(!packet.d) { console.log(packet); return; }

#

that will stop the errors and give you some info about the packet to maybe find out why its empty

split hazel
#

I'll try that

lusty dew
#

Isn’t zlib-sync supposed to help make your cpu and meh usage go down?

#

Mem*

quartz kindle
#

cpu yes, mem no

lusty dew
#

Oh

#

Okay well someone told me to just install it and it should work is that the?

#

True*

split hazel
#

After the emoji error I got

#

{ t: null, s: null, op: 11, d: null }������

#

after logging packet

#

if packet.d is missing

quartz kindle
#

op code 11 is a heartbeat

#

so they are passing through your filter for some reason

lusty dew
#

Do I just install zlib-sync and it will work?

#

Or do I have to do some stuff coding wise

quartz kindle
#

you just need to restart your bot in most cases

#

unless you use a process manager like pm2

lusty dew
#

Yea I use pm2

#

And it made my cpu go up

#

Not down

quartz kindle
#

then do pm2 delete yourbot

#

and pm2 start yourbot.js

lusty dew
#

Okay

split hazel
#

oh i think it logged the heartbeat because i put the logging before the if packet contains messagereactionadd stuff

lusty dew
#

Rn it’s at 5.5% cpu

#

That will change for sure tho

quartz kindle
#

5% sounds normal

lusty dew
#

Ye

quartz kindle
#

mine is also at 5% with zlib, and 10-20% without zlib lul

sinful lotus
#

I run 15k guilds in single shard

#

without zlib sync I get 200-400% CPU Usage

quartz kindle
#

lmao

sinful lotus
#

with zlib-sync its 20%

lusty dew
#

Before it was at like 20 then when I installed zlib it jumped up to 60% now it’s down to 5%

#

A lot of jumping around eh

topaz fjord
#

@sinful lotus single shard ZoomEyes

quartz kindle
#

internal sharding

lusty dew
#

How does that work

sinful lotus
#

yes single process multiple ws shard

lusty dew
#

Ah okay

sinful lotus
lusty dew
#

Doesn’t sharing have an auto feature?

quartz kindle
#

1gb at 15k guilds is nice

lusty dew
#

I’ve seen stuff like shardCount: 'auto'

sinful lotus
#

my ws shards is auto

quartz kindle
#

yes, the auto option will fetch recommended shards

sinful lotus
#

I only specify my process

lusty dew
#

Someone told me actually 2-3 people told me auto wasn’t an option Thonk

sinful lotus
#

or just dont specify at all

#

ez

topaz fjord
#

I need to figure out how much my java bot is taking 👀

#

I recently rewrote

sinful lotus
#

I never rewrote

#

and my code eat that much already

#

haha yes

lusty dew
#

Is there a way to cut down on mem usage?

quartz kindle
#

yes

#

you have to control your caches

sinful lotus
#

use references without making it leak most of the time

#

and control caches as well

lusty dew
#

Actually is 100+mb normal for a bot in 19 servers?

sinful lotus
#

just d.js stuff

quartz kindle
#

yes

lusty dew
#

Okay

sinful lotus
#

specially if your bot is in here

lusty dew
#

I don’t think it is

quartz kindle
#

the node process itself will use 50-60mb

lusty dew
#

If it is my bot would be writing a lot of db entries rn and it’s break

#

It'd

sinful lotus
#

sqlite + lots of write is not a good thing

#

assuming you use sqlite

lusty dew
#

I have to use a separate website for hosting my mongodb

sinful lotus
#

then thats should be fine

lusty dew
#

Cause my friend doesn’t use mongodb so he doesn’t have a mongodb server running on his service

#

But that website only allows me to have 500mb and that’s it

quartz kindle
#

500mb is more than enough in most cases

#

unless you store files or images

#

my bot uses about 4mb for user/guild configuration and 600mb for images lol

lusty dew
#

The user collections if I ever get it working may become a problem in the future

#

Rn userData isn’t being written which is fine for now cause I’m not doing anything userwise Rn

#

Also my next question is how do I control caches?

split hazel
#

nothing gets logged @quartz kindle
this is the full error

0|shards   |     at module.exports (/root/events/messageReactionAdd.js![16](https://cdn.discordapp.com/emojis/521069903785099264.webp?size=128 "16")16)
0|shards   |     at Client.emit (events.js:198:13)
0|shards   |     at channel.messages.fetch.then.message (/root/events/raw.js![18](https://cdn.discordapp.com/emojis/535151786432921600.webp?size=128 "18")20)
0|shards   |     at process._tickCallback (internal/process/next_tick.js![68](https://cdn.discordapp.com/emojis/521069904602988593.webp?size=128 "68")7)
0|shards   | (node:8879) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)0|shards   | (node:8879) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emoji' of undefined
0|shards   |     at module.exports (/root/events/messageReactionAdd.js![16](https://cdn.discordapp.com/emojis/521069903785099264.webp?size=128 "16")16)
0|shards   |     at Client.emit (events.js:198:13)
0|shards   |     at channel.messages.fetch.then.message (/root/events/raw.js![18](https://cdn.discordapp.com/emojis/535151786432921600.webp?size=128 "18")20)
0|shards   |     at process._tickCallback (internal/process/next_tick.js![68](https://cdn.discordapp.com/emojis/521069904602988593.webp?size=128 "68")7)
0|shards   | (node:8879) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)```
quartz kindle
#

either sweep them regularly or prevent unneeded caching. the former is easy to do, the latter not so easy

lusty dew
#

I don’t know how to do that lol

quartz kindle
#

are you using master or stable?

lusty dew
#

master

quartz kindle
#

@split hazel is messageReadtionAdd.js the file you posted earlier?

split hazel
#

Nope, that was the raw.js file

#

or event shall i say

#

what confuses me is the same exact code works correctly on a test bot thats on glitch

quartz kindle
#

@lusty dew master has several different caches, such as client.users, client.channels, client.guilds, but most importantly, each guild has several caches itself such as guild.members, guild.presences, guild.roles, guild.emojis, etc...

#

all of those can be cleaned regularly to free up memory, specially if you dont use them in the first place

split hazel
#

line 16 in messsageReactionAdd is

#

if(reaction.emoji.name !== "🎁") return;

#

and using module.exports = async (client. reaction, user) => {

quartz kindle
#

then you're getting an undefined reaction

#

for some reason

split hazel
#

how would that possibly happen

#

it works correctly on glitch, which has the same code

#

on a test bot thats in like 2 servers

lusty dew
#

@quartz kindle I don’t know how to do that, that’s my problem

#

I’ve never worked with caches didn’t know that you could reduce mem usage by cleaning caches until a few minutes ago lol

quartz kindle
#

@lusty dew all collections have a sweep function

#

<collection>.sweep(function)

#

so you can do client.users.sweep(function to decide what to sweep and what not to sweep)

#

the function works the same way as any other iterator, like you would use in a .map or something

#

or a .find

lusty dew
#

Would I have to do that for every cache?

quartz kindle
#

yes

lusty dew
#

Like I mean you said guild has multiple

#

Would I have to do it for each guild caches?

quartz kindle
#

yes

#

for example, this is something i tested before

#
guild.channels.clear();
guild.members.clear();
guild.roles.clear();
guild.voiceStates.clear();
guild.presences.clear();
guild.emojis.clear();```
#

assuming you dont need to use any of that content

lusty dew
#

I don’t think I do

#

No wait voice states I do iirc

carmine echo
#

is it ok to send a user a dm once they've voted?

#

Even if they haven't interacted with the bot in the past

lusty dew
#

Lava link uses voice states at some point or I think I do I can’t remember what I used in all my music commands

quartz kindle
#

you have to make a lot of tests

#

because sometimes you might need something that you're not aware you do

#

for example if you use members, or set roles

#

and in most cases you will also need channels

#

presences is usually what most people complain uses a lot of memory and not a lot of people need it

lusty dew
#

I use members and set roles

#

And I mess with channels a lot but idk if it counts as like message.channel.send?

quartz kindle
#

yes it does

lusty dew
#

Okay so I shouldn’t sweep channels members or roles?

quartz kindle
#

if you need something you deleted, you need to re-fetch it when you need it

#

for example, if you delete channels, then you need to send a message to a channel

#

you can do this

#
let channel = client.channels.get(id) || client.channels.fetch(id)```
lusty dew
#

Ah mk

#

I’m trying to process this all lol

quartz kindle
#

another good idea is to not clear stuff that has been used recently

#

for example .clear() clears everything, but .sweep() only clears what you specify in the function

#

you can for example clear users that havent sent a message in a while

#

by comparing lastmessage timestamps

lusty dew
#

O.o okay

quartz kindle
#

i had a more complete example somewhere, let me find it

#
    let OLD_SNOWFLAKE = Discord.SnowflakeUtil.generate(Date.now() - 3600000);
    for(let guild of client.guilds.values()) {
        guild.channels.sweep(t => t.type !== "text" && t.type !== "dm");
        guild.members.sweep(t => t.id !== guild.me.id && (!t.lastMessageID || t.lastMessageID < OLD_SNOWFLAKE));
        guild.roles.sweep(t => t !== guild.id);
        guild.voiceStates.clear();
        guild.presences.clear();
        guild.emojis.clear();
    }
    client.channels.sweep(t => t.type !== "text" && t.type !== "dm");
    client.users.sweep(t => t.id !== client.user.id && (!t.lastMessageID || t.lastMessageID < OLD_SNOWFLAKE));
    for(let channel of client.channels.values()) {
        if(channel.permissionOverwrites) {
            channel.permissionOverwrites.clear();
        }
    }```
#

clear channels that are not text or dm channels

#

clear members and users that havent sent a message in the last hour

#

and some other stuff

#

but for each of those, you need to test how it impacts your bot, and make corrections if needed

#

so implement those carefully, one by one

lusty dew
#

How would I test?

quartz kindle
#

@carmine echo should be ok i think

#

@lusty dew use your bot normally and see if and where it crashes lul

carmine echo
#

That's good thanks

lusty dew
#

Oof Okay xD

#

I’ll look into that later rn I think everything is fine how it is thanks for teaching me how to do this though!

split hazel
#

when trying to login to my main bot through the working test bot on glitch i get


(node:1185) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.

    at Timeout.setTimeout [as _onTimeout] (/rbd/pnpm-volume/e0893195-5421-40b1-bc2f-fb899ad367c3/node_modules/.github.com/discordjs/discord.js/d14db521585f2b6b1a6c50d3a9acecc73bea25a3/node_modules/discord.js/src/sharding/Shard.js:137:31)

    at ontimeout (timers.js:436:11)

    at tryOnTimeout (timers.js:300:5)

    at listOnTimeout (timers.js:263:5)

    at Timer.processTimers (timers.js:223:10)

(node:1185) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:1185) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


The app exceeded the memory limit. Stopping and pausing for 15 seconds.

lusty dew
#

Glitch oof

#

Glitch bad boi

quartz kindle
#

app exceeded memory limit

#

lol

split hazel
#

yeah i knew that would happen i just tried to see if at least 1 shard managed to go online before the memory limit

quartz kindle
#

how many guilds are you running on again?

split hazel
#

3.2k

quartz kindle
#

hmm

lusty dew
#

What’s the guild limit before you need to start sharding?

quartz kindle
#

2.5

split hazel
#

k

lusty dew
#

Okay

split hazel
#

its strange how the test bot works fine

lusty dew
#

Anyway I can automate sharding for when it reaches that limit to start sharding?

split hazel
#

yeah d.js will spawn the recommended shards

topaz fjord
#

Yes

lusty dew
#

Might as well get the code over with instead of having to worry about it later

topaz fjord
#

You can also post to the discord API to see what they recommend

split hazel
#

im still trying to realise why my reaction objects are coming back empty

lusty dew
#

Wait couldn’t I just do this:

client = new Discord.Client({shardCount: 'auto'})

#

Or smth

topaz fjord
#

no

lusty dew
#

Hm

quartz kindle
topaz fjord
lusty dew
#

Mk

quartz kindle
#

put the packet type comparison inside the reaction check

onyx summit
#

I think he is on master

lusty dew
#

Yep

#

Was just about to say that

onyx summit
#

Ye then that works

quartz kindle
#
if(reaction){
    reaction.users.set();
    if(packet.t === ...) {}
    else if(packet.t === ...) {}
}```
lusty dew
#

Also nice pfp

split hazel
#

inside the event file?

#

raw.js

quartz kindle
#

yes, the way it is right now, you're still sending the reaction event even if there is no reaction

#

so you get an empty reaction on the event listener

split hazel
#

ahh that would make sense

#

since the bot is constantly receiving reaction packets all the time from the 3.2k guilds

#

or other packets

quartz kindle
#

welp ig2gnow

lusty dew
#

Can’t you sweep messages with the sweepMessage method?

#

Jkjk

#

But does it sweep old messages or new messages?

onyx summit
#

You have to pass a lifetime

lusty dew
#

Ah mk

onyx summit
#

In seconds, and messages that are older than this get removed

lusty dew
#

Trying to find ways of reducing mem usage seems like clearing caches is the only good way?

onyx summit
#

like client.sweepMessages(100) will sweep all messages that are older than 100 sec

#

You can pass some stuff in the client constructor

#

so your bot caches less messages

lusty dew
#

Wym

onyx summit
#

Gimme 10 sec to turn on my pc

lusty dew
#

Kk

pale marsh
#

Optimize your code a bit and make sure you don't have memory leaks as well

lusty dew
#

I haven’t noticed any memory leaks

onyx summit
#

your bigggest memory leak is lavalink anyway

lusty dew
#

Really?

onyx summit
#

not really a memory leak but it eats the most ram

lusty dew
#

Ah mk

#

Ye makes sense tbh

onyx summit
#
 const client = new BClient({
        shardCount: await Discord.Util.fetchRecommendedShards(process.env.BTOKEN, 500),
        presence: {
            status: 'idle',
            activity: {
                name: 'Shard Starting',
            },
        },
        messageCacheLifetime: 60,
        messageSweepInterval: 61,
        messageCacheMaxSize: 20,
    });

the part to cache less messages:

messageCacheLifetime: 60,
messageSweepInterval: 61,
messageCacheMaxSize: 20,
lusty dew
#

Ah so I can add that type of stuff in my client constructor to help reduce cached messages?

onyx summit
#

yeah, as the properties say

#

because d.js caches up to 200 Messages per channel

lusty dew
#

Damn

#

Why so many?

onyx summit
#

and e.g. my bot has 38 731 channels, meaning it could cache up to ~ 8 Million Messages

lusty dew
#

Woah

onyx summit
#

if my maths isnt shit (it is)

#

but I think thats right, 38731 channels * maximal 200 messages = 7.746.200 Messages

lusty dew
#

My bot only reads 433 channels lol

#

Okay well brb while I add in the message cache string

#

Thing*

#

How would I know if it’s working?

onyx summit
#

uhhh, you can eval in any channel (preferable #commands ) how many messages it has cached message.channel.messages.size

lusty dew
#

Okay

#

My bot isn’t even in here I don’t think

#

Okay nvm

#

Why did it not work earlier when I tried using I

#

It*

#

Hmph

onyx summit
#

change the prefix tho xD

lusty dew
#

Wym?

onyx summit
#

your bots prefix is -, and by running it in here a lot of bots will respond

#

so if you can, change its prefix in here

lusty dew
#

Ye

#

I can’t

#

I don’t have customizable prefixes yet

onyx summit
lusty dew
#

I was gonna add that today

#

So ima just do it in my support server?

onyx summit
#

ye

#

in an active channel

#

preferable

lusty dew
#

None of its active rip

#

Except for when me and the other dev talk I’m it

#

In*

#

Hm

#

@onyx summit should I just change the prefix globally?

#

👀

onyx summit
#

nah

lusty dew
#

But then that’d confuse a lot of people

#

Lol

onyx summit
#

I mean, you don't really have to care bout ram yet

lusty dew
#

I know but I wanna be prepared lol

onyx summit
#

my server is not really busy yet whom_the_phoque

lusty dew
#

Lol I just don’t want to cause problems for you

onyx summit
#

look at the dashboard it doesnt give a single fck

lusty dew
#

I don’t know how to add that btw

onyx summit
#

its on my github readme

lusty dew
#

Ah mk

#

Can’t you add that to dbl?