#development
1 messages · Page 1367 of 1
yes
wooh!! that is cool
Array chunking function
1:
function chunkArray(array, splitBy) {
let thisArr = array;
let newArr = [];
for (let i = 0; i < thisArr.length; ++i) {
let cAL = Math.ceil(parseInt(thisArr.length) / parseInt(splitBy));
let nac = new Array(cAL);
for (let j = 0; j < parseInt(cAL); j++) {
nac[j] = thisArr.slice(0, parseInt(splitBy));
thisArr.splice(0, parseInt(splitBy + i));
}
newArr.push(nac);
}
return newArr[0];
}```
2:
```js
function chunkArray(array, splitBy) {
return Array.from({
length: Math.ceil(array.length / splitBy)
}, (a, r) => array.slice(r * splitBy, r * splitBy + splitBy));
}```
@quartz kindle Which do you think is the fastest
obj.isEmpty() 😎
will that also work for class instances?
If I extend Object, how node will use mine extended Object?
@earnest phoenix the first one looks very wrong
what is the function supposed to do exactly?
chunkArray([1,2,3,4,5],2) = [[1,2,3],[4,5]]?
Looz
chunkArray([1, 2, 3, 4, 5], 3); // [ [1, 2, 3], [4, 5] ]```
ah so splitBy is max items per chunk
Yes
still the first one looks very wrong, looks like it would produce duplicated results
i dont help people in dms
did you google "html img tag"?
ya cant find any thing
lol
*it
how can i make an html js function to show html
Wot
and how can i use switches with js to use mongo
inject html code in a string, to dom elements
@quartz kindle Did you figure it out yet
if that works, than whats the issue?
@earnest phoenix the first one modifies the original array
@quartz kindle But which is faster?
(First is faster somehow
)
how did you measure it
Measure how fast it's?
Calling both 999999 times 
just to make sure repeated runs are not being made to an empty array
search djs guide
How to catch errors without using try...catch?
discord.js
@covert gale use if() and see if the message author id is the same as yours
if (message.author.id === "...") {
/* code */
}```
To lock it to just you do smthin like this
if (message.author.id)
How to catch errors without using try...catch?
do logical checks beforehand, promises over throwing, etc.
@sudden geyser u talking to me?
yes
no idea what ur talking abt
How to catch errors without using try...catch?
?
yea
do logical checks beforehand, promises over throwing, etc.
@sudden geyser no idea what this is about
there are only 2 ways to catch errors
try catch for sync code
.catch for async code
there isnt any other way to catch errors
unless you use something hacky like a global promise rejection handler
which is a bad idea
i found it
When i react to my suggestion, it should change the message to be "accepted" but nothing happens wheni react. no errors in console too
Heres the code for the reacting stuff
thanks
Logical checks = checks you do before doing the actual thing that may throw.
Promises over throwing = myPromise().then(...).catch(...)
didn't work oop
async function sendTheTestMessage() {
collected_v1.first().mentions.channels.first().send(
new Discord.MessageEmbed()
.setTitle("Test Message")
.setColor("#738ADB")
)
}
sendTheTestMessage().catch(err => {
console.log(true)
})```
i'm trying to let it detect a error
@harsh blade you're still not showing where you're getting emojiKey from
i'm trying to let it send in a channel it cant send it and let it give it a error it can detect*
@surreal sage the promise is being left in the limbo
you need to return the promise to catch it from outside the function
what
what
what do you want me to return
want me to put return infront of collected_v1?
@quartz kindle
function a() {
asyncFunction()
}
function b() {
return asyncFunction()
}
a().catch() // error catch of undefined
b().catch() // works
if you dont return anything, it returns undefined by default
and cant use .catch on undefined
nope
@quartz kindle Now it's in a catch block, how do i stop the whole code?
what do you want to stop? show code
async function sendTheTestMessage() {
return collected_v1.first().mentions.channels.first().send(
new Discord.MessageEmbed()
.setTitle("Test Message")
.setColor("#738ADB")
);
}
sendTheTestMessage().catch(err => {
setup.edit(
new Discord.MessageEmbed()
.setTitle("Logging Setup")
.setColor("#738ADB")
.setDescription("The bot wasn't able to send a message in <#" + collected_v1.first().mentions.channels.first().id + ">.\nTry fixing the permissions.")
)
})```
I want it to stop after the .edit function is called
return; doesn't work
you cant
async code runs in parallel do the rest of your code
you need to bring it back to the main code by using await
and using try catch
then you did it wrong
show what you did
@harsh blade does the console.log(emojiKey) work?
i just did js try { /*code*/ } catch (err) { /*code*/ }
the error is the DiscordApi something
this one
c est bien ca, mon pot
show the code you put in there
because promises can only be caught by try catch if they are awaited
if they are not awaited, try catch wont catch it
ok nvm
@harsh blade does the console.log(emojiKey) work?
@quartz kindle Nope
jesus christ
montre le
also
@harsh blade do you have any error in your logs?
About how long did it take you guys to get the members intent? Just wondering cos I can’t release an update without it 
Nope
why does it allow this: ```js
.then(somethin => [
])instead of js
.then(somethin => {
})```
no errors
vsc doesn't give a error to that
@surreal sage the first one tells the function to return an array
so you could basicly const or var that function and get a array?
yes
arrow functions dont need a full function block to work, they have a shortcut to immediately return a value
for example (a => true) returns true, the same way as (a => { return true }) does
forever
no idea
WAIT REALLY?
your ip get deleted
likely a few hours
oh that's good
I'm not sure why I got that error though
I switched to a vps from self hosting yesterday
Also. when running status command, it cant find my staff role? how can i use the ID of that role? any help?
@earnest phoenix the first one is 3 times slower for me
@quartz kindle Oh, yea i tested it incorrectly lol (I made both of the functions, but the first is old, guess when i writing the second one i was evolved)
does anyone know why that might be?
I also thought the second one would be a lot faster
but the thing is, I never had that issue before switching to a vps
and I'm pretty sure after switching not many people used the music commands
🤷♂️

my bot can't get my staff role info. any help? i wanna use the ID instead of the role name
Look at the YouTube api ratelimits
A competition? Hell yea
@solemn latch but do you have any idea why did it rate limit just after switching to a vps
my bot can't get my staff role info. any help? i wanna use the ID instead of the role name
https://cdn.discordapp.com/attachments/272764566411149314/773931900184166430/unknown.png
Well, ips are not use once and done. Someone had your vps's ip before you. @ancient nova
Maybe that ip was used for a music bot too and got ratelimited before you got it 🤷♂️
Or people ran a few thousand songs after you swapped to a vps
so
Again, ratelimiting is super common in music bots
using a vps doesn't give you privacy
You'll have to deal with this frequently
Nothing on the internet is private
The ip you have now is only yours now however
It was someone elses.
you make me think that self hosting was safer than using a vps
This is true at home too
so the ip the vps gave the server now is only mine?
Right now it is yes. Assuming its a proper vps
Before you had it, someone else rented it. Its how the internet works for everyone
Music bots get ratelimited a lot either way
And you'll need to deal with it either way
it was worse, and used a lot of my pc's space but at least I didn't get rate limited
@earnest phoenix
The ratelimits the exact same no matter where you host it
🗿 What the fuck
but I never was rate limited while self hosting
idk
that is the thing that makes me mad about being rate limited
let me check if there is anything wrong lmao
my bot can't get my staff role info. any help? i wanna use the ID instead of the role name
https://cdn.discordapp.com/attachments/272764566411149314/773931900184166430/unknown.png
How can i set the transparency of rectangle in canvas?
@earnest phoenix doesnt look like there is anything wrong

I'm gonna go try a few more things, I'm pretty sure if I make a new key using a different IP then the rate limit will reset
I'll try that
TIm can u help
tim is getting overwhelmed lol
@harsh blade your code is very confusing and all over the place, there could be many errors elsewhere
add more console.logs and see until where the code works
@quartz kindle can you try this?```js
function chunk(arr, max) {
const newArr = [];
arr.map((x, y) => y == 0 ? newArr.push([x]) : y % max ? newArr[newArr.length - 1].push(x) : newArr.push([x]));
return newArr;
}
chunk([1,2,3,4,5,6,7,8,9,10,11], 4); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11 ] ]```
lmao
what about this ```js
function chunk(arr, max) {
const newArr = [];
arr.map((x, y) => y % max ? newArr[newArr.length - 1].push(x) : newArr.push([x]));
return newArr;
}
chunk([1,2,3,4,5,6,7,8,9,10,11], 4); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11 ] ]```
🗿
wack
so i guess my first idea still wins by far
what about this eval ```js
function chunk(arr, max) {
return arr.reduce((x, y, z) => z % max ? [...x.slice(0, -1), [...x[x.length - 1], y]] : [...x, [y]], []);
}
chunk([1,2,3,4,5,6,7,8,9,10,11], 4); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11 ] ]```
this is funky af
i'm just keen to see the numbers
Sometimes the simplest solutions are also the fastest, I dunno
Would it be faster to start from the end of the array
@cinder patio can you paste it as text so i can run it here?
function chunk(array, amount) {
const res = [];
for (let i = 0; i < array.length; i += amount) {
if (i > array.length) i = array.length;
res.push(array.slice(i, i + amount));
};
return res;
};
Maybe my PC is faster in general
ye probably
give me your function
whats your browser?
Chrome
He just has a better gaming chair
this is mine
function chunkArrayTim(array,splitBy) {
let a = [[]];
for(let i = 0; i < array.length; i++) {
let index = a.length-1;
let item = array[i];
if(a[index].length === splitBy) {
a.push([item]);
} else {
a[index].push(item)
}
}
return a;
}
a
how do i become an epic coder
interesting
i read somewhere that array.slice() has heavy optimization implications
im using brave browser, array.slice() is extremely slow for me
oo maybe
slow boi
Just convince all your users to use the right browser
xD
well if we're gonna do performance competitions like this, i guess we need to have separate rankings for every single browser
yes, fastest IE benchmark
@quartz kindle Try this
function chunkArray(array, splitBy) {
let bruh = 0;
return array.reduce((acc, current, i) => acc[bruh].length === splitBy ? (acc.push([current]), bruh += 1, acc) : (acc[bruh].push(current), acc), [
[]
]);
}```
@earnest phoenix interesting
1 second? Fuck that's worse go back
but its fast in brave/chrome
lmao
almost as fast as mine and google's
edge is just shit
The one google showed is from stack overflow lmao
lmao
it's not?
[I literally see it everywhere]
more like a general concept
yea... it's a common way to it
Yea but talk about original
¯\_(ツ)_/¯
how do i get input from an html form with wtforms flask and put it into python
ping with resposnesss
I've noticed a trend.
Theres actually a ton of python users here. But none of them sit here to help each other.
Python users don't like helping each other 
i do sometimes!
Most of the time i see you answering a question its because you where here asking a question yourself
I make sure to go out of my way to come here and help. Seems tim and a few other js users do.
Python users don't like helping each other
@solemn latch lol truth
But I am js guy.. not python so no worries
it sad that I use a mobile app to develop my bit lmfao
@woven burrow Discord Bot Maker or something?
Can someone help me im trying to get my bot dm's to go into a channel in my discord. Im kinda lost on how to do that. Thanks
it sad that I use a mobile app to develop my bit lmfao
@woven burrow btw I host my bot on my mobile
@woven burrow Discord Bot Maker or something?
@earnest phoenix yes DBD
Can someone help me im trying to get my bot dm's to go into a channel in my discord. Im kinda lost on how to do that. Thanks
@earnest phoenix what language ?
alr python nerds ping me for help
Kek
@woven burrow btw I host my bot on my mobile
@amber sedge what app?
Ay
@amber sedge what app?
@woven burrow in mobile terminal
English
@earnest phoenix ok get Outta here
Mhmm
Bruh lmao, joke .js
Have not been asleep sorry
Try using listeners on ur bot dms and send the same in channels
Ig
I'm not that expert
Sorry
Hey can somebody help me how to add mongodb in discord.py
Try using listeners on ur bot dms and send the same in channels
@amber sedge it's like say command
Imagine quoting yourself
@solemn latch noone ever needs help with python
thats why
check if guild is none
Hey can somebody help me how to add mongodb in discord.py
If no one needs help with python then is this guy a joke to you

Kek
If anyone needs any hosting for their bot, feel free to DM me. I have an Ubuntu server ready.
too nice
Ay
I bought a vps server and didn't want it within 10 minutes and I still don't feel comfortable giving it to random people
that's very generous of you
So it'll sit there doing nothing
yeah
maybe when my self hosting fails
but right now it hasn't failed me because my has been online for over a month lmao
Is there a way to implement a music seek on ffmpeg
Probably
position (input/output)
When used as an input option (before -i), seeks in this input file to position. Note that in most formats it is not possible to seek exactly, so ffmpeg will seek to the closest seek point before position. When transcoding and -accurate_seek is enabled (the default), this extra segment between the seek point and position will be decoded and discarded. When doing stream copy or when -noaccurate_seek is used, it will be preserved.
woo is my dev senpai now smh
you need to keep a copy of the buffer/stream in your code and feed that to ffmpeg, ffmpeg can't receive signals but stdin, stdout and stderr
you would be seeking the local copy ofc
granted you can always just kill ffmpeg and spawn it with the arg woo sent
Seems fine to me no problems killing it every time
hey is there any plugin like nodemon for python
pm2
@cosmic forum sure
@young flame Alright
@cosmic forum for real lol?
yea
the whole message or just the embed from it?
get the message attachments -> foreach -> is it a MessageEmbed? -> delete
Message attachments does not include embeds
how could i parse this type of content into a map requester|example content|example2etc.
(i know i could just use json, but the clientside language is c++ and i don't really want to use 3rd module for that)
Message attachments does not include embeds
oh yeah, just checked, embeds have their own space
I want to code a bot that allows admins to add league of legends players. The bot will autoassign roles depending on the rank of the players.
Discord has told me that it cannot activate member intents and I have come to ask what you recommend me to make databases for members

The bot should grab the rank from op.gg for example https://euw.op.gg/summoner/userName=The+Beerhunter
Ranked Solo
Gold 4
parah
The bot should then autoassign Gold role on the discord server
Lets say every 24h the bot will go in and update the page then renew the role (if needed)
Is this possible?
@drifting wedge Do you have any cheat-sheet/article that helps with array manipulation like array[::1] and stuff since I dont really understand those
I understand say array[1] but dont understand the ones where [::] is used
1 sec lemme find something
@bleak crypt its possible if the user runs a command and informs their league username and region
otherwise no
a[::-1] # all items in the array, reversed
a[1::-1] # the first two items, reversed
a[:-3:-1] # the last two items, reversed
a[-3::-1] # everything except the last two items, reversed```
account integrations are not accessible by bots, only through oauth2
@earnest phoenix
sqlite, mysql, postgre, mongodb, etc
With better-sqlite3 you can also?
yes, that's sqlite.
How do you make the bot sync with https://euw.op.gg/ ?
It should update the profile, and then assign a role
you need to scrape the website
op.gg doesnt provide an api
but ideally you could use the riot api directly, which is what op.gg does in the first place
think my express broke
Feels lazy man
Callum, what theme is that??
sqlite, mysql, postgre, mongodb, etc
yo..u sa..id m..m..mysql?
is it lazyRouter?
@quartz kindle Do you know someone who would be able to script it for me?
Callum, what theme is that??
@rocky hearth Atom one dark
@bleak crypt many people here are more than capable enough, however the goal of this channel is to help developers with their own projects, so for example we could help you make it yourself. But if you're looking to hire someone, you need to go through other places, like other discord servers or even something like fiverr
or my dms
sqlite would definitely be a go-to for member caching
it's absolutely as lightweight as you can get
^ +1
you know, since better-sqlite3 is full synchronous, you can actually hack discord.js collections to use it
I wonder what's the black magic behind sqlite
like, compression but keeping IO speed?
caching and indexing magic
could someone answer this question though? #development message
loop through it putting entries in a map
anyone know how to register a .js.org domain
if c++ has something akin to java's stream then you can re-map it
anyone know how to register a
.js.orgdomain
@willow mirage it'd be.orgin this case
cname
just go make pr into the repo @willow mirage
check the tutorial on https://js.org lol
Dedicated to JavaScript and its awesome community since 2015
intresting
@restive furnace i did, but didn't get it
then you cant make one if you got denied for one
u guys think this will work to auto update the status and the bot page on site?
@willow mirage then ur website is not hosted on github or has no content
does anyone know what this might mean? ```js
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received Promise { <pending> }
callback must be a function, you cannot use a pending promise
callback must be a function, you cannot use a pending promise
@solemn latch ```js
async function setStatus() {
const obj = await fetch('this url is replaced by a private one').then(x => x.json())
let newStatus = obj.displayStatus
client.user.setActivity(newStatus, { type: "PLAYING" })
}
setInterval(setStatus(), 20000)
how can i fix that in the context of this function?
ah
the function may be used elsewhere, which is a common reason for doing it that way. or for cleaner code.
well yes
@quartz kindle How would u do different regex match statements for one var (effient)?
if( preg_match_all( "/(\d+)\s+(.*?):(.*?)\s+([0-9]+)\s+([A-Za-z0-9]{32})\(.*?\)\s(.*)|([0-9]+) players in total/", $data, $match_list, PREG_SET_ORDER ) != false )
elseif( preg_match_all( "/Player #([0-9]+) (.*) \((.*):(.*)\) connected/", $data, $match_list, PREG_SET_ORDER ) != false )
PHP example
throwing the result into $match_list and is only available if $data matches the whole regex pattern
what is it supposed to do?
Checks if a received message (active socket connection) matches the pattern
huh... posted the pattern above. lel u really dunno regex 
one second
Player #4 Player name (3) (1.2.3.4:2304) connected
Would match pattern 2 (in my example above)
It would create a $match_list (PHP) including all match groups I need
in this case, the ID (#4) the name (Player name (3)), the IP address and client port
well i would just use a combination of indexOf (or the php equivalent) and string splitting on spaces lmao
With this whole complexity it's like impossible to strip/split each received message and check for all patterns
Those are just 2 examples... there are more than 14 patterns I have to check
And I need each group of each pattern every time if the match is positive
Let's ask a different question...
Let's say I'm using regex and u don't have to deal with...
lmao
How would u check if a string.match(pattern); is not null
of cause with a statement if(string.match(/pattern/) !== null) { true }
what is sending that message?
I'm not wanna call string.match(/pattern/) again if the match is statement is true
Isn't there a way in JS like in PHP to define a var inside the statement I can use if statement is true?
Like if(result = string.match(/pattern/)) { result }
my question?
where? like, what is sending that connection message?
is it a website? a game of yours? another bot?
It's not a "connection" message. Just a message received due an emitted event
I get it, but what is triggering it?
couldn't you just send a json payload instead of a direct message?
{
message: "Player #4 Player name (3) (1.2.3.4:2304) connected",
id: 123,
name: "Player #4",
ip: "1.2.3.4:2304"
}
something like that
then get the attributes directly in the code
oh you are, your formatting is just crazy
@boreal iron if(a = something()) a you want to do this in js or in php?
i cant with this formatting, i cant even tell whats going on
Well, after creating it, I can't delete it @solemn latch
because in js it works fine like that, in php i didnt test
I can't delete it gets stuck in creation limit
nope, the message is an event reveived due a socket connection to a game server, the game server's protocol send the message and it's impossible to change the message
ah, now we're talking
@boreal iron
if(a = something()) ayou want to do this in js or in php?
@quartz kindle lmao wanna know if that's possible in JS, like in PHP?
can we get data of the user from the game he/she is playing?
oh
i dont see a delete or send propery for a WebhookClient @quick ridge
https://discord.js.org/#/docs/main/stable/class/WebhookClient
didn't test this out yet, lol
what is that so ?
that's a delete for the webhook itself
your not deleting your webhook, your deleting the webhookclient
there are diffrent ?
yeah
it works fine just like that
@quartz kindle Doesaneed to be defined outsite the statement? Guessingif(let a = function()) awill trigger an error...?!
webhook is the endpoint
webhookclient is what interacts with it
it's like a car and a driver
without a car you can't have a driver
So what should I do to avoid getting a create webhook limit
but you can have a car without a driver
When I use !play, my bot enters the voice channel but does not play the music:
Error: input stream: Status code: 429```
@boreal iron yes, it needs to be defined outside
looks like you got ratelimited
ok
alright
await m.clearReactions();
Why this line get me this error
So what should I do to avoid getting a create webhook limit
@quick ridge in my code I made a getOrCreateWebhook method, to put it in simple terms:
getOrCreateWebhook(String name) {
//see if a webhook with the specified name exists
if (exists) {
return webhook.client
} else {
//create webhook
return webhook.client
}
}
sorry, idk how to write pseudocode
this way you'll have only one webhook for each name
pull.config is undefined
where did you get that from
@solemn latch i whrite this in v11
undefined doesn't have a name property
v11 is deprecated
But now i change it to v12
v11 is as deprecated as lobotomy
okay, clearReactions doesnt exist in v12
one does not simply use v11 code in v12
Idk why this problem is comes
@humble wasp did you try
pull.name
I believe you need to use the reactionManager.
https://discord.js.org/#/docs/main/stable/class/ReactionManager
I believe you need to use the reactionManager.
https://discord.js.org/#/docs/main/stable/class/ReactionManager
@solemn latch thank you
@humble wasp did you try
pull.name
@Robot.ReVa💛✨#9368
pull.aliases is undefined
@humble wasp can you show me the command handler?
yoo, I got a quick question, how to check if a certain user in a guild is? (I wanna make a req giveaway system)
make sure every command has an .aliases or check if it is defined before running that line @humble wasp
if a certain user in a guild is what
This problem has come when i added this command
if (pull.aliases && Array.isArray(pull.aliases)) { pull.aliases.forEach(alias => bot.aliases.set(alias, pull.name)); }
@humble wasp use this
where
Wait
@humble wasp remove this 3 line
And replace it to
if (pull.aliases && Array.isArray(pull.aliases)) { pull.aliases.forEach(alias => bot.aliases.set(alias, pull.name)); }
it worked but
@humble wasp what?
@humble wasp replace line 22 to
let props = require(`./commands/${f}`);
Right my wrong
Instead of all that just do
jsfile.map(file => {
let command = require(`./commands/${file}`);
bot.commands.set(command.help.name, command), (command.help && command.help.aliases || []).map(alias => bot.aliases.set(alias, command.help.name));
});```
No not all
Lines
@humble wasp no
Are you trying to make a help command?
Yep
Say less
?
Did you replace in line 21?
yes
Show me
message.channel.send(client.guilds.cache.get("773311952247062549").emojis.cache.map(x => x).join(' '));```
Can I set a limit on how many it gets? I only want 10
sublist
everybody looks offline while checking user's presence. any ideas why?
no GUILD_PRESENCES intent enabled
const data = role.members.map(m=>`${m.user.tag} (${m.user.id})`).join("\n"))```
For some reason this code is not showing the all members who have the role, why?
@humble wasp thats in the help command right? and help command is already in the commands folder? i suggest you learning relative paths AND also javascript atleast the basic knowledge.
return message.author.send(fs.readdirSync("./commands").map(command => {
let getCommand = require(`./commands/${command}`);
return Object.entries(getCommand).map(entry => entry[1] ? (entry[0] + ": " + entry[1]) + "\n" : "").join("\n");
}).join("\n"));``` all that could have been this line @humble wasp
@stable eagle It only shows the cached members
@earnest phoenix what is the cached member?
discord.js has managers since the v12 update, it caches everything but slowly
message.channel.send(client.guilds.cache.get("773311952247062549").emojis.cache.map(x => x).join(' '));```
> Can I set a limit on how many it gets? I only want 10
Array.prototype.slice()
discord.js has managers since the v12 update, it caches everything but slowly
@earnest phoenix about this my bot have a 100 user in 250 server 😂
What if I want to divide the total number by 10 like send 10 then send 10 again until done because if i send more then x amount it will be smaller
I got 350k users in 187 servers
@earnest phoenix ive got too
Bot bot don't show user
I type
client.users.cache.size
You have to reduce member count instead of using cache to measure user count
What if I want to divide the total number by 10 like send 10 then send 10 again until done because if i send more then x amount it will be smaller
What if there are 150 roles?
this code is right
client.users.cache.size
@boreal iron depends, not for regex xD
@solemn jolt Not for getting all users
@earnest phoenix how i can get all user?
<client>.guilds.cache.filter(g => g.available).reduce((acc, current) => acc + current.memberCount, 0).toLocaleString();```
Ok thank you👍
@quartz kindle
rcon.on("message", async function(msg)
{
console.log(msg);
let time = Math.floor(Date.now() / 1000);
let matches;
msg = msg.trim();
if(matches = msg.matchAll(/(\d+)\s+(.*?):(.*?)\s+([0-9]+)\s+([A-Za-z0-9]{32})\(.*?\)\s(.*)|([0-9]+) players in total/gm))
{
for(let match of matches)
{
console.log(match);
}
}
if(matches = msg.matchAll(/Player #([0-9]+) (.*) \((.*):(.*)\) connected/gm))
{
for(let match of matches)
{
console.log(match);
// process takes ~ 10s
}
}
}
Am I correct... since it's an async function if I receive a message matches pattern 2 (...connected) taking around 10s to process, I can meanwhile reveive another message?
Big bruh moment
no the code to process the data will take a few seconds
what does the code do?
not interessting in this case
it depends on the code
just checking and processing a huge amount of data
if the code is sync, it will block the process, regardless if inside an async function or not
What does that if statement even do
What does that if statement even do
Just the fastest example I could write, Voltrex
div.others {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
}
if the code is sync, it will block the process, regardless if inside an async function or not
@quartz kindle hmm, the code will check and validate the regex group matches, and fetches/saves some stuff from/to the database
Can you show what the regex is supposed to match for example
sure one example RCon admin #9 (1.2.3.4:59603) logged in
It's receiving event messages prodcasted by the remote connection to a game server
It triggers a hell lot of events, players connecting/disconnecting, admin messages, player messages, server status... etc. all being prodcasted to all active remote connections
as long as the database is async, it should be fine
not at this point yet... but ok
async more like the future
trying to convert the whole project from PHP to node, since PHP can't handle async
anyone help me :/
PHP is stupid lmao
and processing lots of messages will cause PHP to miss messages
lel you're just to young... it isn't
crying

Does string.explode() not look like a joke to you

not gonna make fun about the function names lmao
ejs or pug which one should i go for
ejs
anyway...
rcon.on("message", async function(msg) as long as all processes are inside the async function are async, too I'm still receiving messages
it doesn't let node wait until the process inside the async is done
hmm?
Do you like, want it to await one function until it's done then go to another?
nope, god... no
Wot
imaging receiving 10 messages per second, which takes a few seconds to process each and the code would need a promise for each
or 100 messages per second
or more
i just had it fixed wtf
Do you like, want it to await one function until it's done then go to another?
@earnest phoenix As saidrcon.on("message", async function(msg)needs to handle like lots ofmsgper second and needs to process the dataasync(not waiting for the code to end,success)
What exactly doesn't work?
@earnest phoenix -close in ticket does nothing but returns that error
@sand dune Do npm ls discord.js
Isn't it client.user.setPresence({ activity: { ... ? Not familiar with djs
client.on("ready", () =>{
client.user.setPresence({
activity: {
name: "Use f!help",
type: "PLAYING"
}
});
});```
aye it is lmao
@earnest phoenix As said
rcon.on("message", async function(msg)needs to handle like lots ofmsgper second and needs to process the dataasync(not waiting for the code to end,success)
@boreal iron Umm, using async in a function that does not resolve a promise is redundant and has not effect, i don't think this will solve, whatever issue you're having
Well then... how would u do it?
Imagine rcon.on("message", function(msg) { process msg }); will receive like 100 messages / second... the processing takes a few seconds
How to get it async?
hwo do you set the status to "listening"?
iirc only WATCHING is not available
hi
does anyone know how to insert an image with html?
i dont know html but im trying to submit my bot on top.gg and i want to add images
<img src="url" alt="" />
thank you
alt = name if url not found
@boreal iron Processing 100 messages with a sync function is still better, making it async might not be a good idea or just use an efficient code
However, sync or async you can't make this faster
I fear missing a message if the process takes too long
1 sec getting another screenshot
it worked
It can't miss a message
Any help?
i cant remember which is it thats whitelisted
It can't miss a message
@earnest phoenix huh... that's what I don't understand at this point, coming from PHP lmao
All activity types are PLAYING | LISTENING | WATCHING | STREAMING | COMPETING
is there a way to get an image from my pc to google so i can use it in my html
All activity types are
PLAYING | LISTENING | WATCHING | STREAMING | COMPETING
@earnest phoenix i dont think COMPETING is one
if so thats new
theres one that cant be used on normal user accounts, i cant remember which
It's
@boreal iron Node can't miss processing any message unless the event wasn't emitted which can't be the problem of your code
Watching is still possible
Hey shitass, wanna see me speedrun "proving you wrong"
without mods? bet
Could someone help me?
It can't miss a message
@earnest phoenix Another issue I didn't tell u yet is, at the time the message is received, I'm creating a timestamp which is important to process the message
With a sync function I would receive the first message for example - takes a few seconds to process - then the next message.
But the 2nd message would have a "wrong" created timestamp since the code needed to wait until message 1 is processed.
#381870553235193857 message @earnest phoenix
i need help with the bot getting role data
That's why I thought an async function in this case would solve this issue
Processing all incoming messages at the same time
@opal plank Were you talking about user accounts?
I thought you were talking to the guy who asked about how he can set the listening activity to the bot
Like bots can't set watching activity
But you meant user accounts
oh so you're not selfbot? list every discord feature.
i knew it was whitelisted for WATCHING, but i couldnt remember where
🗿
pls help me fix this shit
div.others:after {
content: "";
display: table;
clear: both;
}
div.box {
margin: 10px 0px;
user-select: none;
font-weight: 600;
max-width: 300px;
float: left;
width: 33.33%;
}
Sorry can't unfuck CSS
cant fuck with CSS 2
it is 3*
can't list every discord feature with CSS 42
sorry another dumb question
@earnest phoenix Another issue I didn't tell u yet is, at the time the message is received, I'm creating a timestamp which is important to process the message
With a sync function I would receive the first message for example - takes a few seconds to process - then the next message.
But the 2nd message would have a "wrong" created timestamp since the code needed to wait until message 1 is processed.
@boreal iron Timestamps created is always correct, they run on different contexts which isn't related to the first one being processed
how do i edit the image size in html
<img src="https://cdn.discordapp.com/attachments/756294834226069557/773995599677620234/unknown.png" alt="" />
<img src="https://cdn.discordapp.com/attachments/756294834226069557/773995738349961226/unknown.png" alt="" />
<img src="https://media.discordapp.net/attachments/756294834226069557/773995822265663488/unknown.png" alt="" />
<img src="https://cdn.discordapp.com/attachments/756294834226069557/773996024770723840/unknown.png" alt="" />
<img src="https://cdn.discordapp.com/attachments/756294834226069557/773996268841598986/unknown.png" alt="" />```
Add attribute width and height
is it an int?
No
like 69px
see the thing is
Timestamps created is always correct, they run on different contexts which isn't related to the first one being processed
@earnest phoenix Well nope, thought so, too tested it and nope, the timestamp is effected
using discord as CDN has to be some of the worst ideas you can have
fit to what?
https://cdn.discordapp.com/attachments/272764566411149314/773998718784634970/unknown.png
Could someone assist me please
U cant use JS
i was talking to @harsh blade
Put a line break after each image
but yeah i dont want the images to be all over the place
Oh if you want them to be aligned it would be more efficient to use css and create a column flex box or something
the error ocurrs when using the command -close
Whatever ur doing .roles on is null
@earnest phoenix
rcon.on("message", function(msg)
{
let time = Math.floor(Date.now() / 1000);
let matches;
msg = msg.trim();
if(matches = msg.matchAll(/(\d+)\s+(.*?):(.*?)\s+([0-9]+)\s+([A-Za-z0-9]{32})\(.*?\)\s(.*)|([0-9]+) players in total/gm)) ...
If let's say the first received message takes 10s to process, the 2nd incoming message would have a timestamp + 10s, which is not correct if for example the 2nd message will be received 1s after the first one
Whatever ur doing .roles on is null
@tame kestrel i think the issue is with line 12
That's the issue I have to deal with... thought async would solve this
@harsh blade i already told you before how to fix it
let role = message.guild.roles.find(r => r.name.toLowerCase() == config.Ticket_Support_Role.toLowerCase());
@harsh blade i already told you before how to fix it
@quartz kindle It broke again without any modifications
use member instead of message.member
@quartz kindle So just member.roles.sort
@boreal iron async only enables asynchronicity, it doesnt automatically convert your code to async
hmm that's what I need to figure out how to deal with
i'd need to see the code in question lol
there's no code more yet, as I said I'm converting it to node atm
There's no solution to deal with this issue in PHP, that's why I'm moving to JS
let's say inside the statement if(matches = msg.matchAll(/(\d+)\s+(.*?):(.*?)\s+([0-9]+)\s+([A-Za-z0-9]{32})\(.*?\)\s(.*)|([0-9]+) players in total/gm)) there are 1000 lines of code taking around 5s to process the message
of course only if statement is true
Thank u sm tim
now imagine 2nd and 3rd message are incoming at the same time
the statement will also be true for example and each message needs 5s to be processed also
[
'   
]```
How would I only get emoji I want to put them into new array because
array.push(client.guilds.cache.get("773311952247062549").emojis.cache.map(x => x).join(' '));
that put everything in one element of array
Wot
put array.push into the map
like ['
' ] instead of one emoji per element
oh
that's what happened
wait so
I don't want that and I tried that it didn't work correctly
what do you want it to be?
your only pushing one thing, you need to push for each element
One emoji in element of array
I wanna be able to do more then that
[Wot]
with documents looking like ```js
{
arrayObj: [{ IDs: ["123"] }]
}
how would i be able to find with a query if IDs has a particular ID?
array.push(client.guilds.cache.get("773311952247062549").emojis.cache.map(x => x).join(' '));
is only one element
Because you're joining them
^
oh
@boreal iron it really depends on what the code will do. If its gonna be some super complex math or whatever, then its gonna lock everything up yes, unless you manually split it into parts by using setImmediate, but most likely you will be making IO operations like disk and network, those when run asynchronously wont lock the main thread, so you will be fine
@quartz kindle @earnest phoenix nvm async is working as it should lmao
Anything wrong w line 11
@earnest phoenix oh yeah forgot to specify lol
okay so I removed join and it now returns the huge object/collection
@harsh blade yes, thats not how find works
it really depends on what the code will do. If its gonna be some super complex math or whatever, then its gonna lock everything up yes, unless you manually split it into parts by using setImmediate, but most likely you will be making IO operations like disk and network, those when run asynchronously wont lock the main thread, so you will be fine
yeah atm the code emittes the next message, the timestamp is called
logged it now and it's correct
@harsh blade https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
any other ideas?
yes
@quartz kindle
rcon.on("message", async function(msg)
{
console.log(msg);
let time = Math.floor(Date.now() / 1000);
let matches;
msg = msg.trim();
if(matches = msg.matchAll(/(\d+)\s+(.*?):(.*?)\s+([0-9]+)\s+([A-Za-z0-9]{32})\(.*?\)\s(.*)|([0-9]+) players in total/gm))
{
for(let match of matches)
{
setTimeout(function() { console.log(time); console.log(match); }, 10000 );
}
}
if(matches = msg.matchAll(/Player #([0-9]+) (.*) \((.*):(.*)\) connected/gm))
{
for(let match of matches)
{
setTimeout(function() { console.log(time); console.log(match); }, 10000 );
}
}
}
Hmm the timestamp is correct and is called right at the moment the message is received even if the message needs (like in my example above) 10s to process
message.author is not working. Error: 404 not found
"caxinha" is my client
@boreal iron setTimeout doesnt block the code
if you want to intentionally block the main thread, use a while loop lmao
let time = Date.now() + 10000;
while(Date.now() < time) {}
aye
ahh np the server can handle stress
.
dotpost
Guys i need a host pls
yourself
do you know how little that narrows it down? @lapis furnace
its like asking for a website
guys, give me a random website pls
For the bot
Ya
24/7?
none of the above?
Digital Ocean or preferably AWS
those are the ones i'd stick with
Hmm
@quartz kindle
rcon.on("message", async function(msg)
{
console.log(msg);
let time = Math.floor(Date.now() / 1000);
let matches;
msg = msg.trim();
if(matches = msg.matchAll(/(\d+)\s+(.*?):(.*?)\s+([0-9]+)\s+([A-Za-z0-9]{32})\(.*?\)\s(.*)|([0-9]+) players in total/gm))
{
for(let match of matches)
{
while((Math.floor(Date.now() / 1000) - time) > 10) { }
console.log(time);
console.log(match);
}
}
if(matches = msg.matchAll(/RCon admin #([0-9]+) (.*)/gm))
{
for(let match of matches)
{
console.log(time);
console.log(match);
}
}
});
1st msg matches statement 1
2nd msg matches statement 2
Shouldn't 1st msg log it's match to the console after 10s?
Imma see
If u need free n good dm me
definetly check AWS before
and then get your token stoles

free and good no exist, sorry
free and good no exist, sorry
@opal plank Awh ok ill shut down my company then :c
XD
Dm
so you hosting one bot and now is a trustworthy company?
@opal plank More like 20-30 atm
and around 20 mc servers too
still small for what a big company is
i wouldnt trust a small host
specially one that claims to be free and good
@boreal iron < 10 not > 10
@quartz kindle hmm still same result... that's weird at this point
im not even gonna reply to that
@quartz kindle Using while(true) stops the code at this point (to test of course), shouldn't it still receive the next message if async?
oh but assuming as mentioned above the code takes like 10s would probably lock the thread, too
as i said, the code itself needs to be async
ok, taking my example above, how so?
you know about the event loop right?
aye
node.js runs on a big event loop
on every iteration of the event loop, all the js code that needs to be run will be run
yeah that's the reason I have to switch from PHp for this case
once it completes the entire code, it goes to the next iteration and repeats the process
yeah... so I'm gonna need async database requests
@lapis furnace there are some really good tutorials on how to get a free host from WornOffKeys
When I do )send bruh it doesn't print anything:
@client.command()
async def send(ctx, *, message):
if ctx.author.id == 726230248315813919:
await ctx.message.delete
await ctx.send(message)
else:
await ctx.send('Command not found.')
when your js code is synchronous, like while(true), the event loop will not exit until it finishes running the current code
so it locks while its waiting for the while loop to complete
the entire loop never proceeds until it does
yeah ok makes sense now
when you create async code
what it does is it marks it as a code that will "complete later"
so the event loop starts the async function until it reaches something that tells it to wait
when it does, it stops there, and continues to the next iteration of the event loop
and on every iteration it will check the asyn function again to see if now it is allowed to continue or not yet
Alright thx for the explanation
when the presence array is one, ti detects fine, when its multiple, somehow it doesnt trigger, only when the game ends?
so for example, if you do await new Promise(r => setTimeout(r, 5000))
exbrain pls
that will tell the code to wait come back 5 seconds later
so the code will basically be "can i run it now? no? ok. can i run it now? no? ok", as the event loop continues
until 5 seconds pass, and it can finally conitnue the function
@earnest phoenix what language is that
python
break should escape the scope
the only way i see it could do that is if the name is not exactly that lmao
my only assumption is somehow user doesnt exist
it always is though
ive been logging it
i did get a null user at one time though
console.log presence.activities
@quartz kindle yeah and that’s my current issue with PHP - as it is of course not the right language for this purpose anyways -
It’s running an endless while loop as long as the socket connection is active and fetches each incoming message but if a message is incoming and the code still processes the previous one it just doesn’t react and the event message is missed forever
the name is fine
i see that user can return null but that'd be if the user is not cached /
so it makes no sense to bork that way
@boreal iron that shouldnt ever happen, unless php is really that shit
because if the thread is locked, the underlying network layer will wait for it
the machine's network driver wont feed it data until it can process data
There’s not such an event loop
There are frameworks like react PHP supporting this but not raw PHP
That’s why I’m moving this particular project to JS
As long as the process::input (the incoming message) is being processed or read/written all other incoming input is lost
Like u would open a file, putting a not-writeable on it’s settings and try to open and write the file meanwhile in a different editor