#development

1 messages Β· Page 1822 of 1

terse finch
#

i mean i can check for length, but if i pass in a properly formatted id, but it doesnt belong to a user or the user isnt in the server it should still fail

earnest phoenix
#

@terse finch are you checking if the id passed is the id of a member in the guild

terse finch
earnest phoenix
#

well

terse finch
#

basically !command <ID> <MESSAGE>

earnest phoenix
#

message.guild.members.cache.some(member => member.id === id);

vivid fulcrum
#

check if input string is all numbers and 17-20 characters long -> look up your user cache for that id -> if not found, make a REST request, if that returned 404 a user with that id doesn't exist

#

you can get users globally via REST

terse finch
#

cool good to know

earnest phoenix
#

they only want to see if the member exists in the guild

vivid fulcrum
#

oh

earnest phoenix
#

guild member cache is enough for that

terse finch
#

it would be useful later on if they just exist

vivid fulcrum
#

you can still use REST

terse finch
#

but for right now just existing in the guild is what i need

earnest phoenix
#

Use collection.some

vivid fulcrum
earnest phoenix
#

It takes a test function and returns true if any of the collection items passed the test

terse finch
#

ill keep both options in mind when i try it out

earnest phoenix
crystal wigeon
#

cry is ehere

#

@vivid fulcrum

crystal wigeon
#

pls

#

sorry for ping

vivid fulcrum
#

it's fine

earnest phoenix
#

Remember that the smallest ID length exposed to the API is 17 characters, the longest one being 18 characters

crystal wigeon
#

i need hekp

vivid fulcrum
#

what's up

crystal wigeon
#

grafana sqlite says permission denied, but i've given the perms

#

with chown

#

;-

#

on the same server

vivid fulcrum
#

i never used grafana

#

i think erwin uses it

crystal wigeon
#

lel

#

ahh

#

ping him

#

xd

earnest phoenix
#

DON'T

crystal wigeon
#

im dying from 4 hours

earnest phoenix
#

Pls don't

#

DETRITUS SUX

crystal wigeon
#

he helped me before

#

all good

#

xd

earnest phoenix
#

He's gonna go full Detritus mode

#

now you can ping em

crystal wigeon
#

lol idk which erwin tho

#

he had zero two as his profile pic before

earnest phoenix
#

the not Erwin guy

crystal wigeon
#

ye cant find

earnest phoenix
#

Not Erwin#8753

#

discord searchbar never fails to give me the correct guy

crystal wigeon
#

@fervent carbon

#

lol

#

he left

#

the

#

sadge

earnest phoenix
#

@opal plank

#

oh f it worked

#

brace yourself for a tidal wave of detritus

crystal wigeon
#

uwu

#

orai

#

he here

#

erwin

#

help

#

;-;

#

@opal plank

#

sorry for ping

earnest phoenix
#

wtf

crystal wigeon
#

it keeps throwing this error

#

and on the server i have given grafana user the ownership of the dir

#

;-;

earnest phoenix
#

the file is in /root

crystal wigeon
#

yeah

earnest phoenix
#

maybe that's the problem

crystal wigeon
#

it needs /root/

#

if i remove root it says it cant find the dir

#

it needs an absolute path

earnest phoenix
#

literally
move the dir to / instead of /root

crystal wigeon
#

No file found at: '/izzi/izzi-bot/json.sqlite'

#

No file found at: '/izzi/izzi-bot/'

#

i tried this also

#

i tried ~/ also

earnest phoenix
#

the izzi folder is inside root that's why it cant find it...

crystal wigeon
#

but it has the ownerhsip?

#

so i have to move to /home path?

earnest phoenix
#

yes

crystal wigeon
#

jesus

#

fkin

#

christ

#

it worked

#

fml

#

im domb

#

holy shet

#

you my boi

earnest phoenix
crystal wigeon
#

fr

#

man i feel stupid

earnest phoenix
#

man i feel powerful

crystal wigeon
#

uwu

earnest phoenix
#

remove perms for anyone to send messages there

#

Discord has private channels for that

#

Get onto a computer and goto the channel settings

#

In permissions you can toggle private channel mode

#

Only people/roles you allow can even see the channel

terse finch
earnest phoenix
crystal wigeon
#

so umm

#

code

#

xd

#

where you at brother

#

can i store multiple columns with quick.db? currently everything is just dumped at json

lyric mountain
#

you're storing json in quickdb?

earnest phoenix
#

does it ever happen you write a big project then you forget yourself hoe the fuck you made it

lyric mountain
#

resumed an old project?

crystal wigeon
#

true, happens

#

it basucally only has 2 props

#

id and data

#

qdb

lyric mountain
#
 id | data
-----------
  0 | aaa
  1 | bbb
  2 | ccc
crystal wigeon
lyric mountain
#

like this?

crystal wigeon
#

so anything stored in db it stores json or string

#

yah

#

i wanted more of id | col1 | col2

#

from qdb

lyric mountain
#

bruh

crystal wigeon
#

wondering if that's possible

lyric mountain
#

not only possible, but the way it should be happening

crystal wigeon
#

yeah

#

weird qdb

#

it only has id and data

lyric mountain
#

one doesn't simply use sql to store a single json column

#

that's illegal

crystal wigeon
#

πŸ˜‚

lyric mountain
#

my opinion? yeet qdb and move to an actual sql wrapper

#

I can't say how much performance and resources you're losing with that

crystal wigeon
#

yeah just tried qdb because it was lightweight

lyric mountain
#

actually, it's sqlite which is lightweight

crystal wigeon
#

also straight forward methods for what i was looking for

lyric mountain
#

sqlite is the lightest you can get and retain major sql features

#

tbf, almost all big tools use sqlite for settings storage

crystal wigeon
#

ig

#

the reason i dont want to use sequelize is that

#

im not using any of the features it provides

#

just want a basic set and fetch

#

which qdb was offering

#

lel

#

but this is just dumb

lyric mountain
#

it's better having more than needed than having less

#

also let you ever move on to a larger database like postgres sequelize allows seamless transition

crystal wigeon
#

ik, i already use postgres

lyric mountain
#

what wrapper you use?

crystal wigeon
#

knex and the pg-client itself for faster query

split hazel
#

pogres

#

sorry had to

#

carry on

crystal wigeon
#

ayy my man

lyric mountain
#

faster query is subjective

crystal wigeon
#

yeah

#

my queries are well optimized tho

#

to some level

#

still need more

lyric mountain
#

go with sequelize

crystal wigeon
#

optimzation

split hazel
#

thats what they all say

lyric mountain
#

it can work for both databases you use

#

so less packages

split hazel
#

sequelize doesn't exactly optimise your queries very well but you know

lyric mountain
#

better than using a lib that stores all table data in a json field

lyric mountain
#

sqlite is suffering

crystal wigeon
#

is there anything better than qdb? mariadb?

#

πŸ˜‚

lyric mountain
#

mariadb is a database

#

not a lib

split hazel
crystal wigeon
#

ah

#

aight, i'll switch to seq

#

thanq for da wae

#

lets go spit on qdb

#

jk

lyric mountain
#

I wonder how much bots use qdb

split hazel
#

no that's a terrible joke

#

lets actually do it

lyric mountain
#

I can only imagine how disgusting managing a big db with that is

#

let alone backup restores

crystal wigeon
#

its more like someone trolled us

split hazel
#

i used it once for a bot where i needed a quick database with no complex queries

crystal wigeon
#

big time

#

image suggesting qdb to newbie

#

and later he go ins shock

#

after finding out how the data must atually be stored

#

in db

#

lol

lyric mountain
#

like, you lose so many cool sql features that you're better off going straight to nosql

#

what is sql without inner joins and custom queries

split hazel
#

lol imagine using joins

crystal wigeon
#

imagine joining joins with qdb

#

:ayawoke:

lyric mountain
#

INNER JOIN other_table ot ON ot.data = t.data

#

at that moment, sql dies

split hazel
#

i dont like joins with sql

#

they dont feel right

#

i'd rather use something like mongo if i have an app that would heavily rely on getting data from other tables

lyric mountain
#

why don't they feel right?

split hazel
#

or i would just increase the amount of columns

lyric mountain
#

like, you're putting 2 tables side by side, you just need some identifier so you can estabilish a connection between both

split hazel
#

dont know they just feel unreliable/not very performant

lyric mountain
#

they're the exact opposite of that

split hazel
#

but then i've never used them lol

lyric mountain
#

for example, if you had a table user where each user can have N card, and each card having their own properties

#

how would you do it in a single table?

split hazel
#

card_name_1 card_name_2 card_name_3

#

jk

lyric mountain
#
table user
- id
- name

table user_card
- card_id
- user_id

table card
- id
- name
- color
- price
split hazel
#

yeah i get it but i just like keeping data relevant to that specific thing in one place

#

not spread them

lyric mountain
#

that's not about merely spreading, but allowing 1-N/N-1/N-N relationships

#

like, you can have many entities related to one table

#

or the reverse

#

without that you're stuck with 1 value per column

woeful pike
#

the word you're looking for is called a junction/pivot table btw

#

the table that allows you to do many to many relationships

quartz kindle
#

how often does an access pattern require accessing individual entries like that tho? most times you want to list the cards a certain user has, and when you want to get a specific card, most often you already have one of the ids to look up

lyric mountain
#

just an example, like consider you want to list all the cards the user has

#

you could obv do it with a lone query, I just couldn't think of an example

quartz kindle
#

thats what im saying

#

you could easily store all ids a user has as a serialized array for example

#

since you will most likely always be accessing them as a list, and not individually

#

the situation changes a bit if it becomes read-write heavy tho

uneven fulcrum
#

how do i get the votecount

lyric mountain
#

in my case it's indeed very RW heavy

#

since it's the main feature of my bot

gusty bone
#

I have a question about DigitalOcean

#

How many servers can a bot (on the lowest plan) handle if I host on DigitalOcean?

modest maple
#

that depends on the bot

gusty bone
#

What exactly do you mean?

#

Like what part of the bot is it dependent on

pale vessel
#

Check your bot memory usage too

modest maple
#

i mean it depends on the bot

#

your bot wont use the same resources as my bot shrug

gusty bone
#

True

#

But how can I get an estimate for myself

#

The bot's file size and memory usage?

pale vessel
#

File size shouldn't matter most of the time

uneven fulcrum
#

It was running out of ram

pale vessel
#

It's the CPU and memory I suppose

uneven fulcrum
#

So i switched to the $10 plan

modest maple
#

if you have presence enabled

#

you can expect it to be considerably lower count

#

compared to a bot that has it disabled

pale vessel
#

Depends if your bot does intensive work or caches everything

uneven fulcrum
#

btw how do i get the vote count]

#

monthly

modest maple
#

e.g. bot with no presence will have much lower cpu usage

uneven fulcrum
#

like vote.user

#

is there a way to get like vote.votecount?

pale vessel
#

If you want the monthly vote count use the bots endpoint

gusty bone
#

or "playing ..."

pale vessel
#

Not just those. Statuses, custom statuses, and activities included

gusty bone
#

Ok

pale vessel
#

You won't receive those events if you remove the GUILD_PRESENCES intent

#

If you have it in the first place

#

I don't think an economy bot needs it anyway

gusty bone
#

Im confused

#

Does presence in this context mean guild member presence or the presence on the bot?

pale vessel
#

Member presence

rose warren
#

Guild members

gusty bone
#

I c

pale vessel
#

@rose warren Congrats on BR (just noticed)

uneven fulcrum
rose warren
#

Thanks! 😊

gusty bone
#

My guild presence thing intent is off

uneven fulcrum
#

so would i do vote.monthlyPoints?

pale vessel
#

Yeah

uneven fulcrum
#

ok ty

quartz kindle
#

memory usage depends on a lot of factors

#

you can have a bot using 1gb ram with 100 servers or 100mb ram with 10k servers

rose warren
#

Tim why no lib dev role? πŸ‘€

quartz kindle
#

lib dev role is for top.gg libs afaik

rose warren
#

Ah probably πŸ˜…

uneven fulcrum
#

why does it return undefined

pale vessel
#

It's not in the webhook payload if that's where you're trying to get it from

#

It's on a whole another endpoint

uneven fulcrum
#

oh

#

so how do i get it?

pale vessel
#

There should be a method like getBot() in the lib, not sure

uneven fulcrum
#

ok

#

there is bot

pale vessel
#

If not you can always request it yourself

uneven fulcrum
#

ok

gusty bone
#

Bruh my powershell do be acting up today doe pepecry

proven lantern
#

does java have a way to freeze objects like Object.freeze in js?

#

private final immutable Map<> dontChangeMe = ...

#

found it Collections.unmodifiableMap(mutableMap);

inland pulsar
#

lol

lyric mountain
#

like, except for creating libs, is there an actual use-case to lock collections?

proven lantern
#

i wanted to do it in the signature of a function so the functions dont modify input

lyric mountain
#

ah, that

#

you could just do new HashMap(input) tho

#

or Map.copyOf(input)

#

the latter being unmodifiable

proven lantern
#

but someone could still go in an mutate the original parameter

lyric mountain
#

oh and don't forget state changes might be mirrored to the other map

proven lantern
#

a naughty person

lyric mountain
#

it's literally Collections.unmodifiableMap() but shorter

proven lantern
#

but the original map is still accessible

lyric mountain
#

Map.copyOf creates a new copy

proven lantern
#

because the signature of the request has it there

lyric mountain
#

and neither that or the Collections way prevent data change

proven lantern
#

so a naughty person wont use the copyt

lyric mountain
#

you're only locking map modification

#

not value modification

brave garnet
#

asap question - someone knows maybe a free api with random facts and jokes? using icanhazdadjoke breaks bot...
... due to swear lists

#

;-; pls...

#

;;;-;;;

gusty bone
#

Is it dangerous/bad/dumb to shard your bot when your bot is not in many servers?

brave garnet
#

this last, yea

brisk blade
#

Anyone can suggest a good bot hosting vps?

gusty bone
#

I heard about DigitalOcean

#

$5/month for their lowest plan

grim sundial
gusty bone
#

Also can anyone help me with this lol

grim sundial
#

code?

brisk blade
#

JavaScript, node.js

gusty bone
#

If i do process.cpuUsage it just crashes because it's bigger than 1024 or something

brave garnet
#

Again, a load of questions...

quartz kindle
gusty bone
#

Oh

quartz kindle
#

also cpuUsage.heapUsed doesnt exist

#

heap is for memory, not for cpu

gusty bone
#

Okay

quartz kindle
#

also cpuUsage does not give you what you think it does

gusty bone
#

Is there a property cpu thing?

gusty bone
quartz kindle
#

there is a way yes but its harder than you think

gusty bone
#

Oh

quartz kindle
#

also, you want the entire machine's cpu usage, or the bot's cpu usage?

grim sundial
#

im a little confused with something if anyonecan help

#
        if (Object.keys(this.client.messageChannel).length === 0) {
            this.request.getChannel(this.raw.channel_id).then((data) => {
                this.client.messageChannel = new TextChannel(data.data, this.client);
            });
            return this.client.messageChannel;
        } else {
            return this.client.messageChannel;
        }```i have this code ^^ and what it does is uh, i have to send a call the method twice for it to use run the `else` statement with the correct data.
gusty bone
#

But I'm using heroku so idk if machine works too

quartz kindle
grim sundial
#

like if this.client.messageChannel is an empty obj it should send the new TextChannel any ideas?

quartz kindle
#

you have to await the promise

grim sundial
grim sundial
quartz kindle
# brave garnet -_-

being mad wont make anyone answer you faster. if nobody answers its because we dont know because we dont use whatever you are using

grim sundial
#

oh oops that is only for chuck norris jokes lmao

quartz kindle
brave garnet
grim sundial
#
    get channel() {
        if (Object.keys(this.client.messageChannel).length === 0) {
            this.request.getChannel(this.raw.channel_id).then((data) => {
                this.client.messageChannel = new TextChannel(data.data, this.client);
            });
            return this.client.messageChannel;
        } else {
            return this.client.messageChannel;
        }
    }```
#

thats the full thing, i cant make it asynchronous

#

or am just stupid

quartz kindle
#

you have to make it a promise

grim sundial
#

yeah i tried wrapping it around in a Promise.resolve same thing

quartz kindle
#
get channel() {
  return this.client.messageChannel ? Promise.resolve(this.client.messageChannel) : this.request.getChannel(this.raw.channel_id).then(data => {
    return this.client.messageChannel = new TextChannel(data.data, this.client)
  })
}
grim sundial
#

i'll give it a try

gusty bone
#

For digitalocean, which one is used for discord bots? General Purpose Droplets or Basic Droplets

quartz kindle
#

basic is enough

#

general purpose is super expensive

gusty bone
#

Ohh

#

Thanks

grim sundial
quartz kindle
#

you're not returning it

#

also what do you mean with same thing

grim sundial
#

oh whoops

gusty bone
#

then it looks like maybe Galaxygate has better prices

quartz kindle
#

yes galaxygate is cheaper

gusty bone
#

Aight

grim sundial
#

yeh i misunderstood what u said

#

same thing, it errors then i have to send a message for it to like, work as intended

quartz kindle
#

did you change the caller to await it tho?

#

you have to await the getter

#

await something.channel

grim sundial
#

yeah

quartz kindle
#

if messageChannel exists, you return Promise.resolve(messageChannel) so the getter reads it as a promise

#

if it doesnt exist, you have to return getChannel itself

#

so that the caller awaits getChannel

#

and gets whatever result getChannel returns once its resolved

grim sundial
#

so, js if (Object.keys(this.client.messageChannel).length === 0) { return Promise.resolve( this.request.getChannel(this.raw.channel_id).then((data) => { this.client.messageChannel = new TextChannel(data.data, this.client); }) ); } else { return this.client.messageChannel; }

#

and im calling it by: await message.channel

quartz kindle
#

Promise.resolve is for messageChannel. not for getChannel

#

for getChannel you just return it directly since its already a promise

#

and you have to return inside the then as well

#

otherwise it returns undefined after setting the value

#

or just remove the brackets to make an implicit return

grim sundial
#

im a bit confused, because messageChannel has to be ran if getChannel is called

#

so

quartz kindle
#

getChannel is a promise, correct?

#

its an async function

grim sundial
#

so from whay you've said, this is what i've came up with:```js
if (Object.keys(this.client.messageChannel).length === 0) {
return this.request.getChannel(this.raw.channel_id).then((data) => {
Promise.resolve((this.client.messageChannel = new TextChannel(data.data, this.client)));
});
}

    return this.client.messageChannel;```
quartz kindle
#

Promise.resolve is if messageChannel already exists

#

you dont need it inside the then

grim sundial
#

oh

#

so i've got this: ```js
if (Object.keys(this.client.messageChannel).length === 0) {
return this.request.getChannel(this.raw.channel_id).then((data) => {
this.client.messageChannel = new TextChannel(data.data, this.client);
});
}

    return Promise.resolve(this.client.messageChannel)``` lets see if it work
#

nein

quartz kindle
#
let p = new Promise(resolve => 10);

console.log(await p) // 10
console.log(await p.then(data => { data + 5 })) // undefined (no return)
console.log(await p.then(data => { return data + 5 })) // 15 (explicit return)
console.log(await p.then(data => data + 5)) // 15 (implicit return)
#

awaiting a promise that has a .then() attached to it will return the result returned inside the .then()

grim sundial
#

btw

#

how can i like

#

combat all this without having to even have an await there

#

so its just channel.something not await channel.something

quartz kindle
#

you cant

grim sundial
#

oh

grim sundial
#

so im a bit confused, because it still makes me call the method twice before actually like lets me access TextChannel

#

if that makes sense

quartz kindle
#

did you add the return inside the then?

grim sundial
#

i deleted it by accident

#

whoops

#

same thing, this is the code btw

#
        if (Object.keys(this.client.messageChannel).length === 0) {
            return this.request.getChannel(this.raw.channel_id).then((data) => {
                return (this.client.messageChannel = new TextChannel(data.data, this.client));
            });
        }
      return Promise.resolve(this.client.messageChannel);```
quartz kindle
#

did you console.log the getter?

grim sundial
#

and it errors basically saying its just an empty object

quartz kindle
#

show the code that calls the getter

grim sundial
#
await message.channel.createMessage();
quartz kindle
#

thats the problem

grim sundial
#

yeah i tried mesasge.channel.then

quartz kindle
#

(await message.channel).createMessage()

grim sundial
#

same thi- oih

quartz kindle
#

otherwise you are awaiting promise.createMessage instead of awaiting promise

grim sundial
#

oh yeah true

quartz kindle
#

would probably be a good idea to not use a getter here, to not confuse yourself

#

just make it a normal async method

grim sundial
#

but then i'll have to do message.channel().createMesasge wont i?

#

and it wont like, look nice idk

quartz kindle
#
const channel = await message.getChannel();
channel.createMessage();
#

i'd do it like that

pale vessel
#

Java

grim sundial
#

hm, alright. thank

#

one last question

#

quick tho

#

is there a better way to get the current channels data rather than making an api call?

pale vessel
#

Nope

#

Other than fetching the guilds channels once and cache them

grim sundial
#

yeah but i dont get how caching would work in this sense

#

oh u edited

grim sundial
pale vessel
#

You save them to an object/map and get it from that

grim sundial
#

yeah but i would have to get the id somehow to compare it to or something

pale vessel
#

message.channel_id?

quartz kindle
#

if you dont have the current channel data stored anywhere, then fetching it is the only way. you can then save it somewhere to avoid re-feching later

latent heron
#

@earnest phoenix what do you think of this?

grim sundial
pale vessel
#

Yeah it would change

quartz kindle
#

just create a map to store channels in

#

and get them from the map

grim sundial
#

i still dont get it tho, cuz how am i supposed to get a specific channel from an array of channels

pale vessel
#

But you have all the channels cached

#

You store all channels

grim sundial
#

yeah and how do i know which is the current channel

pale vessel
#

Find the channel by ID that matches message.channel_id

grim sundial
#

oh yeah

#

alr

quartz kindle
#
if(channelMap.has(channel_id)) {
  return channelMap.get(channel_id)
} else {
  const data = await request.getChannel(channel_id);
  const channel = new TextChannel(data);
  channelMap.set(channel_id, channel);
  return channel;
}
grim sundial
#

hm

#

i got an idea, it'd be caching everything upon connect

#

but it'd be a pain to send all that data across

pale vessel
#

That's what I said

grim sundial
#

oh

pale vessel
robust fern
#

Hello citizens of Top.gg, I am needing assistance with my Bot on Discord made from Discord.js. My issue with the Discord bot is the guildMemberAdd isn't working. I had it console.log random letters, but it doesn't log them. And my brains dying. Help πŸ‘

#

a ha i did it

#

wait no

#

it sounds like i fixd it

#

i didnt

#

i swear

errant flax
#

how do i wait for the next iteration?

#

in a for loop

errant flax
#

has*

robust fern
#

o ping

#

wut intents

vagrant sedge
#

i think

robust fern
#

already on

vagrant sedge
robust fern
#

js

#

not pie

wheat mesa
#

you need the GUILD_MEMBERS intent

robust fern
#

wus dat

vagrant sedge
#

wait wrong server

robust fern
#

get it right sauce fish

#

lmayo

robust fern
#

how do i intent the gild membrs

wheat mesa
robust fern
#

ok

#

i am going to do the intenting

errant flax
#
new Client({
ws: {
intents: ["GUILDS","GUILD_MESSAGES","GUILD_MEMBER_ADD"]
}
})
robust fern
#

brains to small for that

vagrant sedge
#

you have to tho

robust fern
#

na ill just remove welcoming ppl

#

problem solved πŸ‘

vagrant sedge
#

bro

#

its not that hard

errant flax
#

bruh just read the guide and ull be ok in no time

vagrant sedge
#

just put in an extra line

wheat mesa
#

it's VERY easy to do

errant flax
#

how do i wait for the next iteration??

#

in a loop

wheat mesa
#

throw the for loop in an async function and await whatever it is you're waiting for

vagrant sedge
#

is there a specific database i should use for storing server configs for a bot? i was thinking of just using a json to store everything

robust fern
#

wa

#

sigh ill add the intents

errant flax
vagrant sedge
errant flax
#

bruh chill misosface

vagrant sedge
wheat mesa
#

or you can do this witchcraft which I believe functions the way you'd like: ```js
const myFunc = async () => {
for await(let blah of blahblah) {
// Cool stuff
}
}

earnest phoenix
#

its okay

errant flax
#

using json as db is bad

vagrant sedge
#

why?

earnest phoenix
errant flax
#

just use mongodb pd_pepethumbsup

earnest phoenix
#

but for bigger ones you should use an actual db

vagrant sedge
earnest phoenix
#

like if you are planning to be in like hundreds

#

of stuff

wheat mesa
#

json is not good to use as a db if it's read/written to a lot

robust fern
wheat mesa
#

...

vagrant sedge
#

are you importing a Client from the discord.js library?

wheat mesa
#

Do you understand what typing new Client does..?

vagrant sedge
#

idk how imports work in js

robust fern
#

lmfayo

vagrant sedge
#

but i assume there's a way that you require Client from "discord.js" or something

robust fern
#

tbh idk wut im doing at this point

vagrant sedge
robust fern
#

na im using bot

#

lol

wheat mesa
#

it's usually ```js
const { Client } = require('discord.js');

earnest phoenix
wheat mesa
#

or es6 syntax as ```js
import { Client } from 'discord.js'

errant flax
#

define

robust fern
#

My wifi just died but im back

errant flax
#

shit

quartz kindle
#

yes, decline your client

earnest phoenix
#

yes, decline your client

wheat mesa
#

decline it

robust fern
#

I want to make a deez nuts joke but i also dont

earnest phoenix
#

decline deez nuts lolz

vagrant sedge
#

wait wtf mongodb is cloud based

earnest phoenix
#

good

vagrant sedge
#

is storing locally bad?

quartz kindle
earnest phoenix
#

its not bad

#

it really is up to you and your needs

quartz kindle
#

locally hosted database is better in all situations except 1: when you actually need to access it from multiple severs

errant flax
#

whats a local hosted db

quartz kindle
#

a db that you install and run on your server

#

alongside your programs/bots/websites

robust fern
#

My wifi is aliving

quartz kindle
#

did it dieded?

errant flax
#

aliving m_keklaugh

robust fern
#

yes

#

sigh now im getting flag and number errors bc of sauce fish

earnest phoenix
#

here we go blaming sauce fish for you not knowing your code

vagrant sedge
#

what the fuck did i do

wheat mesa
#

Perhaps you should show your code instead of giving us errors without context...

robust fern
#

lmayo

#

na

earnest phoenix
robust fern
#

everything

#

k it works now bye

#

πŸ‘

#

sos fish bad codr

wheat mesa
#

I suppose that this might be relevant

robust fern
#

no

earnest phoenix
#

LOL

robust fern
#

dang

#

box logo

earnest phoenix
robust fern
#

how do i save

earnest phoenix
#

I don't know

#

you can always ss

robust fern
#

troo

wheat mesa
#

It's a sticker, not sure if you can even save it

earnest phoenix
#

dfsfs

robust fern
#

i just bit the orange part of my orange

quartz kindle
#

wdym you cant save it

robust fern
#

tastes bad

quartz kindle
robust fern
#

what the hec

#

gime

quartz kindle
robust fern
#

mine

wheat mesa
quartz kindle
#

im on the browser version

robust fern
#

woah

quartz kindle
#

with chrome extensions to preview/zoom images on hover

earnest phoenix
wheat mesa
#

doesn't seem to work for me either

lyric mountain
#

You can't drag stickers

#

But you can simply open devtools, inspect element and grab the url

latent heron
#

Does anyone here have experiencing with using python's ConfigParser module for writing configuration files?

pure lily
#

I spawned 2 shards and if you send a command to one server and go to another server with same shard the cooldown applies. How do I fix this?

quartz kindle
#

you want the cooldown to apply or you dont want the cooldown to apply?

crystal furnace
#
const Discord = require("discord.js");

module.exports.run = async (bot, message, args, god) => {



 
  const promises = [
    
    bot.shard.fetchClientValues('guilds.cache.size')

   ];
  
  Promise.all(promises)
    .then(results => {
 
      const totalGuilds = results[0].reduce((acc, guildCount) => acc + guildCount, 0);





    let string = '';
    totalGuilds.filter(g => g.memberCount>1).forEach(a => {
      string += `Server: ${a.name} - ${a.memberCount} members` + '\n'
    })```
#

TypeError: totalGuilds.filter is not a function

quartz kindle
#

totalGuilds is not an array

#

its a number

crystal furnace
#

Sharding cause a lots of problem

split hazel
#

according to this you are adding the number of guilds each shard has together

#

pretty sure this is not what you want according to the bottom

proven lantern
#

what is results[0]

crystal furnace
split hazel
#

results 0 is the response from the first shard which is a number

proven lantern
#

like this?
[{guildCount:4, memberCount:19},{guildCount:10, memberCount:41}]

crystal furnace
quartz kindle
#

its a promise for fetchClientValues(guilds.size)

#

results[0] should be [size, size]

split hazel
#

i think you're both confused

crystal furnace
quartz kindle
#

no

#

you have the correct code for total number of guilds

#

but you cannot use that for total number of members

#

you need another promise for that

crystal furnace
quartz kindle
#

yes, you need the broadcastEval version

split hazel
#

the code for what you want to do is literally here

crystal furnace
#

Like this

quartz kindle
#

and here

#

if you want to keep the individual counts, then you need to do it differently

crystal furnace
#

Sharding make problem more difficult

quartz kindle
#
const allGulds = await broadcastEval(`this.guilds.cache.map(g => ({name: g.name, memberCount: g.memberCount}))`);
const guilds = allGuilds.flat();
crystal furnace
quartz kindle
#

[[1,2,3],[4,5,6]].flat() = [1,2,3,4,5,6]

crystal furnace
#
const promises = [
    
   bot.shard.fetchClientValues('guilds.cache.size')

   ];
  
  Promise.all(promises)
    .then(results => {
 
      const totalGuilds = results[0].reduce((acc, guildCount) => acc + guildCount, 0);

So I need to delete this first ?

#

oh

quartz kindle
#

yes you can delete that

crystal furnace
#

you are best Tim

#

I should to ask you eailier

#

Can you add friend with me ?

split hazel
#

this is where you say yes

lyric mountain
#

Well...define ur variables

crystal furnace
#
        const allGuilds1 = await bot.shard.broadcastEval(`this.guilds.cache.map(m => ({name: m.name, memberCount: m.memberCount}))`);
        const guilds1 = allGuilds1.flat();
  
    let botembed = new Discord.MessageEmbed()
        .setColor("#000FF")
        .addField("Special greatful to these servers (>1000members)", string)
        .addField('Bot stats',`\`\`\`css
Total: ${guilds1}
Total: ${guilds1.filter(m => m.memberCount > 100000).size} Servers (>100000 members)
Total: ${guilds1.filter(m => m.memberCount > 10000).size} Servers (>10000 members)
Total: ${guilds1.filter(m => m.memberCount > 5000).size} Servers (>5000 members)
Total: ${guilds1.filter(m => m.memberCount > 1000).size} Servers (>1000 members)
Total: ${guilds1.filter(m => m.memberCount > 500).size} Servers (>500 members)
Total: ${guilds1.filter(m => m.memberCount > 100).size} Servers (>100 members)
Total: ${guilds1.filter(m => m.memberCount > 50).size} Servers (>50 members)\`\`\`\ `,)
.setTimestamp()
        .setFooter("Command Used By: " + message.author.username, message.author.avatarURL);
    message.channel.send(botembed);
       
}```
crystal furnace
lyric mountain
#

Errr....

crystal furnace
#

hmm i think i know a problem

lyric mountain
#

You can't flat it that way

#

You have 2 properties for each, name and count

crystal furnace
lyric mountain
#

Map it to a single property per object

#

Only then flat

crystal furnace
#

I think i am confusing myself

lyric mountain
#

You have name and member count for each guild

#

How would you flat that?

#

You don't, because you can't mix it at all

crystal furnace
#

@lyric mountain

#

will it work ?

lyric mountain
crystal furnace
#

TypeError: results.reduce(...).filter is not a function

#

because it is a number

#

=)))

lyric mountain
#

You probably can't reduce an object directly

crystal furnace
#

so it can't fitler

lyric mountain
#

You can

#

Just get the values

#

And you have an array

#

Object.values(obj)

crystal furnace
#

I am done a little

#
let results = await bot.shard.fetchClientValues('guilds.cache.size')
const allGuilds1 = await bot.shard.fetchClientValues('guilds.cache.size')
const guilds1 = allGuilds1.flat();
guilds1.filter(g => g.memberCount>1)
  
    let botembed = new Discord.MessageEmbed()
        .setColor("#000FF")
        .addField("Special greatful to these servers (>1000members)", string)
        .addField('Bot stats',`\`\`\`css
Total: ${results.reduce((acc, guildCount) => acc + guildCount, 0)}
Total: ${guilds1} (>1 members)```
#

reduce flat with ?

terse finch
#

might be a dumb question but does anyone know why my <Guild>.members.fetch() is just pending a promise? it worked earlier today, and now its just indefinately pending.

crystal furnace
#

how to make it [ n, n ] = [2n] >

#

?

lyric mountain
#

Btw, did you state somewhere that your bot will publicly show the server names?

#

Like, that mighty cause privacy concerns

crystal furnace
wheat mesa
#

It is

crystal furnace
#

no

lyric mountain
#

Not all servers are public

crystal furnace
#

it just a test bot

crystal furnace
terse finch
#

discord.js - might be a dumb question but does anyone know why my <Guild>.members.fetch() is just pending a promise? it worked earlier today, and now its just indefinately pending.

#

well it stays unresolved till it gets timed out

lyric mountain
earnest phoenix
lyric mountain
#

Or use async callbacks

earnest phoenix
#

What would I put here

terse finch
#

its just not getting resolved.

lyric mountain
#

What are you trying to do?

terse finch
#
const member = await message.guild.members.fetch(true)
#

this

#

inside an async function

lyric mountain
#

That's...oh my

#

Fetch doesn't work like that

terse finch
#

you sure? it worked like 2 hours ago when i first wrote it lol

lyric mountain
#

Ye, you fetch for an specific id

terse finch
#

i need to check an ID against all possible guild ids to see if its a guildmember in the current guild

lyric mountain
#

Why?

#

Just fetch for the id in the current guild

#

If the user is in it it'll return a result

terse finch
#

i need a cacheable version of all members.

lyric mountain
#

You shouldn't cache all members in all guilds

terse finch
#

cause i dont wanna have to check each id thats passed in with a guild lookup when the command runs

crystal furnace
#

finally

#

yay

lyric mountain
#

Nice

earnest phoenix
#

What exactly are they trying to do

terse finch
#

i have a collection of ids, need to be checked against all guild member ids, and then mark any outliers

earnest phoenix
#

and why are they using true in fetch

lyric mountain
#

Just beware the privacy stuff

terse finch
#

doesnt work either way

earnest phoenix
#

well

#

I doubt you can just do true

#

and it will work

terse finch
#

same but it never hurts to try

lyric mountain
#

Just a note, you're limited on how many fetches you can do in a given time frame

earnest phoenix
#

Also with fetch don't you need to enable partials?

terse finch
#

i dont want to have to check each ID in the collection against a lookup call for guild.fetch(), hence why im trying to fetch all and compare the objects

earnest phoenix
#

But you are fetching all the members for the current guild the message is being sent in...

terse finch
lyric mountain
#

Except you don't need to

#

Most libs will cache users when necessary

#

Like when they send a message, get mentioned, joins guild, etc

#

Those don't generate fetches

crystal furnace
#

how to add , between number

#

like 100000

#

to 100,000

#

I forgot the method

terse finch
#
const member = await message.guild.members.fetch(Discord_id)
//Other stuff here
  if(member.get(Discord_id)) {
    const User = member.get(Discord_id).user.username
    const Server = member.get(Discord_id).guild.name
    //other stuff

heres what i need. if i dont fetch all and fetch by id, how do i prevent getting limited if im running this on multiple servers with alot of people daily

terse finch
#

i can use member.id or member.username. but i need like 100 of these at a time. which is why it makes sense to fetch all the ones i need at once, and compare. 1 request vs 100 requests in a short time frame.

#

does that help explain it? or is this just not possible?

#

ya know im to tired for this atm. it 1130pm, ill work on it when im not tired. if you guys can think of anything let me know

lyric mountain
crystal furnace
crystal furnace
# lyric mountain toLocaleString
let CPU = Number(Math.round((await new Promise(async r => {
  let start = [process.hrtime(),process.cpuUsage()];
  await new Promise(r => setTimeout(() => r(),100));
  let elap = [process.hrtime(start[0]),process.cpuUsage(start[1])];
  r(100.0 * ((elap[1].user / 1000) + (elap[1].system / 1000)) / (elap[0][0] * 1000 + elap[0][1] / 1000000));
}))+'e2')+'e-2')```
#

do this apply when sharding ?

#

need to change this or not

lyric mountain
#

toLocaleString is a javascript thing

#

Regardless of library or framework

crystal furnace
terse finch
crystal furnace
#

oke

terse finch
#

thats what discord_id is

lyric mountain
#

Idk then, I'm a java dude

#

Not javascript

crystal furnace
earnest phoenix
#

why people ping tim smh

wheat mesa
#

For bot testing while my bot is online for other users, should I create a separate bot user, or is there a cleaner solution?

crystal furnace
earnest phoenix
#

@crystal furnace he doesn't have all the time in the world to help us whenever we want

#

that's like pinging straight up veld for topgg support

tulip cradle
#

        if (!owner.includes(message.author.id)) return;```
this work with last ownerid
#

solution?

wheat mesa
#

Make owner an array of strings

wanton flicker
#

does anyone know why this happens on heroku hosting

#
2021-07-27T05:45:39.943630+00:00 heroku[worker.1]: Starting process with command `python app.py`
2021-07-27T05:45:40.715615+00:00 heroku[worker.1]: State changed from starting to up
2021-07-27T05:45:45.417660+00:00 app[worker.1]: Traceback (most recent call last):
2021-07-27T05:45:45.417713+00:00 app[worker.1]: File "/app/app.py", line 6, in <module>
2021-07-27T05:45:45.417852+00:00 app[worker.1]: from client import Client
2021-07-27T05:45:45.417857+00:00 app[worker.1]: File "/app/client.py", line 5, in <module>
2021-07-27T05:45:45.418008+00:00 app[worker.1]: import config
2021-07-27T05:45:45.418011+00:00 app[worker.1]: File "/app/config.py", line 8, in <module>
2021-07-27T05:45:45.418154+00:00 app[worker.1]: with open("config.json", "r") as file:
2021-07-27T05:45:45.418219+00:00 app[worker.1]: FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
2021-07-27T05:45:45.512819+00:00 heroku[worker.1]: Process exited with status 1```
feral aspen
#

Couldn't find a file called config.json.

#
!eval message.guild.roles.cache.map(x => x.name);
#

.. this order kind-of not organised.. any other way that shows it from top role to bottom?

wanton flicker
#

it just breaks every few hours

#

for some reason

feral aspen
#
2021-07-27T05:45:45.418219+00:00 app[worker.1]: FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
#

You will have to double check.

wanton flicker
#

but the problem is it doesnt break the moment it starts

#

and config.json is definietly a file

wanton flicker
#

is it this

worthy ivy
#

so im making a warn command, what permission should the end user have?

#

MANAGE_GUILD?
edit: manage_members isnt a permission so manage_guild instead

earnest phoenix
#

@worthy ivy manage messages is usually used for mods

worthy ivy
#

not a purge

#

so manage_messages?

nimble kiln
#

Yes Manage Messages

earnest phoenix
#

i wonder why someone would need that high access to warn a guy

worthy ivy
#

ok thanks for the help

earnest phoenix
#

You can use that for ban or channel purge

nimble kiln
#

what else should it be

#

Send_Messages? mmLol

modern patrol
#

discord.js

worthy ivy
#

is this an appropriate error message?

nimble kiln
#

If you make the first you Uppercase then yes

worthy ivy
nimble kiln
#

Eh still

worthy ivy
#

ehhh but message.reply does this basically

#

@worthy ivy, you don't have permission to do this!

#

it literally has a comma

nimble kiln
#

message.reply("\nYou can't [...]");

wheat mesa
#

ew

worthy ivy
wheat mesa
#

@wheat mesa,
You can't do that!

nimble kiln
#

I dont care about the comma I still use uppercase

worthy ivy
nimble kiln
#

Even bigger brain idea:

#

.reply() with an embed

worthy ivy
nimble kiln
#

Yes

#

Or this

hexed sedge
#

Hey! Does anyone know of any db packages similar to keyv that also work on node v14 or, more preferably, node v16?

long crow
#

josh?

wheat mesa
#

I have a MongoDB that stores prefixes in different servers. What would be the best way to go about checking to see if the prefix corresponds to the correct server? I feel like fetching the prefix from the db every time a command is executed is inefficient, but correct me if I'm wrong.

pale vessel
#

Do you not cache your prefixes?

long crow
#

/ Go Brrrrr

wheat mesa
#

This is the first time I've worked with per-server prefixes from a db

earnest phoenix
#

Extend the Guild object and put a prefix property Β―\_(ツ)_/Β―

#

Djs will cache it for you lol

wheat mesa
#

Not using djs

long crow
#

He use detritus

wheat mesa
#

Using detritus

#

Yeah

earnest phoenix
#

Doesn't detritus have caching?

wheat mesa
#

I'm sure it does, but the docs are... sub par

earnest phoenix
#

Also doesn't the command handler already have custom prefixes

stray onyx
#

a question , you cannot ping someone in an embed right ?

earnest phoenix
#

No

stray onyx
#

rip sucks

earnest phoenix
#

But you can in the normal message text

wheat mesa
#
const prefixes = ["w!"]

const startup = Date.now();

console.log('Starting bot...');

const commandClient = new CommandClient(process.env.BOT_TOKEN_BETA ?? '', {
  useClusterClient: true,
  shardCount: config.shards,
  cache: {
    presences: { enabled: false },
    emojis: { enabled: false },
    messages: { enabled: true, expire: 60 * 60 * 1000 },
  },
  gateway: {
    loadAllMembers: false,
    intents: [
      GatewayIntents.GUILDS,
      GatewayIntents.GUILD_MEMBERS,
      GatewayIntents.GUILD_MESSAGES,
      GatewayIntents.GUILD_PRESENCES,
      GatewayIntents.GUILD_MESSAGE_REACTIONS,
      GatewayIntents.DIRECT_MESSAGES,
      GatewayIntents.DIRECT_MESSAGE_REACTIONS,
      GatewayIntents.GUILD_VOICE_STATES,
    ] /* 'ALL'*/,
  },
  prefixes,
  onPrefixCheck: (payload: Context) => {
    const prefix = prefixes
    return prefix;
  },
});
``` This is what I currently use for prefixes
earnest phoenix
#

@earnest phoenix
(embed)
haha pingus go brrr @earnest phoenix
(/embed)

stray onyx
#

yee i was tryna ping in an embed to make it look kinda professional but didnt work lol

#

anyways thx dude

wheat mesa
#

Erwin's repo (which I started off with) says this in it: ```ts
onPrefixCheck: (payload: Context) => {
const prefix = prefixes
// The example below show how you should do it. Preferably have it from a database, but make sure to
// cache it so you dont constantly fetch it from database

//  if (!payload.message.guildId) return prefixes;
//  if (
//    payload.commandClient.guildSettings.has(payload.message.guildId) &&
//    payload.commandClient.guildSettings.get(payload.message.guildId)
//      ?.custom_prefix
//  )
//    _prefix = [
//      payload.commandClient.guildSettings
//        .get(payload.message.guildId)!
//        .custom_prefix!.toLowerCase(),
//    ];
return prefix;

},

earnest phoenix
#

when in doubt, ping erwin

wheat mesa
#

I would, but I'm not sure if he's available atm and I don't like randomly pinging people to ask for help

pale vessel
#

You can fetch the prefix directly or cache them first (maybe on the READY event)

#

Are you self-hosting your MongoDB instance?

#

Fetching prefixes on every message should be just fine

wheat mesa
#

I'm hosting on the cloud

pale vessel
#

I see

#

Then you should cache

wheat mesa
#

Yeah, currently looking into doing that rn

nimble kiln
#

I create an object on-ready with guildID: { "prefix": "!" } and other stuff

wheat mesa
#

Just trying to figure out a non-clunky way of doing it mmLol

pale vessel
#

What's clunky about it?

wheat mesa
#

Well, my problem is that I’m trying to figure out where to connect to the db and do that from

#

Someone told me to cache the prefixes with guildids as a map as needed

#

Which makes perfect sense

#

But it’s also 3am and my brain isn’t working

nimble kiln
#

I create a persistent db connection on script start (mysql)

pale vessel
#

I just use a simple object

long crow
#

I moved to slash command

wheat mesa
#

this is what my db entry looks like

#

Very simple

#

Which I’m assuming I connect to the db, fetch the entry corresponding to the guild id, then throw that into a Map

pale vessel
#

Yeah

#

You can fetch all entries at startup and use new Map(entries.map(data => [data.guildId, data.prefix]))

wheat mesa
#

Yeah, I was told that wasn’t a great option because it’ll cache servers that don’t use the bot but still have it in the server

#

(Not really a big problem since my bot is very small, I’m just trying to think ahead)

pale vessel
#

So you want to lazy load them?

wheat mesa
#

I’m not sure how big of a difference it would make

pale vessel
#

Probably not much for a small bot, but I still do that

wheat mesa
#

Lazy loading or cache all at startup?

pale vessel
#

Check if the prefixes inside the cache. If not, cache it

#

Lazy loading

wheat mesa
#

Ah

pale vessel
#

Spaghet code

wheat mesa
#

I assume opening a connection every time a command is sent to check for prefixes would be inefficient(?)

pale vessel
#

Dunno, I use Mongoose so I suppose it uses one connection after it connects (like a pool)

wheat mesa
#

I think I need to get some sleep

#

My brain is fried

#

https://www.compose.com/articles/connection-pooling-with-mongodb/ this seems like something similar to what I need to do

Compose Articles

TL;DR Making proper use of connection pooling can massively improve the performance of your MongoDB deployment. At Compose we often get support tickets from customers asking about the performance of their MongoDB deployments. In many cases, these issues can be addressed with a straightforward adjustment to how your applications

#

agh, I have no idea what I'm doing

#

I'm gonna figure this out in the morning

#

Anyways thanks for the help guys

woeful pike
#

just index ur servers by id and you can get away with querying your db for every message without much trouble for a while

inner fulcrum
#

how do u add a website page like this in top.gg description

spare badger
#

@inner fulcrum People use iframes for that.

inner fulcrum
#

ah ok

vagrant sedge
#

wait wtf can jsons not use integers as keys?

inner fulcrum
#

me when iframe no work:

#

its just a [b l a n k] square :C

cinder patio
cinder patio
pale vessel
#

JS objects can take a number as key but it converts it to a string

umbral lake
#

Hey, its my event:

client.on('voiceStateUpdate', async(oldState, newState) => {
    const voiceCollection = new Discord.Collection();
    const user = await client.users.fetch(newState.id);
    const member = newState.guild.member(user);
    if (!oldState.channel && newState.channel.id === '869482645288013904') {
        const channel = await newState.guild.channels.create(user.username, {
            type: 'voice',
            parent: newState.channel.parent,
        })
        member.voice.setChannel(channel);
        voiceCollection.set(user.id, channel.id);
        channel.overwritePermissions([{
            id: user.id,
            allow: ["MANAGE_CHANNELS", "VIEW_CHANNEL", "CONNECT", "SPEAK", "PRIORITY_SPEAKER", "MANAGE_CHANNELS", "MOVE_MEMBERS", "MUTE_MEMBERS", "DEAFEN_MEMBERS"]
        }]);
        channel.overwritePermissions([{
            id: member.guild.roles.everyone.id,
            allow: ["VIEW_CHANNEL", "CONNECT", "SPEAK"],
            deny: ["MANAGE_CHANNELS", "PRIORITY_SPEAKER",]
        }]);
    } else if (!newState.channel) {
        if (oldState.channelID === voiceCollection.get(newState.id)) return oldState.channel.delete()
    }
});

And when I join the channel, the bot add permissions for me or and everyone but bot both, and sometimes nothing πŸ˜”

quartz kindle
#

overwritePermissions() has to be awaited

#

also, you dont need to run them separately

#

you can put all permission overrides inside channels.create()

opaque seal
#

overwrite permissions overwrites the previous perms too I think, or no?

quartz kindle
#

yes, also that

#

you need updateOverwrites() instead

novel jetty
#

Why do i get errors when running npm i

quartz kindle
#

isnt klasa a dead project?

eternal osprey
#
client.on("presenceUpdate", (oldPresence, newPresence) => {
  if (!newPresence.activities) return false;
  newPresence.activities.forEach(activity => {
      if (activity.type == "STREAMING") {
          console.log(`${newPresence.user.tag} is streaming at ${activity.url}.`);
      };
  });
});```how would i get all the roles of the user?
#

the newPresence.user

split hazel
#

you can't get the roles of a user

#

you can only get it from a member which that user belongs to in a guild

eternal osprey
#

can't i use user.id and later on fetch it

split hazel
#

assuming you want a specific guild you'd do <guild>.members.fetch(id) (make sure to add await before that) and then access the roles via <member>.roles.cache

cinder patio
#

If you know from which guild to get the member from, then you can fetch the member

#

otherwise no, you can't

eternal osprey
#

yeah i do!

#

Thanks!

#

Because i have a certain concept:

#

i have a bot that actually checks the roles of a discord user. It can either be level 10, 20, 15, 25. I want to check the roles of a user and get the HIGHEST level of that user. Would i create like a chart for that using numbers? So: level 10 = 1, level 15 = 2 etc. Can i later on then just easily use the math.max property to get the certain role?

#

something like that

cinder patio
#

It sounds like you're using discord as your database

eternal osprey
#

wait what

#

no i just want to see if someone is streaming (using a presence event that i have already set up). I just need to get the highest level role of a certain user.

#

So i was thinking about like creating a chart and assigning numbers to the roles.

eternal osprey
cinder patio
#

You can get all the roles's names and get the ones which start with "Level" or whatever, then parse the number from the role name and Math.max

eternal osprey
cinder patio
#

regex

eternal osprey
#

aha okay. Thank you

split hazel
#

regex? a simple split by space and then accessing the second element will do

eternal osprey
#

wait how would i get all the roles again. It's like member.roles.cache() right?

split hazel
#

I'm pretty sure .cache objects have an .array() function which converts the role list into an array you can iterate over

#

do you know how to iterate over an array?

eternal osprey
#

yup!

#

i love using for loops actually

split hazel
#

forever useful

eternal osprey
split hazel
#

yes

eternal osprey
#

lovely speedy!

quartz kindle
#

you dont need to convert it to an array just to iterate over it

#

you can use the iterator functions

#

.keys() .values() .entries()

split hazel
#

ah yes

#

converting to an array is a waste of precious ram

warped lintel
#

hello good when my bot will be reviewed, how many days are missing?

quartz kindle
#

365 days

warped lintel
split hazel
#

your bot reviewum in a year

quartz kindle
#

nvm i just checked, its 3874658 days

warped lintel
#

in a year will my bot be reviewed?

quartz kindle
#

in 10615.501369863014 years

vivid fulcrum
#

everytime you ask, you add 24 hours

#

/s

grizzled fractal
split hazel
warped lintel
grizzled fractal
vivid fulcrum
#

we're just messing with you

quartz kindle
#

they dont tell you when, you have to keep your bot always online

grizzled fractal
#

or it will be declined

warped lintel
warped lintel
#

my bot is always online, 24/7

eternal osprey
#

is there any way to mimic streaming to twitch lol? I don't have a twitch and don't want to go live to test tbh.

vivid fulcrum
#

in the discord status?

eternal osprey
#

yeah

#

like the streaming to twitch presence