#development
1 messages ยท Page 360 of 1
try without the setInterval in not sure but it might not get executed instantly rather than after 3600000 seconds at first
yeah, it worked without that

why is it in there 
dunno
idk
cough
tonkku posted it
pinned by tonkku
#BlameTonkku
run far away
anyway, just dont loop it, and you are fine
Lets get working!
Should I use dblposter to post my stats to the server easy
Nop
Use if you want and is lazy to make it yourself
But there are plenty of better ways to do it
Wdym?
What lib are you using?
Yeah it does from what i read
Js
There are examples in #312614469819826177
But still bad
How bad
Really bad, because first you'll have a new dependency only for that when you can write yourself in 10 lines, second because it "checks" your lib when doing anything, didn't fully read the source code, but looks broken
I do, then it breaks on me, I think I might of put my token other than my bot key idk
where can I find the key I need so I know I don't mess up
did it?
maybe dbots is being really slow
can't access it at all
rip
ok so
@fleet epoch go here https://discordbots.org/api/docs
scroll to the bottom
select your bot
and the token will appear
I use that and it still breaks
const snekfetch = require('snekfetch');
const key = 'YOUR DBL KEY';
snekfetch.post(https://discordbots.org/api/bots/{client.user.id}/stats)
.set('Authorization', key)
.send({ server_count: bot.guilds.size})
k
Why would it not work
hm
I put it in my ready area
The setinterval says it will only run once an hour
@fleet epoch can you share your full code for the update in a code block here
kk later then
I need technical kinda help:
let Pages = {
'page_1': {},
'page_2': {},
'some_3': {},
'yep_lul': {}
}
Can I use a for (let page in Pages) {}
Say you're on "page_1"
How would you iterate "pages" and proceed to the next object?
Never use for...in
;-;
for(const key of Object.keys(obj)) {
const element = obj[key];
}
legend
Well, back to your issue, since you know the key, there's no need to loop through Pages, you need need to loop through the page_1 object.
Unless you want to show them all (which kinda defeats the purpose of pagination).
its more i have Pages.page_1 currently showing in an embed
and now i need Pages.page_2
I feel like this is a reaction pagination thing.
const keys = Object.keys(Pages);
let pos = keys.indexOf('page_1');
pos++;
for(const key of Object.keys(Pages[keys[pos]])) {
// uwu
}

Feel free to ping me.
i appreciate your help btw 
https://please.zbot.me/CpgPaa24.png
thought i'd pitch in for no reason but you can do this
if you only want the value of the key, you can just change entries to values
Oh god for...in
thats fine for small things like this
It's never fine.
its not ideal for larger objects
removes all my for..in's
ikr rip 
same
regardless it's good to hear from everyones point of view
i only use for..of on like client.guilds or other stuff
A lot of electrons died that day 
same happens if you use a normal for~
What happens when you use a normal for for what?

incoming noob question again
say "current page" is the Pages.page_1
how would i know exactly what the object is called
idek
ignore that im gonna do some googling
const currentObj = Pages.page_1
const key = Object.keys(Pages)[Pages.indexOf(currentObj)]
๐ฅ 
tonkku
Thonkku
?
?

snekfetch.get(`https://discordbots.org/api/bots/363695248997613575/votes`)
.set("Authorization", key)
.then(res => {
if(body.includes(message.mentions.members.first().id)) {
return message.channel.send("Has upvoted")
}
message.channel.send("You havn't upvoted")
}).catch(console.error)``` Failed ๐ฆ
body isnt defined
ohh cwap i forgot
I'm trying to make a database in python so I can make a currency system for my bot but I am clueless on how to append to the database and how to properply make one, any help will be appreciated โค
@python experts
shit
@restive silo alright thanks ๐
owo
What Bot Library should I use?
Ish, I do know JavaScript

Eris is pretty lightweight and resource gentle, Discord.js is very abstracted and have a lot more utiloty aswell as uses more resources because of that,
i dont know about discord.io
but i heard that it isn't the best
lol
I use the Roblox engine to send and process data on their servers
wowa
jk but it is possible probably
maybe
can someone help me
whats the issue
client.on("ready", () => {
console.log("Serving in " + client.guilds.size + " guilds");
console.log(client.users.size + " users use " + client.user.username)
const snekfetch = require('snekfetch');
const key = 'My bots token';
snekfetch.post(`https://discordbots.org/api/bots/${client.user.id}/stats`)
.set('Authorization', key)
.send({ server_count: client.guilds.size})
});```
comes off as a socket type error
only when i add the snekfech part
socket hang up
hmmm
idk, but you probably shouldn't run it on the ready event
make it into a command
yeah
yeah
thats not the reason
ik its not
what's the exact error message?
It just shouldn't be in the ready event anyways
while using snekfetch you need to use .then()/.end() on it or await it or you will never end the request
i post on ready, join and leave
oh i need a .end?
.end()
or .then() / await it
I don't think .end() is necessary, but its probably better
it is
you await it or use .then()
i dont need a .then
or?
ill just use a .end
are you using snekfetch?
yea .catch() will also attach a .then() listener
kk
ok command is finished
YES
it worked
its now locked to only me
ok i need help, how do i push code to github?
i have git on here, i also have notepad++ and microsoft code
@fleet epoch it's the same as any other time you push code
theres a command called git push 
you also need a remote (aka server/origin) to push to
you can just set it to your github repo and call it a day usually
although you do want to use a ssh remote to make sure you don't need to enter a password
git push -u origin master```
ok then you can just use https://github method :p
uh, how do i log out of the current respitory im in using git bash lol
@restive silo could you possibly help me make a database
im sorry but i dont know much about pyhton, isn't my prefered language aswell as i never really worked with either python not d.py or disco
so i might not be helpful at all
Natan its not
oboi
yes it is
to integrate it into the code is anooying
creating the database
thats why most peeps use ORM
means you'll be responsible to write to files, make it concurrent if that's a need, etc
i would recommend a Database like Postgres or MySQL but Nathan seems to have an other options ๐
I'm trying to make one rn
oboi

these are the most known and famous sql one's
SQLite wooo
sqlite3?
postgres is pretty neat
anyone knows why?
isn't embed : embed the correct way to do it?
for a RichEmbed()?
.send({embed: embed})
you can short stuff up if you do .send({embed})
no its the same as doing .send({embed: embed})
ok, thanks! ^_^
๐
404 background information not found
IU wanna know how to get a server invite to a server called SonVatanTR using the eval command.. (Discord.Js)
what are the color codes for rich embeds
you can use any colour you like
like red like the color codes
you mean in hex?
It's a decimal.
yes
i guess you are using D.js ?
@earnest phoenix some libs uses Hex instead of decimal
Uh no
yup
All libs have to use decimal in the end.
ยฏ_(ใ)_/ยฏ
Those libs just provide a nice way to convert #FFF to decimal.
0xFFFFFF is offered by the language compiler/interpreter and results in a decimal.
PS: In JS, if you are going to use hexadezimal, use 0xYOUR_HEXADEZIMAL.
module.exports = class CoinCommand extends Commando.Command {
constructor(client) {
super(client, {
name: "kill",
memberName: "kill",
group: "fun",
description: "Kill a user!"
});
}
async run(message, arg) {
let user = message.mentions.users.first();
if(user === undefined) {
message.channel.send("Please specify a user to kill!");
return;
}
let embed = new Discord.RichEmbed().addField(title, value);
.setColor("#EE82EE")
.setTitle("Kill")
.addField((message.author.username + " murdered " + user.username + "๐ซ")
message.channel.send({
embed: embed
}
}
whats wrong
hmmm
Hey guys, I can't get client.user.id to work in discord.py, the command isnt recognized and i defined client = discord.Client() earlier in my code
i'm trying to implement this:
import aiohttp
dbltoken = "token"
url = "https://discordbots.org/api/bots/" + bot.user.id + "/stats"
headers = {"Authorization" : dbltoken}
async def on_ready():
payload = {"server_count" : len(bot.servers)}
async with aiohttp.ClientSession() as aioclient:
await aioclient.post(url, data=payload, headers=headers)
async def on_server_join(server):
payload = {"server_count" : len(bot.servers)}
async with aiohttp.ClientSession() as aioclient:
await aioclient.post(url, data=payload, headers=headers)
async def on_server_remove(server):
payload = {"server_count" : len(bot.servers)}
async with aiohttp.ClientSession() as aioclient:
await aioclient.post(url, data=payload, headers=headers)
while(!encounter) {
console.log(`You're in the while loop.`);
con.query(`SELECT * FROM characters WHERE encounter_id = ${k}`, (err, result) => {
if(err) throw err;
console.log(`You're in con.query.`);
if(!result[0]) {
encounter = k;
console.log(`You're in the NOT RESULT.`);
} else {
k++;
console.log(`You're in the ELSE.`);
}
});
}
can anyone explain to me why does it loop endlessly with only the first console log spamming?
what the hec happened to the formatting there xd
it seems I can't write more than 2k characters
you can't
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
You're in the while loop.
only the first one logs?
as I said, yes
well you're trying to get the encounter value right
btw let k = 1
nvm
what?
I can't read this formatting
its too painful
while(!encounter) {
console.log(`You're in the while loop.`);
con.query(`SELECT * FROM characters WHERE encounter_id = ${k}`, (err, result) => {
if(err) throw err;
console.log(`You're in con.query.`);
if(!result[0]) {
encounter = k;
console.log(`You're in the NOT RESULT.`);
} else {
k++;
console.log(`You're in the ELSE.`);
}
});
}
try running the con.query(SELECT * FROM characters WHERE encounter_id = ${k}, (err, result) => { part by itself and tell me what it logs @ornate shadow
is this better now?
I edited it...
you mean in the mysql?
console?
it will show nothing
because there's nothing to show
that's why the if(!result[0])
I'm planning to find a missing number
if it doesn't output anything, it's a success for me
yeah so run the sql code
but you have an else
it should still output
because the else should catch if there is a result
Sup
it seems like it doesn't even call the callback~
._.
I commented the while loop
forgot to comment the first console.log
I guess the query works
but the problem is with the while loop ๐
yeah
Uh what
let encounter = 0 is before that
wait what
No encounter = 0; means encounter is defined
k I'll leave it to you
oof
javascript rules
I'm sorry I'm used to java 
even though my bot is made in js
I'm still used to java
JS is dynamic typed.
if(!result[0]) {
encounter = k;
console.log(`You're in the NOT RESULT.`);
basically encounter = 1;
For what do you need the while loop?
it should turn false
I need the while loop to loop through all the results in a query starting with k = 1, k = 2, etc and when it doesn't return anything, assign that number to encounter;
hmm ok
can you help me, then?
what I want to achieve is this
I have different values of encounter_id column
let's say some row as 1, other row has 2, other one has 2, then 4, 4, 5.
so 1, 2, 2, 4, 4, 5.
I want to make it so that I assign the value of 3 to encounter
the "available" number
how could I do this?
So you basically want to make the ID consecutive?
yes but still be able to assign the same value to others when needed
Why does have an ID column even duplicate values?
like if I find the number "3" available, I want to be able to assign the number "3" to multiple rows
Point of an ID column is to be unique.
I have a separate id for that. I need an encounter_id so that that ID can tie up the objects
Oh
one-to-many relationships
Instead of selecting rows one by one, you could just select all, look which numbers aren't used and do whatever you have to do.
for example I have a table for spawned monsters. I want to be able to tie up 2 monsters to 1 character. that would make one encounter made up of 3 objects
select all?
Yeah, just get all rows
didn't I do this?
I added the while loop so I could "find" the "missing" number
k=1, k=2 etc
That's a pretty stupid way to do it.
theres no point of that
then how?
Just get all rows of that table and look which numbers haven't been used yet.
is there some query for that?
Remove the WHERE clausel and you get all rows.
WHERE encounter_id = ${k}
you used where
That's not a WHERE?

Then what is it?
oh that where ๐คฆ sorry
I didn't understand
hmm
so I'll get all the numbers and then use node.js to find the missing number
I'll try that, thanks
I'll get back if I stumble upon something again
again, thanks
let embed = new Discord.RichEmbed()
.setTitle(`Encounter!`)
.setDescription(`This is an encounter...`);
let counter = 1;
con.query(`SELECT name FROM monsters WHERE encounter_id = ${character[i].encounter_id}`, (err, monsters) => {
if(err) throw err;
if(monsters[0]) {
for(let j = 0; j < monsters.length; j++) {
embed.addField(`${counter}. ${monsters[i].name}`); // <--- this doesn't get added
counter++;
}
}
});
bot.channels.get(character[i].channel_id).send({embed}); // <--- this runs probably before adding any fields
I suck at async/await. can anyone help me? ๐
it's in the comments
try a console.log there?
ok lemme do that quickly
prepared statements
huh
oh yeah true, you have to do the send inside the callback function
let embed = new Discord.RichEmbed()
.setTitle(`Encounter!`)
.setDescription(`This is an encounter...`);
let counter = 1;
con.query(`SELECT name FROM monsters WHERE encounter_id = ${character[i].encounter_id}`, (err, monsters) => {
if(err) throw err;
if(monsters[0]) {
for(let j = 0; j < monsters.length; j++) {
embed.addField(`${counter}. ${monsters[i].name}`);
counter++;
}
}
bot.channels.get(character[i].channel_id).send({embed});
});
oh, I did a console.log and it shows up... for some reason (probably some bug that I need to figure it out) it still doesn't add the fields
oh, ok
I'll do that, thanks! ^_^
np
a field got added so it worked! thanks! ^_^
Anyone on that uses discord.py
more of a general question- is storing information in .txt files bad? i've been storing databases and server prefixes in .txt files... but someone told me recently that it's very ugly to read and extract data from files manually, and that i should look at yaml
He is using Java I think
So yaml is what he needs to use
It's like json, but for Java, Json is for javascript
do you guys have a good tutorial to make a bot?
@dense goblet not really, but i recommend you look on YouTube or Google for tutorials that will lead you on the right path
ok
@fleet epoch yaml and json are both supported by both languages, XML is more commonly used for Java, but it's more about user preference rather than something defined
๐ค uhh i primarily use python -dunno where java came from-
hi, i need help with something in python if anyone could help
i might be able to
how would I get the user's id from a discord.Member object?
lets say i got a list of members from server.members
and i need the member's user ids
how would I go about doing that?
are you using discord.py?
yes
@earnest phoenix for python, JSON is good since python has built in libraries for handling it
hmm i see, thanks
@fleet epoch JSON can be used for python
and other langs
but the J and S in JSON stand for JavaScript
JavaScript Object notation iirc
My bot keeps automatically leaving the voice channel when trying to play some audio via ytdl-core 
Do you have opusscript?
and ffmpeg?
Are there any errors in the console?
@neat falcon
But it still worked
@restive silo
npm -v xyz Always shows the npm version
oh...
Thats why it said 5.6.0
yeah

Indeed
Does it work?
nope
Hm
try a dispatcher.on("error"
okay
tried that
dispatcher doesn't give error
also how do i give people who upvoted my bot a role on my server?
idk, guess you can find that in the discordbotlist api
you'd need to iterate over the /votes api endpoint to see whos voted, then for every user who has voted, add a role
you can use <Member>.addRole(<Role>) on stable
if you don't know
https://discordbots.org/api/bots/<client.user.id>/votes
actually you'd also need to check if they are in your server as well
okay, thanks
btw, i'm using v12-dev of d.js, how can i get messages of a textChannel?
that aren't cached
<Channel>.messages.fetch({ limit: (number) })
limit isnt required but you can fetch multiple messages using it
or you can specify the amount you want to fetch
^
oh, okay i thought channel.messages was a collection ๐
thanks
Well
okay
Did stable already change to Stores?
rip
My bot doesn't have any functionalities that requires categories.
Oh, but I should add animated emoji support to the fork, brb committing
oh god.. what's going on in here?
This is a closed community, move along.
...
oof rip
@scenic crest In which language are you making your dapi lib?
I'm obviously in DAPI and saw your question.
wanted to make one in go because discordgo is awfully low level and it's quite painful for just simple stuff
trying to get a discordgo.Guild pointer from a discordgo.MessageCreate pointer is like:
channelid -> channel -> guildid -> guild
then add error checking since all non id thingies there canthrow errors ๐
yeh
snekfetch.post(`https://discordbots.org/api/bots/${client.user.id}/stats`)
.set('Authorization', key)
.send({ server_count: client.guilds.size})
.end()
message.channel.send("My stats are now updated on discordbots.org");
}```
this forsome reason spammed my console
Because it's in the message event?!
no its its own command
I doubt it
and it spammed 401 error
I mean idk if anyone actually uses go but I wanna combine the speed of go with the simplicity of like d.js
@fleet epoch It probably spammed it because the request got spammed. Which means the command got spammed.
Or something else broke.
no cause i only did the command once, im thinking something broke
You'll need to debug it, either way.
should i do a .then other than i .end
Do you understand the difference?
people said .then stops the request like a .end, but in .then i can add some stuff i want it to do
People are wrong
Anyone knows how i can fix this?
let mes = await message.channel.createMessage({embed: {
description: 'testr111'
}});
mes.edit({embed: {
description: 'test2'
}});
//it would edit as:
"test2111"
//but i want it to edit as
"test2"```
@indigo notch client bug
so just wait until there comes a fix?
๐ค
pretty much but IIRC it's rare, I wouldn't worry about it
you might be able to trick the client into re-rendering it fully by messing with whitespace
accidently pasted my clipboard
is electron heavy on resources? I remember something along those lines being told to me
electron is a browser loading "webpages" from disk
it's heavy on resources in that there's significantly more overhead than a native ui impl
@earnest phoenix sorry for pong, this is sent in the d obj of payload right:
{
"token": "my_token",
"properties": {
"$os": "linux",
"$browser": "disco",
"$device": "disco"
},
"compress": true,
"large_threshold": 250,
"shard": [1, 10],
"presence": {
"game": {
"name": "Cards Against Humanity",
"type": 0
},
"status": "dnd",
"since": 91879201,
"afk": false
}
}```
Do you actually decompress the payloads?
But yes.
Notice: The first shard has ID 0.
I don't know if I'm using compression ngl, but if I am go's json parser is decompressing it
yeah I use sharding already dw
compress: true means https://discordapp.com/developers/docs/topics/gateway#payload-compression
Also you may want to implement transport compression, as it will be required for gateway v7.
Transport compression means 80% less bandwidth
is the whole payload gonna be compressed or just the d?
The whole message.
hm ok ty
It's transport compression.
@uncut slate I have a d.js question !!!
k
so if I get a guild object
can I technically do guild.name = "whatever I want"
and then d.js will use that when handling internally
or is it write protected
you can
if you set client.guilds.forEach(g => g.name = 'arrayin suk kok') on boot
then, every message received in your message event will have msg.guild.name === ' arrayin suk kok'
(every guild that isn't new)
hmm le docs say it's read only but thanks anyways
hmm alright
try it out
nah I don't actually need to
I was just curious
because JDA uses triple condoms for protection, whereas discordgo you can change w/e you want
so I was wondering where abouts d.js is
right
since they changed to use a lot of getters now this isn't quit possible anymore atleast for some stuff, others might be editable
\๐ค
Anybody wanna check out this app I made? https://github.com/PlayBy/Discord-LiveBot
It's basically a discord remake, but for controlling bot accounts instead of user accounts
"An app that allows you to be inside a bot!" yea ik what it is 
i think i've seen one before
oh really?
pretty neato
thanks
is this a typo https://owo.whats-th.is/d4d374.png
guild guild
I think so
ya
animated guild indicator means the same thing
the bot app thingy sounds really cool
but it just says "write npm test"
what do i install, do i install nodejs
yeah you'll need node js
lol electron
we already have botcord and lightcord iirc
both are static apps that can run without electron
O
this is a fun program
thanks ๐
@wooden shoal doesnt work for me
run npm install -g electron --save-dev --save-exact
@bright spear
it's not packaged right now so some development steps are required
that doesnt work either, with or without sudo
is it the same error?
is this reasonable ```py
async def on_guild_join(self, guild):
bots = sum(m.bot for m in guild.members)
users = guild.member_count - bots
if bots > users/3:
await guild.leave()
else:
pass```
reasonable? leave guild if a third of user count is less than bot count
ty
or just don't care if it's a bot collection
@elder rapids wasting resources tho
Get a better server
How much will it waste
that's.... terrible
Not like you're already caching millions of things already?
not really

What does a simple bot collection do to your resources
I didn't say simple
That a thousand other regular servers don't
I'm only allowing dbl and ls.terminal.ink
honestly I just don't think it's worth it but that's me
its generally pointless
๐
not really I log commands
the higher guild count the better ur bot looks amirite
eh
good joke ken
I was saying checking at all isn't reasonable ๐
yes
I didn't ask that
๐
What is this about?
Hello i need serious support and help.
hmm?
Are their any bots that can clear the chat of a discord text channel?
Im just wandering
CleanChat bot wont work
Clone channel and delete old channel.
Can you hand me a bot that can clear the chat?
Clearing isn't supported yet by the API.
i hate all my messages scattered around the place
"Clone channel and delete old channel."
No bot needed.
how to make reactions which takes to page 2
Has anyone had experience with the "pug" template middleware for express.js?
i think everyone uses ejs templates
Not me
html
head
title test title
link(
rel='stylesheet'
href='./assets/styles.css'
)
body
h1 Registration
div(class='testing') hello there
this lmao
In Discord.JS, how and where should I handle promise rejections for permissions?
Always handle them wherever they get rejected.
So within the code/commands themselves?
Yes.
Unless you have a proper command handler. Then you will want to forward the rejected promise to it and then it will handle it.
Alright
Usually I do .catch(this.handlePromiseError.bind(new Error())) 
well or you use async/await and handle it in your command handler what is less annoying tbh
which just gives me a proper stack trace and forwards the rejected promise to the command handler
async/await the way 
I use async/await everywhere in my JS bot
same
..I don't think I've ever used async/await
Inside child processes, inside the REST API, inside the process manager.
It's omnipresent.

async/await makes for so much cleaner code โค

@earnest phoenix "connection refused" try checking your firewall or smth
Could also mean there's nothing listening on port 80 so the OS refused to accept.
Could anyone tell me how could I make 3 mysql query functions run in a specific order without creating a callback hell in node.js?
async/await
Could you give me an example, please? I tried throwing these async await everywhere
Again, I suck at them
await req1
await req2
await req3
It gave an error and crashed. Something about unidentified... Something (await word)
Is the function async?
aaa beat me to it
async function () {
}
// or
async () => {
}
I added async to the function, yes (also a query)
I'm not at home rn so I can't show the code
What does node -v print?
Latest version probably
OK I'm gonna come back to you when I get home
Thanks for your will to help me. I got stuck on that... It's a wall I always bump in when I code in node.js
I'm gonna guess he's in a non-async nested function
hey
I'm gonna guess he uses an old Node.js version.
i want to host my bot in my phone
Don't
in termux
and
i copyed a folder from a root folder
and the folder with the bot are rooted
and i can't acces it
you know how i can unroot ?
?
@earnest phoenix why not
if theres anyone here on the latest (or close to latest) discord.js master, do you experience any ECONNRESET's? ive been having them a lot more frequently ever since a few updates ago and its happening quite often, even when executing commands sometimes i've noticed
i dont expect much since this is probs only a me thing but i was just curious
https://please.zbot.me/kGJ2jJga.png
Just don't do it, if you don't care about performance, use glitch which is a free hoster for node.js applications. ( @gusty topaz )
Well, a few hours ago the discordapi had an outage. Could that be the issue?
Nah probably like once every few days
this has been happening a lot even before the outage so i doubt it
Oh ok. Discordapi has lots of outages.
it's just a connection problem appearently
@inner zinc yeah it seems that way, but this is hosted on google cloud platform so i kinda doubt it'd be a connection thing on their end
ECONNRESET usally happens for promises that couldn't succed
ahh okay
hmm i guess i can see how that could happen, it generally occurs (only sometimes) after a "Missing Permissions" from the API
it's not anything that bad it's just appearing in my console and it kinda makes me worried lmao
mh, nah, i don't think it's because of missing permissions~ :v
have you had any ECONNRESETS before to know what it might be?
yep
i appreciate your help btw 
not really sure if it's because of weak connection or connection reset, but it seems that this happens when as a timeout of promises
hmm alright, thanks for the help! i'll have a look into it to see what it might be 
ECONNRESET usally happens for promises that couldn't succed
..no?
uncaught promises will throw their own unhandledRejection
ECONNRESETs have nothing to do with promise rejections or promises
are you sure? the ECONNRESET gets triggered under unhandledRejection which is related to promises
Yes, I'm sure.
ECONNRESET is just your normal throw which is going to mean and unhandledRejection if you're in an async function
sorry i dont mean to sound rude or question your knowledge it just says here
https://please.zbot.me/5PD5U1xC.png
yeah, it is a connection problem :v
and in discord js, the thing that's mostly going to triggers this are promises :v
@austere meadow read what I just sent
ahh okay
so its nothing to worry about?
It is something to worry about, but it doesn't have anything to do with promises, or "timed out promises"
okay, thanks a lot for helping me understand it 
@earnest phoenix I finally got home. it says v8.7.0
Are you sure you use await in a function defined as async?
I read about that nested async functions
do every function have to be async for it to work?
Yes
async () => {
(() => {
await somePromise();
})();
}
doesn't work
I mean
Because the function the keyword is in isn't async
first to be async, second to not be async, third to be async (then awaits)
Doesn't make sense to do that
so all 3 have to be async
Just the one with the await keyword has to be
oh?
But it doesn't make sense the other to not be async
Since you probably want to wait for the async thing to finish
hmm... I'm gonna mess with them again and see what works and what doesn't
what is your code looking like right now
since it's a pretty big project, I'm gonna try to sum it up and paste it here
Use hastebin
hint hint hastebin.com is sexy
the 3 functions
what line am i looking at
holy shit pastebin actually works on mobile now
๐ฆ
lol xD
Please use prepared statements, string interpolation can cause SQL injection attacks
I want these 3 functions to execute in the order they're written in (well at line 146 is an IF... I can turn that into a function I guess)
i mean assuming you always control the content of the string interpolation
but i guess good conventions should always be followed
still bad practise imo
I have no idea what prepared statements or string interpolation is
string interpolation is ${some.var}
oh ok
prepared statements are pretty much statements that ensure that the query values are treated as values
without them users may be able to edit the actual query
PreparedStatement s = c.prepareStatement("SELECT * FROM `users` WHERE `user_id`=?");
s.setString(1, "123);```
an example
so you're saying that I should let var x = before using x in a query?
uhh I have no idea how prepared statements work in JS sorry
but that would be a java example ^
then again, how could I make let's say the function at line 81 and the function at line 115 execute in the order they've been written?
I tried making the function at line 45 async and awaiting the other 2 functions
are mysql queries asynchronous?
do they block until the query is complete?
do they block the main thread/process until they're completed
NE MUTLU TรRKรM DฤฐYENE
i would assume no since you're passing a callback
no, they complete randomly
arrayboy can you mute
i'm on mobile
@ornate shadow the answer would be to write each successive query operation in the callback of the previous one
well that's what you expect when you use callbacks
already did before you fanta ๐
alternatively you could write each query as a function and just call those functions successively in each ccallback
or you could try wrapping the query with a promise and using async/await
so to use async/await on them I have to "wrap them into promises"?
that's a bummer, since I don't know about promises either. I tried learning them a month ago but it seems so complicated
that's very kind of you
hello
I was planning to go to my nearest university to ask for help on this particular subject in the days to come
if you could lend me a hand instead, that would be awesome
if you're referring to uh node.js and discord.js
then its mostly just
async function () {
await do_something();
}
await message.channel.send('mesage')
.then((message_object) => {
message_object.edit('new message')
})
a very vague example
i found this https://github.com/martinj/node-mysql-promise
saves you the trouble of promisifying mysql yourself
I'm trying to use a different but pretty similar wrapper https://github.com/lukeb-uk/node-promise-mysql and it works fine setting the connection up and all; but I bumped into this
}).then(function(result) {
if(character[i].encounter_id) {
con.query(`UPDATE characters SET action = 'idle' WHERE name = '${character[i].name}'`);
let embed = new Discord.RichEmbed()
.setTitle(`Encounter!`)
.setDescription(`This is an encounter...`);
let counter = 1;
con.query(`SELECT name FROM monsters WHERE encounter_id = ${character[i].encounter_id}`, (err, monsters) => {
if(err) throw err;
if(monsters[0]) {
for(let j = 0; j < monsters.length; j++) {
embed.addField(`${counter}. ${monsters[i].name}`);
counter++;
}
}
bot.channels.get(character[i].channel_id).send({embed});
});
}
}); // <--- SyntaxError: missing ) after argument list
any ideas?
I turned the if statement into a function and put it into a .then()
am I missing something?
wait why are you using .then
the whole rationale for promisifying is to enable the use of async/await
you're right
I turned them into async/await and no errors/crashes now!!! ๐
gotta test if it really works though
that would be awesome
it seems it doesn't work; in the sense that the code doesn't run at all... oh well, I guess that's my part to see where's the problem. it's great that async/await works now though! I will come back if I ever need help again, thank you! ^_^
Is there any way to stop people from searching nswf search terms?
tell them not to in a commanding, but not harsh tone
no you need to be gentle
or alternatively use safesearch
it's near impossible
i assume you're talking about google?
Yes I am
safesearch is google's fancy web content filtering tech
so that if they google stuff like that it stops them
are you using their api or just scraping
why lol
idk
google doesn't like that
They don't?
no
they have a tos clause somewhere iirc
but anyways you should be able to filter out nsfw by enabling safesearch on the machine you're running the bot on
navigate to google's search settings from a web browser
Yes it just filtered the results
Then its not enabled?
I enabled it and saved it
Try your browser with safe search on?
What should I even search for?
Something you expect nsfw for?
I searched something and I still got results
@glossy sand @ornate shadow Use mysql2 instead of mysql.
For node
A) mysql2 has already a promise based interface.
B) mysql2 supports Prepared Statements.
ok, nice! ^_^



