#development
1 messages Β· Page 1822 of 1
@terse finch are you checking if the id passed is the id of a member in the guild
ill checkout the api for discord.id thanks
yes
well
basically !command <ID> <MESSAGE>
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
cool good to know
they only want to see if the member exists in the guild
oh
guild member cache is enough for that
it would be useful later on if they just exist
you can still use REST
but for right now just existing in the guild is what i need
Use collection.some
i don't think so, in guilds especially you probably won't have all members cached
It takes a test function and returns true if any of the collection items passed the test
ill keep both options in mind when i try it out
Get user input
Test it against the regex or check it's length
Check if the ID belongs to a user from the guild by fetching them from the guild by<Guild>.members.fetch()and catching them if it doesn't exist as you're using discord.js
Then do whatever
welp then fetch ig
it's fine
Remember that the smallest ID length exposed to the API is 17 characters, the longest one being 18 characters
i need hekp
what's up
grafana sqlite says permission denied, but i've given the perms
with chown
;-
on the same server
DON'T
im dying from 4 hours
the not Erwin guy
ye cant find
wtf
it keeps throwing this error
and on the server i have given grafana user the ownership of the dir
;-;
the file is in /root
yeah
maybe that's the problem
it needs /root/
if i remove root it says it cant find the dir
it needs an absolute path
literally
move the dir to / instead of /root
No file found at: '/izzi/izzi-bot/json.sqlite'
No file found at: '/izzi/izzi-bot/'
i tried this also
i tried ~/ also
the izzi folder is inside root that's why it cant find it...
yes
correct
man i feel powerful
uwu
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
so i fetched the guild members, now do i just run collectionOBJ.find(member => member.id === PassedInID)?
You can also just do <Collection>.get(<ID>)
so umm
code
xd
where you at brother
can i store multiple columns with quick.db? currently everything is just dumped at json
you're storing json in quickdb?
does it ever happen you write a big project then you forget yourself hoe the fuck you made it
resumed an old project?
id | data
-----------
0 | aaa
1 | bbb
2 | ccc
like this?
so anything stored in db it stores json or string
yah
i wanted more of id | col1 | col2
from qdb
bruh
wondering if that's possible
not only possible, but the way it should be happening
π
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
actually, it's sqlite which is lightweight
also straight forward methods for what i was looking for
sqlite is the lightest you can get and retain major sql features
tbf, almost all big tools use sqlite for settings storage
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
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
what wrapper you use?
knex and the pg-client itself for faster query
ayy my man
faster query is subjective
go with sequelize
optimzation
thats what they all say
sequelize doesn't exactly optimise your queries very well but you know
better than using a lib that stores all table data in a json field
can't disagree on that
I wonder how much bots use qdb
I can only imagine how disgusting managing a big db with that is
let alone backup restores
its more like someone trolled us
i used it once for a bot where i needed a quick database with no complex queries
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
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
lol imagine using joins
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
why don't they feel right?
or i would just increase the amount of columns
like, you're putting 2 tables side by side, you just need some identifier so you can estabilish a connection between both
dont know they just feel unreliable/not very performant
they're the exact opposite of that
but then i've never used them lol
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?
table user
- id
- name
table user_card
- card_id
- user_id
table card
- id
- name
- color
- price
yeah i get it but i just like keeping data relevant to that specific thing in one place
not spread them
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
the word you're looking for is called a junction/pivot table btw
the table that allows you to do many to many relationships
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
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
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
how do i get the votecount
I have a question about DigitalOcean
How many servers can a bot (on the lowest plan) handle if I host on DigitalOcean?
that depends on the bot
Check your bot memory usage too
True
But how can I get an estimate for myself
The bot's file size and memory usage?
File size shouldn't matter most of the time
I have an economy bot, and it was handling up to about 2.2k servers before it got really slow
It was running out of ram
It's the CPU and memory I suppose
So i switched to the $10 plan
if you have presence enabled
you can expect it to be considerably lower count
compared to a bot that has it disabled
Depends if your bot does intensive work or caches everything
e.g. bot with no presence will have much lower cpu usage
If you want the monthly vote count use the bots endpoint
presence is like "listening to ..." right?
or "playing ..."
Not just those. Statuses, custom statuses, and activities included
Ok
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
Im confused
Does presence in this context mean guild member presence or the presence on the bot?
Member presence
Guild members
I c
@rose warren Congrats on BR (just noticed)
Thanks! π
My guild presence thing intent is off
so would i do vote.monthlyPoints?
Yeah
ok ty
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
Tim why no lib dev role? π
Ah probably π
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
There should be a method like getBot() in the lib, not sure
If not you can always request it yourself
ok
Bruh my powershell do be acting up today doe 
does java have a way to freeze objects like Object.freeze in js?
private final immutable Map<> dontChangeMe = ...
found it Collections.unmodifiableMap(mutableMap);
lol
why tho?
like, except for creating libs, is there an actual use-case to lock collections?
i wanted to do it in the signature of a function so the functions dont modify input
ah, that
you could just do new HashMap(input) tho
or Map.copyOf(input)
the latter being unmodifiable
but someone could still go in an mutate the original parameter
oh and don't forget state changes might be mirrored to the other map
a naughty person
not with Map.copyOf()
it's literally Collections.unmodifiableMap() but shorter
but the original map is still accessible
Map.copyOf creates a new copy
because the signature of the request has it there
and neither that or the Collections way prevent data change
so a naughty person wont use the copyt
asap question - someone knows maybe a free api with random facts and jokes? using icanhazdadjoke breaks bot...
... due to swear lists
;-; pls...
;;;-;;;
Is it dangerous/bad/dumb to shard your bot when your bot is not in many servers?
this last, yea
Anyone can suggest a good bot hosting vps?
dumb, yeah. because all you're doing is decreasing you're performance
Ok
Also can anyone help me with this lol
loads of people use galaxygate
code?
JavaScript, node.js
If i do process.cpuUsage it just crashes because it's bigger than 1024 or something
..
Again, a load of questions...
cpuUsage is a function, not a property
Oh
Okay
also cpuUsage does not give you what you think it does
Is there a property cpu thing?
Like is there a way i can get the cpu's usage
there is a way yes but its harder than you think
Oh
also, you want the entire machine's cpu usage, or the bot's cpu usage?
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.
Just the bot's probably
But I'm using heroku so idk if machine works too
like if this.client.messageChannel is an empty obj it should send the new TextChannel any ideas?
Thanks a lot :D
??
-_-
.then() runs at a different time, since its async
you have to await the promise
i just googled free joke and fact api and this is the first thing which came up: https://api.chucknorris.io
thats the thing, the method is a getter :/
being mad wont make anyone answer you faster. if nobody answers its because we dont know because we dont use whatever you are using
oh oops that is only for chuck norris jokes lmao
it doesnt matter, if getChannel is an async function, it has to be awaited. you can make the getter return a promise, and then await it at the caller
Bro... Not this... Where chucknorris and a command in a bot for displaying ASCII art cow(cause this I'm doing)?
yeah, i've tried to make the channel asyncronous but i have no idea how to. one sec
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
you have to make it a promise
yeah i tried wrapping it around in a Promise.resolve same thing
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)
})
}
i'll give it a try
For digitalocean, which one is used for discord bots? General Purpose Droplets or Basic Droplets
same thing, i also tried: js if (Object.keys(this.client.messageChannel).length === 0) { Promise.resolve( 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; }
oh whoops
then it looks like maybe Galaxygate has better prices
yes galaxygate is cheaper
Aight
yeh i misunderstood what u said
same thing, it errors then i have to send a message for it to like, work as intended
did you change the caller to await it tho?
you have to await the getter
await something.channel
yeah
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
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
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
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;```
Promise.resolve is if messageChannel already exists
you dont need it inside the then
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
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()
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
you cant
oh
Should be pinnedβ¦
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
did you add the return inside the then?
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);```
did you console.log the getter?
im calling it, and because the obj is empty it is supposed to create a TextChannel instance which is this.client.messageChannel which then is called somewhere else
and it errors basically saying its just an empty object
show the code that calls the getter
await message.channel.createMessage();
thats the problem
yeah i tried mesasge.channel.then
(await message.channel).createMessage()
same thi- oih
otherwise you are awaiting promise.createMessage instead of awaiting promise
oh yeah true
would probably be a good idea to not use a getter here, to not confuse yourself
just make it a normal async method
but then i'll have to do message.channel().createMesasge wont i?
and it wont like, look nice idk
const channel = await message.getChannel();
channel.createMessage();
i'd do it like that
Java
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?
if i were to do this then, how would i get the current channel?
You save them to an object/map and get it from that
yeah but i would have to get the id somehow to compare it to or something
message.channel_id?
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
that'd change tho, every time its called in a diff channel - this was my initial thought but it didnt seem very good
ye
Yeah it would change
i still dont get it tho, cuz how am i supposed to get a specific channel from an array of channels
yeah and how do i know which is the current channel
Find the channel by ID that matches message.channel_id
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;
}
hm
i got an idea, it'd be caching everything upon connect
but it'd be a pain to send all that data across
That's what I said
oh
As in /guilds/:id/channels
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
check if ur bot had the Server Members Intents
has*
i think
already on
you need the GUILD_MEMBERS intent
wus dat
wait wrong server
brains to small for that
you have to tho
bruh just read the guide and ull be ok in no time
just put in an extra line
it's VERY easy to do
throw the for loop in an async function and await whatever it is you're waiting for
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
i use a json 
note only add the intents u actually need
ITS A SINGLE FUCKING LINE OF CODE
bruh chill 
i was asking cuz im pretty sure using json to store things is megacringe
yes but
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
}
}
its okay
using json as db is bad
why?
for smaller bots it does not matter
just use mongodb 
but for bigger ones you should use an actual db
and learn the syntax?
json is not good to use as a db if it's read/written to a lot
sigh the intentations arent intentationing
...
are you importing a Client from the discord.js library?
Do you understand what typing new Client does..?
idk how imports work in js
lmfayo
but i assume there's a way that you require Client from "discord.js" or something
tbh idk wut im doing at this point
also it seems to me that you have no clue what your code does
it's usually ```js
const { Client } = require('discord.js');

or es6 syntax as ```js
import { Client } from 'discord.js'
also decline ur client btw
define
My wifi just died but im back
yes, decline your client
yes, decline your client
decline it
I want to make a deez nuts joke but i also dont
decline deez nuts lolz
wait wtf mongodb is cloud based
good
is storing locally bad?
not necessarily
locally hosted database is better in all situations except 1: when you actually need to access it from multiple severs
a db that you install and run on your server
alongside your programs/bots/websites
My wifi is aliving
did it dieded?
aliving 
here we go blaming sauce fish for you not knowing your code
what the fuck did i do
Perhaps you should show your code instead of giving us errors without context...
nothing lolz
I suppose that this might be relevant
no
LOL
how do i save
troo
It's a sticker, not sure if you can even save it
dfsfs
i just bit the orange part of my orange
wdym you cant save it
tastes bad
Oh, there's no option for that on desktop
im on the browser version
woah
with chrome extensions to preview/zoom images on hover
you can drag the sticker to your browser and it gives you the png for the sticker
doesn't seem to work for me either
You can't drag stickers
But you can simply open devtools, inspect element and grab the url
Does anyone here have experiencing with using python's ConfigParser module for writing configuration files?
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?
you want the cooldown to apply or you dont want the cooldown to apply?
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
What should I rewrite to fix this ?
Sharding cause a lots of problem
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
what is results[0]
I will putting more value
results 0 is the response from the first shard which is a number
like this?
[{guildCount:4, memberCount:19},{guildCount:10, memberCount:41}]
No filter guild member > value
its a promise for fetchClientValues(guilds.size)
results[0] should be [size, size]
i think you're both confused
so reduce cache first ?
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
https://discordjs.guide/sharding/#broadcasteval I am following this
yes, you need the broadcastEval version
the code for what you want to do is literally here
and here
if you want to keep the individual counts, then you need to do it differently
Sharding make problem more difficult
const allGulds = await broadcastEval(`this.guilds.cache.map(g => ({name: g.name, memberCount: g.memberCount}))`);
const guilds = allGuilds.flat();
can you explain me what is flat
[[1,2,3],[4,5,6]].flat() = [1,2,3,4,5,6]
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
yes you can delete that
it is working
you are best Tim
I should to ask you eailier
Can you add friend with me ?
this is where you say yes
Well...define ur variables
wait
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);
}```
Errr....
hmm i think i know a problem
can you rewrite this or give me a example
I think i am confusing myself
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
yup i am confusing myself
@lyric mountain
will it work ?
TypeError: results.reduce(...).filter is not a function
because it is a number
=)))
You probably can't reduce an object directly
so it can't fitler
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 ?
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.
Btw, did you state somewhere that your bot will publicly show the server names?
Like, that mighty cause privacy concerns
a server name is not a problem
It is
no
Not all servers are public
it just a test bot
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
Await it
Or use async callbacks
What would I put here
What are you trying to do?
const member = await message.guild.members.fetch(true)
this
inside an async function
you sure? it worked like 2 hours ago when i first wrote it lol
Ye, you fetch for an specific id
i need to check an ID against all possible guild ids to see if its a guildmember in the current guild
Why?
Just fetch for the id in the current guild
If the user is in it it'll return a result
i need a cacheable version of all members.
You shouldn't cache all members in all guilds
cause i dont wanna have to check each id thats passed in with a guild lookup when the command runs
Nice
What exactly are they trying to do
i have a collection of ids, need to be checked against all guild member ids, and then mark any outliers
Just beware the privacy stuff
i was trying to force it to fetch, hence the true (to skip the cache)
doesnt work either way
same but it never hurts to try
Just a note, you're limited on how many fetches you can do in a given time frame
Also with fetch don't you need to enable partials?
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
But you are fetching all the members for the current guild the message is being sent in...
exactly why i wanted all at once, compare across opbjects
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
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
I think
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
replace(DISCORD_id)
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
no i am asking you another code
const Discord_id = user.id
oke
thats what discord_id is
@quartz kindle sorry for ping
why people ping tim smh
For bot testing while my bot is online for other users, should I create a separate bot user, or is there a cleaner solution?
he is very skillful you can see also he is a owner of discord.js-light library and many big things
@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
if (!owner.includes(message.author.id)) return;```
this work with last ownerid
solution?
Make owner an array of strings
ok
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```
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?
yeah but the file exists
it just breaks every few hours
for some reason
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.
but the problem is it doesnt break the moment it starts
and config.json is definietly a file
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
@worthy ivy manage messages is usually used for mods
but it is a warn command
not a purge

so manage_messages?
Yes Manage Messages
i wonder why someone would need that high access to warn a guy
true
ok thanks for the help
You can use that for ban or channel purge
discord.js
is this an appropriate error message?
If you make the first you Uppercase then yes
Eh still
ehhh but message.reply does this basically
@worthy ivy, you don't have permission to do this!
it literally has a comma

ew
what is this just to be ready for inline replies?
@wheat mesa,
You can't do that!
I dont care about the comma I still use uppercase


Hey! Does anyone know of any db packages similar to keyv that also work on node v14 or, more preferably, node v16?
josh?
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.
Do you not cache your prefixes?
/ Go Brrrrr
This is the first time I've worked with per-server prefixes from a db
Extend the Guild object and put a prefix property Β―\_(γ)_/Β―
Djs will cache it for you lol
Not using djs
He use detritus
Doesn't detritus have caching?
I'm sure it does, but the docs are... sub par
Also doesn't the command handler already have custom prefixes
a question , you cannot ping someone in an embed right ?
No
rip sucks
But you can in the normal message text
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
(embed)
haha pingus go brrr @earnest phoenix
(/embed)
yee i was tryna ping in an embed to make it look kinda professional but didnt work lol
anyways thx dude
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;
},
when in doubt, ping erwin
I would, but I'm not sure if he's available atm and I don't like randomly pinging people to ask for help
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
I'm hosting on the cloud
Yeah, currently looking into doing that rn
I create an object on-ready with guildID: { "prefix": "!" } and other stuff
Just trying to figure out a non-clunky way of doing it 
What's clunky about it?
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
I create a persistent db connection on script start (mysql)
I just use a simple object
I moved to slash command
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
Yeah
You can fetch all entries at startup and use new Map(entries.map(data => [data.guildId, data.prefix]))
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)
So you want to lazy load them?
Iβm not sure how big of a difference it would make
Probably not much for a small bot, but I still do that
Lazy loading or cache all at startup?
Ah
Spaghet code
I assume opening a connection every time a command is sent to check for prefixes would be inefficient(?)
Dunno, I use Mongoose so I suppose it uses one connection after it connects (like a pool)
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
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
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 People use iframes for that.
ah ok
wait wtf can jsons not use integers as keys?
nope. All keys are strings. It's the same for JS objects, too.
Can you give a link to your site?
JS objects can take a number as key but it converts it to a string
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 π
overwritePermissions() has to be awaited
also, you dont need to run them separately
you can put all permission overrides inside channels.create()
overwrite permissions overwrites the previous perms too I think, or no?
Why do i get errors when running npm i
isnt klasa a dead project?
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
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
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
If you know from which guild to get the member from, then you can fetch the member
otherwise no, you can't
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
It sounds like you're using discord as your database
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.
idk if there is any other faster way to achieve this\
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
How would i only parse that number, as there is level in front right.
regex
aha okay. Thank you
regex? a simple split by space and then accessing the second element will do
wait how would i get all the roles again. It's like member.roles.cache() right?
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?
forever useful
i actually didn't know that. So it would be like: <member>.roles.cache.array()
yes
lovely speedy!
you dont need to convert it to an array just to iterate over it
you can use the iterator functions
.keys() .values() .entries()
hello good when my bot will be reviewed, how many days are missing?
365 days
???
your bot reviewum in a year
nvm i just checked, its 3874658 days
in a year will my bot be reviewed?
in 10615.501369863014 years
perfectly right
no you multiply your remaining time by 24
sorry I didn't know that as it's my first time adding a bot in top.gg
thats better
if you didnt realize by now, we are trolling you. you cant know when your bot will be reviewed. you just have to wait until it is. it usually takes 2-3 weeks
they dont tell you when, you have to keep your bot always online
or it will be declined
ah thank you very much I will wait those weeks aver that passes, xd
my bot is always online, 24/7
xdd
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.
in the discord status?







