#development
1 messages · Page 547 of 1
not against tos, just unwanted I believe
It's all up to the server owner if they want to do that or not
It will only grab me the link to a single server
I tried to do your method but returns the same result
Turtle i am alright with that, and I can handle the errors without perms.
I'm just not that expirienced and I would like to add that to my bot for my use only.
I'm not one to try and get spoonfed, but I would love to have this in a bot, and I do not know how.
No
I work on this with another user
They do not know how to make what I am asking aswell
and They normally are the ones to make commands while im at work
Its discord.js right
yes
you should probably read up on this https://www.w3schools.com/js/js_arrays.asp
Alright so .map returns an array, look at this website https://www.w3schools.com/js/js_arrays.asp
Oh
Beat to it
great minds think alike.
some examples combine webdeving and js but you'll get the gist of it
I got the gist
Instead of just sending it, you should assign it to a variable to access it later
Do you think someone has made this before?
Cause my main dev set the whole bot up, I just edit the code
Mostlikey, but making it your own way give valuable skill and lessons
https://discord.js.org/#/docs/main/stable/class/TextChannel in here you can find out how to make invites aswell
That would work, or create invite which you need permissions for.
I didn't see createinvite on d.js docs.. maybe I over looked it, but swear ive seen it before
Quick question. Anybody know the URL format for jumping to a message in a server?
nvm im blind
console.log("(client.user) Ping")
why is not there the username
what
i like : when a user send Pong -> and that goes to the Consol with his name
username
@earnest phoenix
console.log(`${client.user.username} Ping`)```
thx

it dosent works
show code
sendconsole: function() {
console.log(${client.user.username} Ping)
}
}
module.exports = {
sendconsole: function() {
console.log(${client.user.username} Ping)
}
}
that is the code
like this ```code here```
there is no client in that function
the module cannot see client
you need to specifically pass something to it
Eef
for example
function(text) { console.log(text) }
then in the other file yourfunctionname(text you want to console log)
k
or put your function in the same file as your client
k i make it but there stand dosent his name
in console : LS-Gangwars Ping Ping
Error: Couldn't find an Opus engine.
client.on('', message => {
if $ip,$port
$ip=84.200.101.107
$port=22005
if (true) {
if (message.content === 'server online'){
}
}
};
}
why
???
wut
you're putting... not js in js
why do you have ips and ports in a client on message
no one knows
@earnest phoenix looks like you're putting non-js code in js
which obviously wont work
pls just learn js
or pick a different language but stick to it

I am using Html and Css to make buttons and some of my buttons are not appearing and I don't know why
Code for Css File: https://paste.tscforum.com/ndwnwgruzj.css
Code forHtml File: https://paste.tscforum.com/xxlsbgkgej.xml
I may be dumb and just missing what is causing the error but please, help :>
it is the websites syntax detection
it is not acccurate ig
accurate
Also
Omg
I can't believe I didn't notice that extra </a>
It still isn't showing up though
line 9 of your css
missing ;
line 15 and 34.. and 60 something
or last lines dont require?
I pretty sure they don't but I could be wrong
I dont think they do now that I think about it
I dont see any issue.. idk if XML is messing with it
its saved as xml
Yea
I don't see why that is needed
but ok
Yea
That didn't help
@mental solstice Do you even know Html?
I know a fair bit lol I dont see why it's not working.. so I assume try thing
is it because the css puts the button off the page?
It shouldn't be off page
I already did the measurements with the first button
and adjusted them accordingly
comment out the css for button tag and see if it shows up
I have already made it just a nomral button without any color or change of possiont
position*
the button still won't pop up
no idea then.. have it hosted anywhere?
Nope
I am doing it all from my pc
Unless
Fuck me
I hope my friend stopped hosting it when he looked at it
:/
can you put this on codepen for people
if(command == "lb") {
db.startsWith(`guildMessages_${message.guild.id}`, { sort: '.data'} ).then(resp => {
resp.length = 10;
let finalOutput = '**Leaderboard:**\n\n';
for (var i in resp) {
finalOutput += `${client.users.get(resp[i].ID.split('_')[2]).username} -- ${resp[i].data} messages`;
}
message.channel.send(finalOutput)
});
}
``` can someone help me with this code
I didn’t see any mistakes but it didnt give me a message leaderboard
its not approved yet, but i have another one named @earnest phoenix
@earnest phoenix
fiqstro does your command have your prefix added in? or does that need to be added In front of "lb"
My command had my prefix added in
@earnest phoenix (cc @keen drift) thats a bug in channels where you dont have the use external emojis permission
?
Oh you saw that?
Reported by Tarek1337#0379
Steps to reproduce:
- Join a server that has "Use External Emojis" revoked for @everyone
- Open the emoji selector and scroll all the way down
Expected result:
All the emojis should be in the correct category
Actual result:
The emojis ...
13
P3: Will get fixed eventually, Mid
client.on('message', message => {
if (message.content === 'how to embed') {
const embed = new RichEmbed()
.setTitle('A slick little embed')
.setColor(0xFF0000)
.setDescription('Hello, this is a slick embed!');
message.channel.send(embed);
}
});
it doesent works why 😦
It'd be nice if you gave us the console output or error :+1:
Oh
Wait
I see
Look at the constructor for a rich embed
There is nothing wrong with that?
const embed = new RichEmbed() is wrong unless you require RichEmbed as discord.js
the proper constructor is new Discord.RichEmbed()
no
if you do ```js
const { Client, RichEmbed } = require('discord.js');
then new RichEmbed is corrct
Did you read my message?
theres nothing "improper" about that
unless you require RichEmbed as discord.js
well you implied that new richembed is improper
it is, unless you for some reason require RichEmbed as discord.js
"for some reason"
its cleaner
theres nothing wrong with it its just a different style
Normally, you just do const Discord = require("discord.js")
just because someone else does something a different way than you doesnt mean their way is wrong/improper/abnormal
Never said it was?
Now the edit
makes it correct
I guess the word "unless" doesnt matter?
Either way before this escalates Im going to bed
lmao k
What is wrong with this code
if(command == "lb") {
db.startsWith(`guildMessages_${message.guild.id}`, { sort: '.data'} ).then(resp => {
resp.length = 10;
let finalOutput = '**Leaderboard:**\n\n';
for (var i in resp) {
finalOutput += `${client.users.get(resp[i].ID.split('_')[2]).username} -- ${resp[i].data} messages`;
}
message.channel.send(finalOutput)
});
}
you tell me
which library is db coming from? is db.startsWith even a thing? also resp.length = 10 is not really doing anything, thats not how you limit the length of an array
@quartz kindle it’s from quick.db
alright, so assuming the db is getting what you want correctly
just remove the resp.length and do js for(let i = 0; i < 10; i++) {}
instead of for in
So ill delete resp.length
And replace (var i in resp) with
(let i = 0; i < 10; i++)
he wants to iterate over 10 items only, not all of them
would be logical to filter that on the db query
for of and break
using what code
console.log(resp)
it may happen that your db will return less than 10 results
so you will need to check for that too
Where do i put that
for(let i = 0; i < (resp.length > 10 ? 10 : resp.length); i++)
well, according to the quick.db docs, the startswith function returns all matching entries
no option to limit
How about console.log(resp)
console.log(resp) is just for you to see in the console the results of the db
Oh kk
you can put it anywhere after resp is defined
It works fine but still the problem i had at start
whats the problem?
show the result of console.log(resp)
before the for
then your db is empty
either you're not inserting data in it correctly, or you're not retrieving data from it correctly
oh god this is a wrapper for mysql
Can you check my code again see if i did simething wrong with the data

no its sqlie
you can try db.all()
instead of db.startswith
to see if there is anything at all in your db
hecc sql in general then
Ok
@keen drift atleast it isnt discord-economy
What lib are you using
weird lol
oh I see the sqlite wrapper
Ik
I don't see the point to quick.db but that's a talk for another time
@quartz kindle it doesn't return a promise I think
i havent used quick.db either, so idk what else
if it doesnt return a promise, it would throw on .then() no?
he said its throwing on .all()
you could try it without .then()
bc usually it'll complain saying it's not a function if it doesn't return a promise
And u use .then
@knotty steeple what's that
yeah but it should say .then() is not a function not .all() is not a function
Kek
and is also sqlite
didnt work either
Npm never ceases to amaze me
I even followed a video tutorial online for the command (because im new at quick.db)
Still doesnt work
Step 1.

Never follow videos
they can be outdated
Did the video say use quick.db
try doing condole.log(db.all()) at the beginning of your bot file, right after you define db
and see if it shows up in your console when your bot starts
@keen drift I'm gonna bet it did
Also that community is full of people who need spoon-feed
I've been there before and I think I'm probably banned
They got made at me for telling someone to learn js
plexi?
yes
Didnt send a thing
hmm, are you trying to do any guild changes?
@quartz kindle const db = require('quick.db')
@earnest phoenix the owner of the bot app needs to enable mfa
@earnest phoenix so you didnt create a table?
if i understand the docs correctly, you're supposed to work primarily on tables: js let table = new db.table('tablename'); table.set/get/all/startswith/etc()
hmm ok
Can I get a webhook only with his name?
Wut
For those who have a Raspberry Pi, do you know why after a while the program stop ? (I'm using Python)
I mean, even changing IDE or executing the command from the terminal the program stop without marking any message.
Not happening for my bot
I'm on a pi 3
With thonny
It's had basically 24/7 uptime
I have Pi 3 too, I wondered if it was not because I was in wifi and I lost the connection. I noticed that by uninstalling teamviewer my bot stayed longer connected.
As a result, I hesitate to buy an ethernet switch to connect my raspberry pi by cable.
Thank you for your answer
I will first test cable to see if my bot does not stop anymore. If so, I will consider buying an ethernet switch.
Okay
@earnest phoenix try db.fetchAll()
How do I find out in a on_message_delete who deleted the message?
can someone help me with my websites navbar
on the main page
its offset for some reason
but on the commands page its not
@earnest phoenix you cant
and font is broken too
@earnest phoenix Check audit logs when the message delete event is triggered
Yeah I have tried figuring out how to get into audit logs, but I cant find it in the API reference
What discord library are you using?
Python
if(!message.member.hasPermission("MANAGE_GUILD")) && message.author.id !== settings.owner return message.channel.send("`You must have 'MANAGE_GUILD' permission to use this command`")
Alright so, that code works and denies usage to a command with someone who doesn't have permissions.
But how could I insert some code, that allows the Bot Owner to use the command without needing permissions.
I currently have a setting for the bot owner: https://totallynotavir.us/i/otd9.png
So settings.owner should be the name to put in there, I'm just not as expirienced
use &&
!message.member.hasPermission("MANAGE_GUILD") && message.author.id !== settings.owner
It's in the settings.json
So mental: ```js
if(!message.member.hasPermission("MANAGE_GUILD") && message.author.id !== settings.owner) return message.channel.send("You must have 'MANAGE_GUILD' permission to use this command")
That should work?
Also the language is js
You need a closing parenthesis
What about now
Yeah, you need to have settings defined in that command file
Doesn't matter
wouldnt u want || instead of &&
if they have manage guild.. but arent owner.. it will say u need manage guild
Because it’ll only invalidate if they have both of them
Just replace && with ||
When checking if something isn’t something else and you want to see if they don’t have either of them you need to use or (||) only use && if you’re doing it when you want it to work if they’re true.
since they are using ! operators on both expressions && turns into ||
it gets inverted
so in that situation using || would mean you are actually doing &&
@mental solstice @slim heart
That’s what I was saying above
That if ur saying is somethings fade use || and if ur testing if somethings true use &&
Someone know how to get bot guilds size with jda? jda.getGuilds().size() doesn't work :c
Length doesn't exist for an array in java :c
oh ok
Oh i just found, i need to wait the bot to be ready x)
length does exist for arrays
but getGuilds() returns a list
also, it's better to do getGuildCache().size() instead
getGuilds() creates a copy
in general, using getXCache() is better than getX()
it's either more efficient or at least as efficient as getting the list
Okay thanks 😃
node canvas is driving me crazy
whats the issue?
its will not install i fallowed the install guide but npm will not install it
have you installed the dependencies?
yes
are you on linux or windows?
windows
did you install node-gyp, GTK2 and libjpeg-turbo?
How do i make a Server Check with JS
tes
yes
Do hava anybody a nice Embed?
I dosent find a cool one
whats the errors you're getting chosenone
library
lmao
discord.js most likely
jeah bot.js
:)

😑
or you can use the embed option here when sending a message https://discord.js.org/#/docs/main/stable/typedef/MessageOptions
i never use richembeds 
@quartz kindle Warning: Missing input files:
C:\GTK\bin\libpangoft2-1.0-0.dll
C:\GTK\bin\zlib1.dll
C:\GTK\bin\libintl-8.dll
C:\GTK\bin\libgmodule-2.0-0.dll
C:\GTK\bin\libglib-2.0-0.dll
C:\GTK\bin\libexpat-1.dll
C:\GTK\bin\libpng14-14.dll
C:\GTK\bin\libcairo-2.dll
C:\GTK\bin\libfontconfig-1.dll
C:\GTK\bin\libgobject-2.0-0.dll
C:\GTK\bin\libgthread-2.0-0.dll
C:\GTK\bin\libpangocairo-1.0-0.dll
C:\GTK\bin\libfreetype-6.dll
C:\GTK\bin\libpango-1.0-0.dll
C:\GTK\bin\libpangowin32-1.0-0.dll
not installed properly?
i guse but there so many ways to install GTK on windows
You will need the cairo library which is bundled in GTK. Download the GTK 2 bundle for Win32 or Win64. Unzip the contents in C:\GTK.
link
thanks
client.on('message', message => {
if (message.content === 'TeamCommands') {
const embed = new RichEmbed()
.setTitle('TeamCommands')
.setAuthor("New Update!", message.author.avatarURL)
.setDescription('Test')
.setFooter('Test')
.addField('Test')
.setFooter('This is work')
.setColor(0x820000)
message.channel.send(embed);
}
});
->
undefined
New Update!
TeamCommands
Test
Test
undefined
This is work
but why undefined
the .addField needs to have 2 args
You gotta learn the basics dude
Yeah i know but it doesnt works 😦
Yundo because it needs to have 2 args
if (message.content === 'TeamCommands') {
const embed = new RichEmbed()
.setTitle('TeamCommands')
.setAuthor("New Update!", message.author.avatarURL)
.setDescription('Test')
.setFooter('Test')
.addField('Test')
.setFooter('This is work')
.setColor(0x820000)
message.channel.send(embed);
}
});```
You see that
Look
You have two set footers
client.on('message', message => { if (message.content === 'TeamCommands') { const embed = new RichEmbed() .setTitle('TeamCommands') .setAuthor("New Update!", message.author.avatarURL) .setDescription('Test') .addField(Test, 1, [inline=true]) .setFooter('This is work') .setColor(0x820000) message.channel.send(embed); } });
use this
This guy doesn't know anything
I suggest you learn a language before you decide to make something
^^
@quartz kindle i am getting this errror now
gyp ERR! command "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "build" "--fallback-to-build" "--module=C:\Users\TheUnChosenOne\Desktop\MogBotUpdate\node_modules\canvas\build\Release\canvas-prebuilt.node"
"--module_name=canvas-prebuilt" "--module_path=C:\Users\TheUnChosenOne\Desktop\MogBotUpdate\node_modules\canvas\build\Release" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v67"
why is your nodejs folder in program files x86? did you install 32bit node?
i did not relise i install 32bit
@earnest phoenix when they use [] in the docs, it means those arguments are optional 👀
You don't just copy that xd
Hey, I am new to this whole developing thing, so I was wondering, what would I add to the kick command to have a reason? FYI, I a =m using Python
please help
h
Can u please help
trim the command off the kick message content and use that as your reason?
idk python.. I think in JS there is just a loop for each word. the sentence is split by spaces and put into an array
ok
Help please, how to protect the number of characters in the message?
what
like.. dont accept input larger than a certain amount of characters?
you need bot to protect the number of characters in the message and if it exceeds 3, the bot ignored the message
if message.length > 3 return;
hm
depends on the language I suppose
are u doing this in the message recieved event?
in command, prefix, I want to limit the number of characters
your prefix should be hard coded
and command names
err I guess unless u want server to set their prefix...
in theory, on each server you can set your prefix, everything works fine, the problem is only in prefixes with a large number of characters
put a limit in your prefix command
if someone sets prefix to something like "ubgouebgpuebgp", check for the input length, and if its bigger than like 3, reject it and return a message saying "prefix too long"
or something
it is clear how it is done in js
its very basic js
you can google things such as "how to get string length"
and "how to compare string length"
also google arrays and the split function, since you need to split the input
thanks, I'll try now
You guys think it would be a great idea to comment on every line explaining what it does for possibly future reference when making a multi-purpose discord.js bot?
no.
Why?
// this line sends the pong message to the server
message.channel.send('Pong!')```
just please dont
I only do that if I'm giving code to someone on stackoverflow
still
I mean something like this:
fs.readdir(config.dirs.eventsDir, (err, files) => { //Attempts to read the /Events/ Folder
if(err) return console.log(`[ERROR] ${err}`); //If there is an error doing the line above, it returns an error to the console.
files.forEach(file => { //Loops through the directory.
if(!file.endsWith(".js")) return; //If the file does not end in .js, it returns nothing.
const event = require(`${config.dirs.eventsDir}${file}`); //Requires each file so that it can load up.
if(!event) return console.log(`[ERROR] I was unable to require the event file ${file}`); //If there is a problem requiring a file, it will log it to console.
let eventName = file.split(".")[0]; //Sets eventName variable.
client.on(eventName, event.bind(null, client, config)); //Listens for new event emittions.
delete require.cache[require.resolve(`${config.dirs.eventsDir}${file}`)]; //This clears the cache on every bot restart so there is no need to use the y!reload command for events.
})});
if its literally a mulitpurpose bot i dont think the code needs to be commented
What are you making?
On the same line as it
Still
maybe for the more complcated lines, like the delete require.cache...
legit no one ik does that (comments on each line)
but for every line, fuck no
let eventName = file.split(".")[0]; //Sets eventName variable.
thats just
no
please dont
If you're hiring devs they should know what it does
But it would possibly help us in the future, maybe my devs wont know what a certain line does.
Should already know*
i doubt they dont know what a fucking let does
But if you're paying them money and they dont understand something...
I'm saying, what if they don't
If you hire someone and they cant do their own research they arent worth the money.
@amber fractal so programmers who need to use google shouldnt be hired ever?
i sent the message 0.2 seconds after you sent that ok
lol
I know, I'm just telling you to read it so people that come back to this later dont think you didnt
In short, do what you want, in other short, no.
dont comment literally every line
like cyber said lines like let eventName = file.split(".")[0]; //Sets eventName variable. dont need to be commented
delete require.cache[require.resolve(`${config.dirs.eventsDir}${file}`)]``` this is reasonable, not all people know what it would do
guys, remember that most people dont even comment their code, like, at all
i dont
commenting is always good
regardless if it looks bad or is done in a weird way
its still better than uncommented code
but no need to like fill ur entire script with comments
if he is a beginner it can be very good for him
writing down what you're doing does wonders in helping you remember
☝
i wouldnt pay a beginner to help me code
Atleast I have 1 person on my side 😂
always commenting is not a good idea
specially not something you would want to teach to a beginning
over commenting is purely unnecessary and cumbersome
My coding class said to comment what function do, not on every line tho
you meant beginner right
yes
For the record. I ain't really a beginner 😂
you should only comment your code when you believe it is necessary for a future reader to understand
Just wanna point it out there lmao
that's a good rule of thumb
Yeah like my devs?
only lines which you belive that would be hard to understand
or that are not self-documenting enough
They know similar stuff to me, i'm just worried that they will messa bout with the code they don't understand
yea
just no need to make a 1 hour tutorial through comments
if they dont know what a line does most of the time you can explain it to them
in fact, many comments may lead to more confusion
than actual help
It's not that simple samurai
it would be correct to comment in such case
uh i'd say it's viceversa
basics of programming
and logic
that's what comments are for
explaining things and making notes
Not even just a quick desc of what each line does. Maybe 3-7 Words or something?
Not detailing your entire code-base
to a point of writing more comment than actual code
I wouldn't recommend commenting each line
that's just exaggerating
if a developer couldn't understand at least a single line
experienced coders use advanced terms in their comments, then you have newbies pretending they're your most elite russian hackers when they dive facefirst into any language instead of reading docs and making beginner projects to practice first
than he/she shouldn't call himself/herself a developer at all
and that's where confusion originates from
Yes but my point is, I'm hoping that it will actually become a good bot... Like really good and that members will add it more. More guilds = more work to the bot. More comments = Better understanding of what things to change etc.
are you EA lol
?
nah they are worse
It's not really "advanced terms" just precise wording is what really matters, and sometimes words that precisely detail a situation may seem complex
☝ Was this english? 😂
your hoping it will become a good bot because all of your lines are commented?
No
^
then why are you forcing the comments
Just the bot itself will hopefully be a good bot
on every line
For future referance
so why are you making that point
let me tell you something
there is a concept called self-documenting code
For my devs. So i know what to change later on if it becomes popular
if you comeback 6 months and you understand nothing of your code
you won't get any guilds if your bot is coded in a shitty way without any knowledge of the language, and shitty projects originate from shitty knowledge
then you'll really want to work on your coding structure and naming practices
Can we keep this chill? I just asked a simple question. No need to go all parliament on me lmao
No one is judging you
Ik but I feel a bit of heat in this convo
from some people
well it does sound that some people don't use proper wording
and it does sound somewhat offensive
so I understand what you're saying
you don't need to subtalk about it, you can just refer to the person itself, which is more than likely me
It's fine lol. Okay, so a few lines that are probably hard to figure out are worth commenting? Just not the whole code?
No commenting = skill smh
yes
i barely comment my code
no need to overdo it
Getting heated over commenting 
you don't need to comment if you write readable code
Like you don't need to comment 1 + 1
Alright, thank you lol. I never used to comment my code. I was a little curious if other large bot devs comment like that... Seems as if they do not lol
good programmers wouldn't even need comments (in most situations) as their code would be self-documenting
Well
I have a 15k project and barely have around 50 comments
most devs comment their functions
Cry, what you said is just false ;-;
they comment it using jsdoc
Comments are good if you intend on letting others see source
but docs are comments so :^)
I understand
Cry, what you said is just false ;-;```

they have different intentions however
My is a project that I work on with other people? What would you recommend?
it is very different to comment every line of your code
also
than to document your functionality
even very good code can be hard to read
"you don't need to comment if you write readable code" is just wrong
eg fields added to pad for memory alignment
wow... Did I start this?
Slowly backs away hoping nobody see's him...
whats popular these days is to split your code into functions and use jsdoc, like this ```js
/**
- Download data from the specified URL.
- @async
- @function downloadData
- @param {string} url - The URL to download from.
- @return {Promise<string>} The data from the URL.
*/```
it doesn't have to be hard t oread if it is properly organized and documented
if you're a js dev your opinion doesn't count /s
try reading a lock free data structure source code
it may be, however, to those who have not mastered/completely understand what the code does
His bot is in js 
or crypto stuff
Commenting the use of a function can be good to know its use for later if you bring in other developers in the future, so they know what it a certain function does, bot not every line, thats a bit excessive.
the hardest thing to understand that I've seen is C/C++ code specially in os development, mostly because C/C++ naming conventions are somewhat vague and short
JS is best imo
because you more than likely can't understand any more complex language
bruh
Can you like not 😂
sheesh
i'm saying that as if isn't complex with inconsistencies
i mean
js implements a large amount of advanced programming concepts
i find java the best
best language is html
it may seem like a simple language however it is not
my bot is written in css
without comments maintaining that kind of thing is practically impossible
Yes
html is a programming language
'm guessing you're implementing a data structure in the code above
hypertext mprogramming language
I got another question now 😂
I see
did you make the hashing functions
or are you using a helper library
speaking of thread safety, dbl's official .net wrapper is full of deadlocks
that's java's ConcurrentHashMap
I see
so it's based upon it
I am going to be adding members to a database, without using async, what would be the best way to do it? I was thinking of like do it in the 'guildMemberAdd' event. I don't really want to do it in the 'message' event... Any idea's plox?
i have a bunch of weird old uncommented code that i hardly remember how it works
like this js for(i=0; i< 10; i++) { var arccos1 = Math.sin(h2) * Math.tan(e*Math.PI/180) * Math.tan(result.observer.latitudeGeodetic*Math.PI/180); if(arccos1 > 1) {arccos1 = 1} else if(arccos1 < -1) {arccos1 = -1}; var arccos2 = Math.sin(h3) * Math.tan(e*Math.PI/180) * Math.tan(result.observer.latitudeGeodetic*Math.PI/180); if(arccos2 > 1) {arccos2 = 1} else if(arccos2 < -1) {arccos2 = -1}; var arccos3 = -Math.sin(h11) * Math.tan(e*Math.PI/180) * Math.tan(result.observer.latitudeGeodetic*Math.PI/180); if(arccos3 > 1) {arccos3 = 1} else if(arccos3 < -1) {arccos3 = -1}; var arccos4 = -Math.sin(h12) * Math.tan(e*Math.PI/180) * Math.tan(result.observer.latitudeGeodetic*Math.PI/180); if(arccos4 > 1) {arccos4 = 1} else if(arccos4 < -1) {arccos4 = -1}; h2 = (ramc+180)*Math.PI/180 - Math.acos(arccos1) / 1.5; h3 = (ramc+180)*Math.PI/180 - Math.acos(arccos2) / 3; h11 = ramc*Math.PI/180 + Math.acos(arccos3) / 3 ; h12 = ramc*Math.PI/180 + Math.acos(arccos4) / 1.5; }
lmao
whats the reason for doing that 
add members to your database only when they execute database interactive commands
😂
and then there's crypto where nothing makes sense anymore https://javascript.is-bad.com/376b1d.png
@earnest phoenix yes
lmao
wtf
bitwise operators may seem confusing
but after mastering them it is not the case
i know bitwise ops
they are used a lot in cryptography
then why wouldn't you be able to understand the snippet
but a 150 line method that consists of nothing but bitwise ops on loops isn't the easiest thing to read
I see
@earnest phoenix However, it would mean that they would need to enter the command twice... Once to actually add the to the database otherwise it would give errors, and the second time to make it work.
I thought it was just a block
I only want to make them do it once
you can just add the user to the database before the command's actual code? ...
^
that would mean that you would have to await the database query to apply
I don't know if that would be possible or not... Using cmd handler also.
depends on the database and the helper library
Thing is, I don't use async
😦
yep
☝
It's just plain inefficient to query a database in a blocking way
tbh
Why not just add async tho
is there something bad with it?
so you might want to reconsider using async programming for that
if you must use sync, your best option is to use eventual consistency
I've literally never used it before
work on an in-memory copy of the database, and only push it to the db every once in a while
if you must use sync in js, you're screwed
^
i struggled a bit to learn how to use it properly, but after i got it down, i cant do without it anymore
Only thing I even use it for is await 
so you're not familiar with async programming
then that should be your next topic to learn
very important
so learn
await new Promise()
It's really not that hard
xD
I learned how to use async stuff from stack overflow alone
await is just syntatic sugar for .then()/.catch()
lmao
for js that is
one of my hardest concepts to grasp was that of async programming
but mostly because I never found a good guide
I like to understand things from their core, deep down, how they work internally
Wait I couldve been using await instead of setTimeout
lmao

lmao
I thought it was as simple as adding await to the beginning of a line 😂
i might be a little late but;
Clearly not 😮
Actually, I could still use a .then for this? ☝
yea you can use a callback
wow
.then returns a promise thats why you need to learn about it
Oh, it's fine. I used it already before lmao
in case you don't know, a promise is an object used to represent a pending action
Just never thought about using that
when you execute js, your code will always execute immediately, it cannot wait, there is no such thing as waiting. what an async code does, is that it immediately returns a "promise" instead of a value, meaning it will eventually give you something, but not yet, so your code continues. when your code finishes, it goes back and looks for anything that is left over, and finds there is a promise waiting, so it goes back there again until the promise finishes, then you can receive the result from the promise, and continue the code that was waiting
yeah
a promise is a value that will eventually™ be available, or will be an error
I'm not entirely sure about js, but the event loop designates execution time from action to action, it is not processed in a sequential order, that would take away the entire reason for async
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise is a good place to learn about promises and its methods
all types of async code, async/await, promises, .then(), they all rely on the "promise" value
when your code finishes, it goes back and looks for anything that is left over
that would make async programming essentially useless
let me rephrase
I understand what you meant, you just didn't phrase it properly
it finishes the code, then moves on to the next loop, and repeats any leftover/waiting code
what code?
the promises
you're still mentioning that it is done in a sequential order
So .then requires the new Promise thingy ma bob?
What about if I was to just use .catch?
js is sequential, its single thread
.then is a property of the Promise object
what node does is put everything into a neverending loop
which can be used to specify the callback of the promise once it is completed
I am aware
and executes code sequentially on each loop
it is called the event loop
But couldn't I just do this?
addtodatabasethingy.then(() => {
//add whole code in here
}).catch(console.error);
if addtodatabasethingy is a promise, yes
does that return a promise?
yeah
async functions return a Promise object in javascript
sql.run("CREATE TABLE IF NOT EXISTS userConfig (userID INTEGER, prefix TEXT, embedColour TEXT, banner TEXT, balance INTEGER)").then(() => {
sql.run("INSERT INTO userConfig (userID, prefix, embedColour, banner, balance) VALUES (?, ?, ?, ?, ?)", [user.id, "y!", "ffffff", "default", 500]);
}).then(() => {
//Do the rest here
}).catch(console.error);
```?
oof sql
ikr kill me
depends on if sql.run returns a promise
I would recommend using something like Knex.js
that's just plain painful
once your application grows, it'll become 70% sql queries 30% code
(exaggeration)
if you have hard-coded queries everywhere
Could I do this?
function userDB(client, config, userDB, user) {
//Things in database get completed.
}
//======================
userDB(client, config, userDB, user).then(() => { console.log("Finished") }).catch(console.error);
yes
you must return a promise in the userDB method however
function userDB(client, config, userDB, user) {
//Things in database get completed.
return new Promise((resolve) => {
// call resolve when you're done
resolve();
});
}
in the code should be js return new Promise((resolve, reject)=>{ blah blah blah resolve() })
if you're not going to use the reject callback there's no need to include it in the parameter list
So:
function userDB(client, config, userDB, user) {
//Things in database get completed.
return new Promise((resolve) => {
// call resolve when you're done
resolve();
}).then(() => { console.log("Finished") })
}
So something like that?
yes
Ah okay, thank you very much 😃
() => { console.log("Finished") } no need for the { }
Yeah, I would do the rest of my code in there...
yep
you can do that but
hence the {}
I see
uh
you're doing it a bit weird
if you were to do it like that that would remove the purpose of the function
or at least the result of it (Promise)
what you would want to do is userDB(..).then(() => { console.log("Finished") })
not inside it
just move that piece of code
Yeah, I specified that earlier but you guys suggested I added the Promise stuff in there lmao
yes the promise should be inside the function
ah
but the .then callback not
Would it be good to add the .catch also?
Or would promise do that? Idk xD
you're not rejecting the promise anywhere so it would be useless
rejecting is basically throwing an error inside a promise
What if there was an error, I would want the user using the command to know that there is an error
where would the error originate from tho
Nvm lmao
.then(result => {it worked}, error => {🔥})
Maybe they was not able to be added to the db?
or .then(result => {it worked}).catch(error => {🔥})
That would trigger an error in the func, kherrect?
but what is the method call
that triggers the error
or that could possibly trigger such error
what if the db is down?
I need to know which method you're concerned that might throw an error
so I can help you
if you meant sql.run, that it would depend on what sql.run returns
if it's a promise than you would have to "pipe" or so to say the error using .catch into YOUR promise
function userDB(client, config, userDB, user) {
sql.run("CREATE TABLE IF NOT EXISTS userConfig (userID INTEGER, prefix TEXT, embedColour TEXT, banner TEXT, balance INTEGER)").then(() => {
sql.run("INSERT INTO userConfig (userID, prefix, embedColour, banner, balance) VALUES (?, ?, ?, ?, ?)", [user.id, "y!", "ffffff", "default", 500]);
}).catch(console.error);
}
Further below.. (Technically in a different file cuz I use cmd handler cuz I kewl af 🔥 )
userDB(...).then(() => {
//Rest of code here
}).catch(err => return message.reply("There was an error adding you to the database???"))
OOF
otherwise you'll want to try catch the error and reject your promise
o wait
I can see that you attached a callback to your sql.run method so I'm guessing they return a promise
in such case follow my first instructions
if it's a promise than you would have to "pipe" or so to say the error using .catch into YOUR promise
Add the promise code to the func?
return new Promise((resolve, reject) => {
sql.run(...).catch(reject);
});
then you can do
userDB(...).then(() => {
//Rest of code here
}).catch(err => return message.reply("There was an error adding you to the database???"))
aaaah
there is also no need for the return keyword nor the err parameter since they're not being used at all
Okaaaaay
return and err are redundant
So complicated at this point haha
probs best using async tbf but whatever
😂
it may seem complicated at first but I highly recommend you learn async programming in your spare time
it is certainly an efficient approach to interfacing with databases and will make your life easier in the long run
Do you know of any good guides at all for me to check over please??
not really
Then thats a lil problem haha
a simple search of async node.js programming will do
So would this be it? :P
function userDB(client, config, userDB, user) {
return new Promise((resolve, reject) => {
sql.run("CREATE TABLE IF NOT EXISTS userConfig (userID INTEGER, prefix TEXT, embedColour TEXT, banner TEXT, balance INTEGER)").then(() => {
sql.run("INSERT INTO userConfig (userID, prefix, embedColour, banner, balance) VALUES (?, ?, ?, ?, ?)", [user.id, "y!", "ffffff", "default", 500]);
}).catch(reject);
})
}
Below this:
userDB(..).then(etc)
looks like that would do it
Alright, will give it a go soon 😛
also you're not resolveing your promise
or at least I can't see the call
ow?
function userDB(client, config, userDB, user) {
return new Promise((resolve, reject) => {
sql.run("CREATE TABLE IF NOT EXISTS userConfig (userID INTEGER, prefix TEXT, embedColour TEXT, banner TEXT, balance INTEGER)").then(() => {
sql.run("INSERT INTO userConfig (userID, prefix, embedColour, banner, balance) VALUES (?, ?, ?, ?, ?)", [user.id, "y!", "ffffff", "default", 500]);
}).resolve(resolve).catch(reject); // look here
})
}
oof aight 😂
Thank you
resolve(resolve) ?
why?
lul
yeah something similar in slovenian
lol anyway.
Lets try this 😛
Would it be good to add them to the database on the message event or the command file that requires the db?
well
the message event might just spam tf out of it
Yeah
lol
a command that requires a db, else you'll be querying the db on every single message
I was thinking it would probably use up more memory also, kherrect?
I generally add a "rate-limiting" mechanism for commands that perform database queries which increase in strictness depending on the bot's load
Is it good to indent code?
😂
Okay
yep
same goes for spaces
they can make a big difference in readability
I like to keep most code on one line so it looks cleaner
that's not a good idea, specially if is very long
you can break the line on each .
that's what I do
yeah but when you use promistes and callbacks, you will have code that runs inside another code. you will want to indent that
I see
Okay 😂
Thank you vm guys ❤
something.something()
.something()
.something()
.something();
that's what I like to do
needs a bit more async tbh
And I'm probably correct when saying that it is not really a good idea to stack brackets either?
provide an example
hmm one sec
you mean parentheses?
( )
Uhhh
Dunno 😂
I generally do use them for better readability
.then((result) => { ... }); // I prefer
jsfiles.forEach(f => {
let props = require(`${config.dirs.commandsDir}${f}`);
props.fileName = f;
if(!props.help) return;
client.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
})})
Bottom line
you mean something like this? function(){ function(){ }}
Not good?
Ye
Looks cleaner imo but may not be good
I personally don't see anything wrong with it
I would recommend you add { } whenever possible
specially in the if statements
there are several reasons why this is good practice but I'll save you the research
yee
i would rather group them together just like html, into parents and children
i like the concept of "boxes" with a clear visual definition on where it starts and where it ends
So this:
jsfiles.forEach(f => {
props.conf.aliases.forEach(alias => {
})
})
I'd be better doing this is what I think your saying Tim?
jsfiles.forEach(f => {
props.conf.aliases.forEach(alias => {
})})
oh
You mean the top one?
i would do like this js jsfiles.forEach(f => { props.conf.aliases.forEach(alias => { //code }) })
with a few exceptions
yea same
I just think that it would be nicer and cleaner to stack them lol
jsfiles.forEach(f => {
props.conf.aliases.forEach(alias => { code })
})```
Yeah, i'd do that also
if its more than 1 line, then the previous one
jsfiles.forEach(f =>
props.conf.aliases.forEach(alias => code)
);
even simpler
lol
yeah, but i dont like that style, because it hides the "ending" from the visual field
xD






