#development
1 messages · Page 916 of 1
Discord probably replaces them with the raw unicode before it counts the characters
so you can still have the same amount
no it doesn't
internally all :emoji: get parsed to unicode, replacing all colon format emojis to their unicode counterparts
I tried it
it does
oh fuck i found it #development message
well I don't know how they do it internally
@copper cradle
but fact is, they rejected my bot messages when its character count was over 2000, with shortcodes
whatever
thanks
those dudes make the rest of the Spanish dev community get bad looks
If you write a bot to throw on more than one server do you actually host all instances of that bot?
Or when people add it to their server you as the author host it yourself?
the first
like server-specific setting? maybe like a prefix
@reef girder
you only need 1 instance of the bot
then you can use a database to store such data
so you use a database to store that
const fs = require('fs')
const hour = JSON.parse(fs.readFileSync("./hour.json", "utf8"))
function write(){
fs.writeFile("./hour.json", JSON.stringify(hour), (err) => {
if (err) console.log(err)
})
}
if(!hour[moment().format("DD/MM/YYYY")]){
hour[moment().format("DD/MM/YYYY")] = {
users : 0,
bots: 0
}
}
write()
if(message.author.bot){
let add = 1
let Current = hour[moment().format("DD/MM/YYYY")].bots
hour[moment().format("DD/MM/YYYY")].bots = Current + add
write()
return
}
let add = 1
let Current = hour[moment().format("DD/MM/YYYY")].users
hour[moment().format("DD/MM/YYYY")].users = Current + add
write()```it does not write in the json
it's like asking if a new account gets create everytime I join a server
I use keyv and a mongodb
add hour as a parameter and pass it to the function
keyv is really simple and to the point
what things should i consider when storing user input in a json file? is there a parse function to escape stuff like quotes etc?
you shouldn't do that
If you want to do it you can though!
checkout decodeuricomponent
oh wait maybe thats the wrong thing sec
oh no thats right
but JSON.parse will get you most of the way there
yeah json parse
so i am trying to do it if the guildid has 1 in the blacklist row they cant do any commands what have i done wrong
client.on('message', async msg => {
if (msg.channel.type !== 'text' || !msg.content.startsWith(settings.prefix)) return;
console.log(`[${msg.guild.name}] ${msg.author.tag} >> ${msg.content}`);
const cmd = msg.content.toLowerCase().slice(settings.prefix.length).split(' ')[0];
if (!commands[cmd]) return;
con.query(`SELECT * FROM testing WHERE guildid = ${msg.guild.id}`, (err, result) => {
if (err) return console.log(err);
if (result[0] && result[0].blacklist == 1 || cmd !== 'help') {
return msg.channel.send('This server is blacklisted so cannot use this command.');
}
else {
commands[cmd](msg);
}
});
});```
are you getting an error?
aren’t jsons prone to corruption
or whats happening when you run that
@earnest phoenix yeah its not perfect but if they want to just move forward best to help people with their actual question instead of suggesting rewrites
will json parse fix stuff like quotes being stored properly etc
dont use json as a db because it isnt a real db and you are gonna run into issues trying to write to a single file simultaneously. unless you forcibly do everything synchronous, which also sucks
?
any errors @wicked pivot
no :c
im assuming write() isnt doing what you think its doing?
aka
you should be calling fs.write()
im assuming
oh nevermind i see you have it as a function
ignore me
dbl.hasVoted(message.author.id).then(voted => {
if (voted) {
//command
}
});``` Does anyone know why does this always run ? (even if the person didn't voted in the past 12 hours) This example is from https://discordbots.org/api/docs#jslib
Spice up your Discord experience with our diverse range of Discord bots
const fs = require('fs')
const hour = JSON.parse(fs.readFileSync("./hour.json", "utf8"))
function write(){
fs.writeFile("./hour.json", JSON.stringify(hour), (err) => {
if (err) console.log(err)
})
}
if(!hour[moment().format("DD/MM/YYYY")]){
hour[moment().format("DD/MM/YYYY")] = {
users : 0,
bots: 0
}
}
write()
if(message.author.bot){
let add = 1
let Current = hour[moment().format("DD/MM/YYYY")].bots
hour[moment().format("DD/MM/YYYY")].bots = Current + add
write()
return
}
let add = 1
let Current = hour[moment().format("DD/MM/YYYY")].users
hour[moment().format("DD/MM/YYYY")].users = Current + add
write()```it does not write in the json
@wicked pivot do you use command handler ?
and do you host on glitch ?
glitch
yikes
glitch frequently has problems with file writing
yes it does
try to host it on your computer
just to make a test
if it works then it means that the pblm if from glitch
if not idk
check the name of the file
pm2 and self host are great things
I already used json before and I had no problem
I have to do what ?
download your bot files
yeah
on your computer
you won't be using json dbs on glitch
and try to run it on your computer
and nowhere else
json is not supposed to be used as a database
just get a real database smh
on my pc it works
on my pc it works, what do you advise me like db on glitch? free
ofc it's gonna work on your pc
@earnest phoenix for keyv is there a way to set character encoding types?
I want to store emojis
Is it any way to get the Field title white?
or don't bother people with such problems
Is it any way to get the Field title white?
@vestal sequoia no sorry
Ok, Thanks
@reef girder not sure, you might be able to store emotes
@hasty lotus I already use quick.db in the same file
but you can use .setDescription @vestal sequoia
Ok thanks 🙂
yeah like make it white
but nope
field titles are gray
and they will stay gray
🤷♂️
the message returns an array of embeds if there are any the embed you want will be the first item
then you can get it's properties
In an Embed, AddField, What dose the inline do?
Ok, thanks
np
I'm having issues with my djs v12 bot, music starts by being glitchy and then stabilize after ~20 seconds, how can I avoid that
ytdl gang
@tight plinth are running it locally
?
are you running it on your computer or in the clouds
vps
is there any way to force a git fork to sync back to the current commit the base repo is on
or do u have to re-fork
anyone used remotemysql? what do i write in "host:" when i want to connect my nodejs code with the db?
phpmyadmin just says localhost
but when i type that i get a connect refused
127.0.0.1
Error: connect ECONNREFUSED 127.0.0.1:3306
found this
not sure how to relate it to host
you mentioned port, but where do i input that?
just local:3306?
because 3306 is the default port
that's the default port
yes
you're prone to data leak
yeah
glad we agree, lol
if your database vanishes one day, you can't blame us
I won't use such sketchy hosts
i think there are some free myswl hosting through github student pack too
but are i really like how it instantly has your phpmyadmin setup too
to I'm fine
pma is good
this is what i have access to https://education.github.com/pack
oh well
what if i use json on the mysql db
are you kidding
doesn't sound like it
Hey so im trying to make a vote command that gives a user a role when the vote and it works to tell if you voted or not but it gives me this error
(node:3265) UnhandledPromiseRejectionWarning: TypeError: message.addRole is not a function
at dbl.getVotes.then.votes (/app/master/commands/vote.js:13:11)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:3265) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3265) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This is my code
module.exports.run = async (Discord, client, message, args) => {
const DBL = require("dblapi.js");
let voter = message.guild.roles.find(role => role.name === "voter");
const dbl = new DBL(process.env.DBL_TOKEN,
client
);
let member = message.member
dbl.getVotes().then(votes => {
if (votes.find(vote => vote.id == message.author.id)) {
message.channel.send("Thanks for the vote! :)");
client.channels.get("708353671175602206").send(message.author + " has voted for Yobo")
message.addRole(voter)
} else {
message.channel.send(
"You have not voted yet go vote on our discordbots. \n\n**If you already voted it can take up to 5 minutes to update on to our bot.**"
);
}
});
};
you're trying to add a role to a message?
surely that'll work
oh
god
i changed it message.author
but it was member
so go with it as that
same error tho just member.addRole
let me get that one
https://cdn.discordapp.com/attachments/491362216096825345/708353644109496380/message.txt
data.find is not a function
My bot was returned today and it said it was declined because of my !image command which can send NSFW content and I need to add a search filter. How?
put safesearch
make it nsfw channel only
now it gives this ```
(node:3455) UnhandledPromiseRejectionWarning: TypeError: Supplied parameter was neither a Role nor a Snowflake.
at GuildMember.addRole (/rbd/pnpm-volume/7d63fd46-a383-46f0-afca-7da9eafb3707/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/structures/GuildMember.js:452:38)
at dbl.getVotes.then.votes (/app/master/commands/vote.js:13:10)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:3455) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3455) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:3513) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of null
at dbl.getVotes.then.votes (/app/master/commands/vote.js:13:24)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:3513) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3513) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
voter is null
How do I put safe search?
role name is case sensitive, are you sure it's the correct spelling ted?
https://cdn.discordapp.com/attachments/491362216096825345/708353644109496380/message.txt
data.find is not a function
please don't bump messages
;v
remove .id from voter.id because why not
Im rewriting my play command in eris, but I have some problems with connection... https://cdn.lumap.me/ad98i3nx.png
https://cdn.lumap.me/d1txnrv8.png
https://cdn.lumap.me/fptkixmf.png
when my bot ques a song it just plays it emiedeatly, its really enoying anyone else have that problem
the bot connects to the vc and leaves it instantly with this error
message.member.addRole
Eris, a NodeJS Discord library
ffs
did you press escape
yes
dispatcher.on
help?
so I guess
//djs v12
connection.dispatcher.end()
```--> ```js
//eris
connection.end()
```for the stop command?
I do
oh
I genuinly dont know how to make webhooks,
pog
do you need webhooks?
no
mk ight
https://cdn.discordapp.com/attachments/491362216096825345/708353644109496380/message.txt data.find is not a funciton
because data is not an array
or is it
yes it is
but you're using the v1 api, which is deprecated.
use https://corona.lmao.ninja/v2/countries instead.
Just changing the url?
yes
Oh ty
anyone here do scala?
lumap what language are you using
seems to be english
seems to be js
0|index | at Module._compile (internal/modules/cjs/loader.js:1156:30)
0|index | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
0|index | at Module.load (internal/modules/cjs/loader.js:1000:32)
0|index | at Function.Module._load (internal/modules/cjs/loader.js:899:14)
0|index | at Module.require (internal/modules/cjs/loader.js:1042:19)
0|index | at Module.Hook._require.Module.require (/usr/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:80:39)
0|index | at require (internal/modules/cjs/helpers.js:77:18)
0|index | at CommandoClient.<anonymous> (/root/bot/index.js:79:3)
0|index | at CommandoClient.emit (events.js:310:20)
0|index | at CommandoMessage.run (/root/bot/node_modules/discord.js-commando/src/extensions/message.js:256:17)
0|index | at runMicrotasks (<anonymous>)
0|index | at processTicksAndRejections (internal/process/task_queues.js:97:5)```
this keeps popping up in the console
good job you managed to not show the error
commando oof
yh
idk how i can help but look at the stack trace
Okay well I assume the error was logged at /root/bot/events/client/commandError.js:1:15. There's also stuff like /root/bot/index.js:79:3 and /root/bot/node_modules/discord.js-commando/src/extensions/message.js:256:17, so could you show the code in the index file at line 79?
function randColor() {
red = (Math.floor(Math.random() % 255) + 100).toString(16)
green = (Math.floor(Math.random() % 255) + 100).toString(16)
blue = (Math.floor(Math.random() % 255) + 100).toString(16)
color = `#${red}${green}${blue}`
console.log(`Made Color ${color}`)
return color;
}
I made this random color function to generate a random color for my embeds, but it always generates the same color: #646464, does anyone know what is causing that?
Math.random() % 255 is always a number between 0 and 1
flooring it makes it return always 0
I guess I did the Math.random() wrong then, I guess my brain was thinking like the rand() function in C++
in js, Math.random() returns a double between 0 and 1
Math.floor(Math.random()*255)
Yeah, I guess my brain forgot which language I was using halfway through the thing and I thought JS worked like that
'#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6)
is a fun way to generate a color
const rand = Math.floor(Math.random()*16777215);
const color = '#'+rand.toString(16);
is another fun way 😛
Is it a thing to create multiple bots with the same name to better being able to distribute workload?
i mean ensure that when i add new servers/shards, the same guilds stay on the same shard/server
@fallow quiver Which lib are you using because I know discord.js has a built in random function for embeds. .setColor('RANDOM')
Yeah lol
Anytime
Yes you can. if you make xxBot1,xxBot2, .. and log them in on different vps, then the same guilds will stay on the same servers
Clustering is basically splitting the bot into separate subprocesses, where X amount of shard distributed over X amount of processes (Clusters)
What it is not is making seperate bots and doing that because thats not how it works
no
nononononono
that is sharding
Clustering != sharding
they are two very different things
@neat ingot did you steal my code to generate a random color for every message? 😄
also afaik theres no reason to convert from decimal to hex into an embed
https://sourceb.in/f0ff80fc3b
I'm using this code, what it should do is:
set the placeholder's color, send a preview of how role color would look, then await reactions for yes/no (green tick/red x) and based on that it will accept the command, create the role with the desired color by the user and add it to the user, when cancelled it will edit the embed saying its cancelled and when on error, it will say time's up
what it does:
changes the placeholder's color, sends the embed message of the preview, adds the first reaction the green tick and almost at the same time as it adds the second reaction the red x it doesn't await for the message reactions by the user and it cancels the command out as if it reads its own reaction the red x and it cancels the command
I'm using relatively the same code for when the role already exists and it works without an issue
i keep getting the error discord.errors.NotFound: 404 Not Found (error code : 10008): Unknown Message and i have 0 clue where it’s coming from 👀💧has anyone heard of a fix for this (python btw)
(node:12) UnhandledPromiseRejectionWarning: Error: This video is not available.
at request (/home/container/node_modules/ytdl-core/lib/info.js:47:25)
at PassThrough.Miniget.stream.on (/home/container/node_modules/miniget/dist/index.js:196:32)
at emitNone (events.js:111:20)
at PassThrough.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
This error shows up when I try to play a music video
its basically saying the message is no longer cached so the bot cant see it when it tires to do somthing to it
aight but it keeps spamming my bot with errors
anyone knows why?
so i am only talking about different bots and sharding, not about clustering. I am talking about being able to split guilds to separate vps, never changing which server the guild is on. (After a bot has recahed a certain limit of servers, the next bot is created and the next say 100k servers can connect to this one, instead of the last).
just silence it
@viral spade and i am telling you YOU CANNOT DO THAT
which is why i told you
you need to cluster
with cluster i can do that?
damn this is hard
i would suggest it would be a good idea learning how Sharding and Clustering works with deployment
because you have a rather large misconception on how it needs to work
can you link me to an info about this clustering i need for discord?
huh ? no lol, i got those samples from github ages ago when i was looking for random colors, thought they were neat 😛
@tardy estuary
haha im just messin
i said in here a few days ago that I don't see a good use case for the embed colors. it's too small of a sliver to provide a user a good understanding of what it means, so I decided to just make it random
So i dont understand how i can use a cluster to ensure the same guilds stay on the same vps?
yeah that might be about it. but i mean their name is already a color so it just seems redundant still (imo)
@viral spade YOU CANT
but using it for an error color or something is kinda.. not helpful imo
Clustering is the method of splitting shards into seperate processes
these processes can potentially be split across machines
yea, thats true lol
but your bot is in 16k guilds its no where near the size to where multi machine scaling is needed
i am rebuilding it now and i want the next version of it to being able to sustain 1.000.000 servers
ideally
or just be horzontally scalable
At that point, it must have already been horizontally scaled really
unless you like wasting resources
yes so is there a way to scale horizontally in such a way, that each set of guilds has its dedicated vps and local database forever? When a new guild adds the bot, it gts assigned a vps and stays there forever?
no
aight, thanks
unless you set it to like 500 shards, and never change lol
wouldnt creating a single bot for each vps work, tim?
i am asking in theroy
split the shards into seperate proccesses
and no
diffrent bot
different account token everything
dude i am thinking about a way to achieve this "yes so is there a way to scale horizontally in such a way, that each set of guilds has its dedicated vps and local database forever? When a new guild adds the bot, it gts assigned a vps and stays there forever?"
people rlly need to learn how to scale shit earlier on smh
and the same time you say i dont need to care about this yet with 16K
you mean having separate bot accounts for each vps?
ye
i mean, in theory it could work, but that just sounds like even more work to maintain
you cant create a bot account programmatically though can you?
its just avoiding learning how to properlly scale stuff
and no
not without getting banned
you shouldnt even need seperate VPSs at 16k guilds
@modest maple
people rlly need to learn how to scale shit earlier on smh
@modest maple
i am doing this
🤨 Learn about splitting shards up into seperate processes
read d.js docs on the sharder
will it achieve this: "scale horizontally in such a way, that each set of guilds has its dedicated vps and local database forever" ?
get that idea out of your fucking head
that is not how you should scale shit
that is not a robust system
that is not good
id call that the perfect scaling, but as tim said, the solution with maintaining different bots sounds like more work
no its not
because what happens if a guild gets sent to the wrong thing
what then
that vps has fuck all on that guild
Your system should be able to scale regardless of being on seperate machines
or on the same machine
you should start by just not having your bot run on 1 freaking process
isnt the sharding manager creating 1 process per shard per default?
NO
theres no reason to be mad at someone for asking questions
that would be a awful waste of reasources
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
it would help if you read up even a little bit into more depth on how sharding works
and why it exists fundamentally
Linck01 is your bot really in 16k guilds already?
y
i mean, if someones bot was that successful I feel like they would already understand a majority of this
but perhaps not
its not a new bot
@viral spade honestly, if you want to go for database clustering, you should give up on mysql
mysql is simply not designed for that, mysql works best as a single-machine mega-database
idek how the bot got so big considering some of his logic
i just dont want to redo everything at 100K servers, preferably also not at 500K servers, but only "add new nodes to my cluster" you know^^
thats litterally what clustering is
with one database and proper caching on all shards, i doubt you will need horizontal scaling on the database side
Discord makes it so freaking easy to split processes and multi machine bots
by that point you should probably just have a online host for the db and let them scale it for you
cassandra gud
no point scaling the db if he cant scale the bot lmao
the db is the only problem
the thing is that his bot is highly reliant on the database
should of ditched Mysql before hand then lol
or set up a cache db aswell as a buffer
whats he trying to do
hes at 16k guilds with zero knowledge of how sharding or clustering works
that is what is happening
i mean the bot runs on different vps perfectly right now
odd
with an in memory local cache of every guild that is on that vps
i cant, this is too much for me
then get out :^)
so what database you could recommend me for a stats bot like this?
mongodb/mongoose imo
that works well for scaling and discord and everything
heyo Tim 
would you be able to help me yet again
https://discordapp.com/channels/264445053596991498/272764566411149314/708391887307800767
why do you need to break an if? just end the if block :/
i dont want when the code come in if() it will stop, and dont read code anymore
it's not even brake
dont use return if u dont want it to stop
yes but not on forEach loop
return won't work on forEach loop
I mean there's else if and such
oh
you cant stop a forEach unless you error it
yes i only need stop on else if
if you intend on using a lot of else if, consider using switches
you can continue a foreach i beleive, never used it myself
what's the point of that
noop
that doesnt work in forEach
shouldn't this work on mysql nodejs? connection.query("SELECT * FROM timezones").then(data =>{console.log(data)})
yeah
this is better then stackoverflow xD
You cant stop a forEach loop
tf does a continue do
not without erroring it
for (i = 0; i < 10; i++) {
if (i === 3) { continue; }
text += "The number is " + i + "<br>";
}```
yes it will work if you have a table called timezones @earnest phoenix
skip to next iteration
i do
okay
but it says it's not a function
@earnest phoenix if you use promise mysql, it should work, if you use default mysql, that's on callback functions, also what it returns is an array
TypeError: connection.query(...).then is not a function
did you define connection
yes ofc
let connection = mysql.createConnection({ host: process.env.host, user: process.env.user, password: process.env.pass });
it is that
dont think the mysql module works like that
have you tried reading the official docs?
u need a callback..?
query doesnt return a promise ^^
u do
it takes a callback
yes
ew lowercase env variables
so sql, (data => {}) instead of using a .then
yes
uh
the first one is the error
but (error, results, fields) => {}
no
so no
did you say there was a version of sql that works with promises instead of callbacks?
u wouldnt get real data
.then only works for promises
i answer yes to everything
u need a callback function and the first argument is the error if there is any
yes mysql2/promise
the second is ur actual data
const [rows] = await con.query(fuck)
what does that do
same shit
connection.query('database you deal with', (<error>, <rows>, <anything else you need>) => { code in here })
@earnest phoenix this is callback default mysql
if you install and set up promise-mysql, you can use .then
use promise-mysql or mysql2/promise?
mysql2/promise is better
mysql2/promise is mysql2 with promises
with what would mysql2/promise be better 
yes
so its just the promise branch that has promises
cleaner syntax
compared to promise-mysql
promise-mysql is a different package
is the connection code still the same
yes
it is, yes, but it seems to work quite good for me
depends, for promise-mysql I had to change some things around
does it deal with reconnecting itself?
because the reconnecthandler i got from overflow is not working
and make it like this:
(async () => {
bot.db = await mysql.createConnection({
host: 'ip',
user: 'user',
password: 'pass',
port: 'port',
database: 'db',
});
console.log('DB Coonected');
})();```
inside my `index.js` file, what I do is I bind the connection to `bot.db` and I have to await it, otherwise it can't do proper query
wdym reconnect handler
oh ggod, good spot imma fix that
function handleDisconnect(conn) {
conn.on('error', function(err) {
if (!err.fatal) {
return;
}
if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
throw err;
}
console.log('Re-connecting lost connection: ' + err.stack);
connection = mysql.createConnection(conn.config);
handleDisconnect(connection);
connection.connect();
console.log("reconnected")
});
}

hmm so i can't just connect in the beginning inside bot.on("ready"... ?
oh, when you do reconnects your "ready" event should be ran again
you can do the connection in there
I do mine outside of my on ready event
as I access it in other events as well
and I dont use reconnect handler as I have pm2 which so far works good enough for me
actually
it doesn't matter
you can even use the original mysql
i wanted to use promises though
you don't necessarily need promises
well in that case you can use mysql2
and require it as mysql2/promise
i sent it
i thought it had a separate page
Using discord.js v12, Is there a way to check if a link is a working mp3 url?
Will the V11 still be usable after October?
For example http://episodes.ne.fm:8000/bbcradio1
No @winged remnant
I have several versions ... @smoky spire
Tim can you tell me what clustering db you would choose for my bot, and how/where you would host the cluster? Would you take a managed cluster or install in on your own machines? I just saw the mongodb cluster prices for amazon/google/azure on the mongodb website, and they terrify me a bit..
@winged remnant ?
Let the V11 be deleted.
When the code is ran it just returns "what are you THINKING man ..."
if (
message.content.includes(r1) ||
message.content.includes(r2) ||
message.content.includes(r3)
) {
return message.channel.send("if this message shows up then it detects the correct input");
} else {
return message.channel.send(
"what are you THINKING man that's not a valid option from the list??"
);
}
})
hi so if I have this let prefix = config.prefix; how would I make it so you can set a custom prefix with mongodb i already connected it but i dont know what todo
hello can any bot developper sms me please and thanks
Just ask
Is there a way to check if an link matches a following extensions
.png, .gif, .jpg - Basically all the image formates
Is there an easier way to do the message.content.includes?
just check if it that link ends with these
its easy to filter through just the image ones
I mean I am trying to do a stream command using discord.js. So I want to make sure no images linkes are there
for example stream blabl.png - Should give an error
@viral spade honestly cant say, i've never used anything other than sql, but if you're up for a little experimenting, take a look at one of those newer ones, like yugabyte and cockroach db, otherwise mongo is known to be easily clusterable, but i would personally go for a vertically scaled remote rdbms and work on efficient caching and transactions, because thats what im most familiar with. if it gets very bad, you can always throw a redis cache in the middle. alternatively if you prefer a fully managed and automatic solution and dont mind paying for it, check out google cloud spanner
Any solution for this #development message
again, just filter out the image types, thats the only way i know
if that link ends with .png, give an error
There is alot of image types that is the reason
what are you trying to do?
A stream command
to play mp3 links only - For example http://episodes.ne.fm:8000/bbcradio1
make a request to it and check the response headers
its much easier and better to check if its a valid audio stream, than to check all other possibilities (theres literally thousands of other possibilities)
What do you mean by response headers
when you make an http request, for example using node-fetch or any other http library
you can access the response headers
I am confessed 😐
what are you using to play this link?
connection.play(<args[0]>, { volume: 1 }); ```
let connection;
try {
connection = await VC.join();
} catch (error) {
console.log(`Error On play.js : ${error}`);
message.channel.send(` **Error occurred! Please retry the command again or contact support - https://discord.gg/xxx**`);
}
doesnt it throw an error if you play an invalid link?
well then i'd make an http request to it
I have no idea how to, that is why ...
Also how did you do this - #development message
have you ever used a library like node-fetch, request, got, axios, snekfetch?
open dev tools in chrome
check network tab
then open firefox's dev tools
Where will it be?
so, you can use an npm package like request to check the content type of the url
how would I get an sql server for quick.db
for some reason firefox doesnt show the headers for that page lmao
thats why i dont use firefox, full of weird shit
chrome is where its at
open dev tools, go to network tab, reload the page, click on first connection that appears in the network tab, click headers
OOh DAM
Thoughts on Dart? I just stared learning it today and it looks amazing
its used for dart throwing
yes, thats why you have to use a library like request
you can make a HEAD request instead of a GET request, to check only the headers, and not download any content
And what should the header be?
there are a few more
(node:12132) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
user_id: Value "@smoky cedar" is not snowflake.
Anyone knows something about this APIError?
ooh 👀
theres about 5 or 6 audio mime types, although not all types are used by streams
you would do something like this: ```js
let audiotypes = ["audio/aac","audio/mpeg","audio/opus",...]
let check = await request(url,{method:"HEAD"})
if(audiotypes.includes(check.headers["Content-Type"])) {
connection.play(url)
}
@smoky cedar remove the <@! >
look whos back back again
@quartz kindle Thank you Tim for the help 🙂
oh tim i have something for you lol
oofs RIP
if its something super basic, ill just tell you to go learn javascript
he is yping
typing*
My spelling oofs
One more small question will you tube links be blocked by this? - @quartz kindle
#development message
YouTube, Sportify and etc ..
if you give it a youtube link directly, it will not contain an audio type
because the audio is in a player on the page, its not a direct link
ooh i see
what do I have to do, to have always embedded images in rich embeds that I get from deleted messages?
const mFiles = await message.attachments.map(a => a.proxyURL);
if (mFiles.length >= 1) {
for (const a of mFiles) {
if (a.toString().includes('.png') || a.toString().includes('.gif') || a.toString().includes('.jpg') || a.toString().includes('.jpeg') || a.toString().includes('.tiff') || a.toString().includes('.tif') || a.toString().includes('.bmp')) {
const mDelete = new Discord.RichEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setDescription(`**Message sent by **${message.author}** was deleted in **${message.channel}\n${message.content}`)
.setColor('#c4150f')
.setTimestamp()
.setImage(a.toString())
.setFooter(`Author ID: ${message.author.id} & Message ID: ${message.id}`);
if (!logChannel) { return; } else if (logChannel) { return logChannel.send(mDelete); }
} else {
const mDelete = new Discord.RichEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setDescription(`**Message sent by **${message.author}** was deleted in **${message.channel}\n${message.content}\n**File format not an image: **${a}`)
.setColor('#c4150f')
.setTimestamp()
.setFooter(`Author ID: ${message.author.id} & Message ID: ${message.id}`);
if (!logChannel) { return; } else if (logChannel) { return logChannel.send(mDelete); }
}
}
}```
didn't expected it to be that big, but anyway for that code I get like 50/50 chance of the image to not be set in the rich embed
and it'll just log that a message was deleted
so I'm trying to see what do I have to do to have it constantly get the image's links and have them in the embeds
@quartz kindle Just one more questions.
Is it possible to get the name of the stream to?
no
ooh ok
streams are just data, nothing else
you'd need to get the name from somewhere else
So it is possible?
like a page about the stream, if it exists
for example, if you load http://episodes.ne.fm:8000 and search for "bbcradio1" you will find it
but thats only for that specific website, all websites are different
sometimes you can find some metadata in the header
metadata - ?
@hollow prawn if that's from a messageDelete event, i dont think thats possible, as discord deleted the images before your message arrives
@heavy marsh it will always depend on the website, broadcasting system used by the website, custom fields set by the owners, etc
OOh ok
it is from messageDelete event, it takes a bit of time until discord deletes the images
like 5-10 minutes
as I get the proxy URL
well if it works only 50% of the time, clearly not
it's weird, if I spam delete images it works 50/50 time
if I do it slower, it always works
how did u guys do that
and if I do multiple images from phone, then delete them, I get more entries in the mapping
how to do the colored text
prob
console.log the urls to see if they are not being duplicated or messed up with
yeah, but I can't figure out what, no global variable, already did, logs the URL links properly without an issue and returns them in an array even if its 1 link
that code is run inside an IF statement that checks if the bot has the permissions for sending messages and embedding links
and before that I check if there's a logging channel on the database or not
even if I use forEach same thing
try console.logging(a) before sending
const request = require('https')```
for this - [#development message](/guild/264445053596991498/channel/272764566411149314/)
alright
you can use the https module, but that module is more complicated to use
no lmao
hmmm
Then what request should I use
if you want something easier, check out got
got - ?
yup, logging a properly without an issue
got is the name of the package, check their npm page
let HighestAmountOfVotes = -1
let Winners = []
await ParticipantArray.forEach(async Participant => {
let AllVotingDocsOfParticipant = await VotesSchema.countDocuments({Type: "Vote", UserName: Participant})
if(HighestAmountOfVotes < AllVotingDocsOfParticipant){
if(Winners.length == 0){
HighestAmountOfVotes = AllVotingDocsOfParticipant
Winners.push(Participant)
}
else{
HighestAmountOfVotes = AllVotingDocsOfParticipant
Winners = []
Winners.push(Participant)
}
}
else if(HighestAmountOfVotes == AllVotingDocsOfParticipant){
Winners.push(Participant)
}
})
let WinnersString = ""
console.log(Winners) --- Logs an empty array
does anyone one know why it does not await the foreach before moving on?
.forEach isn't fond of await
Does anyone know how to give someone a Role?
i tried this:
message.author.roles.add(role)
^
TypeError: Cannot read property 'add' of undefined
using for ( X of Y ) { do magic }
@sterile minnow whats your version
you're adding a role to a user not guild member
^
djs 12
users don't have roles
you're adding a role to a
usernotguild member
@hollow prawn how do i fix it?
@hollow prawn what would x and y be defined as
@earnest phoenix forEach cannot be awaited
X is your entries of Y array
I’m struggling to keep my bot up 24/7
yeah but i have two users
Remove add and only add
https://tayron.is-inside.me/h0dWzagM.png thats member
wdym you have two users
i have author and member
and to who do you want to add the role?
i want to give them both the role
message.member will give you the author of the message in a member object
message.mentions.members.first() will give you separate member object that's the first mentioned one
there are two different things in discord.js: User and Member
a User contains things like username, profile picture, etc
a Member contains things like nickname, roles, etc...
message.author is the User of who sent the message
message.member is the Member of who sent the message
for it, you do member.roles.add(role)
as you have defined it as a member in your code
you can check the docs for removing, search for GuildMember in v12 and look for it if you're not sure for something
i haven't used v12 so idk for sure, but should be the same as .add
instead of .add it should be .remove and again with (<role>)
okie
Tim still I get this ...
let streamlink = args[0];
try {
let audiotypes = ["audio/aac","audio/mpeg","audio/opus"]
let check = await got(streamlink,{method:"HEAD"})
if(audiotypes.includes(check.headers["Content-Type"])) {
let connection;
try {
connection = await VC.join();
} catch (error) {
console.log(`Error On play.js : ${error}`);
message.channel.send(` **Error occurred! Please retry the command again or contact support - https://discord.gg/**`);
}```
alright, console.log it
@heavy marsh it appears the content-type is lower case
I'm thinking maybe the issue comes from the "if" statement
Let me re test
is there a way I can reduce it without chaining multiple else if?
@quartz kindle Thank you it works well now 🙂
@heavy marsh may I dm you?
About what exactly?
That command actually 😂
I was wanting to do something similar for my bot but for some reason everytime i try it crashes
so i was gonna see if youd wanna trade your code so i can learn
ah ty
Bruh why no android
that's language
js is a language not a library
THATS A LANGUAGE
the library you use to communicate with discord
you ask me
discord.js? eris?
yes
I don’t think it’s possible with either of those actually
it is
is it
you can supply ws options on both
well idk the syntax
Just edit the source it will work
too much work
Basically you go to node_modules to discord.js
not recommended
$identifyProperties: { $browser: 'Discord iOS' }
Well fork the github then smh
lol the fact that you have to fork to do it means that it isn’t supported
..just saying
it's supported in djs
you’ll probably run into problems in the future if you fork the lib
Nah theres a thing called maintaining
yeah but you don’t get that maintenance if you run on a fork
or just run on base repo and don’t fork packages you use
Or dont be lazy and control your packages instead of letting them be controlled 
don’t know about you but trying to maintain forked packages is probably a pain
and a waste of time
it’s not lazy it’s just pointless, if you want something to be added you open an issue
or a pull request
Useless prs get denied anyways
if you’re forking for a useless feature then wtf are you doing lol
Im forking because im not going to move to these managers lol
But the versions after managers has bug fixes
And no ones gonna accept PR stuff for an old version lmao
eventually ur old version will just become obsolete
Not if you maintain it 
pain in the ass
I have enough javascript knowledge and github knowledge to maintain it until november
yea literally
discord.js v11 community edition
i wanna work on the code I wrote not some else’s lol
lmao
which is what that maintenance is doing
I'd rather maintain for months by cloni g commits into my fork rather than update my entire bots core with all its other npm packages because these damn devs thought adding .cache to everything was a good idea
scrolling though commit history to find patches I should make to my fork based on my assumption of how important it is doesnt sound like a good long term model
managers are good
didnt eris start as a discord.js fork?
probably lol

@white anvil "how important" yeah no
create a discord.js fork with optional caching
you’re the one that said that you’d patch in ‘important’ bug fixes ¯_(ツ)_/¯
I just update everything which has bugs, which is basically every commit nowadays
i mean, the only thing you have to do to keep v11 running is supporting intents and changing the domain name
Yes important as in guild.available never turning false causing a massive fake event spams is pretty important
@grizzled raven you don't have to use caching lol
oh you're gonna fork v12 pre-caches?
what is all this shit about .cache anyway
Im only gonna update when i get my bots 50k lined code in its core and npm packages fixed for this managers bullshit
i don’t follow the bloatville that is djs
lol
did they just make collection have shit like limits and expiration
it makes sense, and its good for the library, but v12 has been in development for years, so people started porting their bots to v12 while it was still in development, then they introduced the managers change and fucked over hundreds of developers who have been using the v12 version lmao
yeah the lib I use has that, with a .cache property
You can manage ur memory urself jacher
I cba to look through like 100k lines of code to fix this shit
but all the methods you get on Map also exist on the Collection class it has
it was a big breaking change, which is normal because the lib was in development still, but everyone was using it as if it was stable because its been in dev for years
which means you never need to reference the .cache property
don’t see why djs wouldn’t introduce that
Yeah but then still lmao
you do, all the collection methods were moved to a .cache property
did they just make collection have stuff like limits and expiration
@white anvil two different classes, LimitedCollection and Collection
Why didnt they add it like a year earlier
they dont exist on base anymore in v12
big brain devs
It was easier to maintain the backend with managers
yeah with the lib I uses you can just do .members.get
even though the actual cache itself is .cache
pretty neat
the reasoning is that the cache property handles all sync operations, while the parent class handles all async operations and rest methods, in order not to have them mixed up in the same class
They shouldve done it in v11 tbh
what difference would it make
what rest methods even exist on those caches
fetch
rest methods dont exist on the cache
on all managers
.fetch for example
oh
Now i guess with all this talk our bots are messed up anyways
yeah i just don’t use that stuff
I have a rest client
that I use for basically all my rest operations
you're using a custom lib?
Is there a way to refer .cache back to its collection but keeping .cache a thing
thats basically what im gonna do as well lol
Does anyone know how i can sort this map by the number of votes
whats its name?
@earnest phoenix you can extend the classes and add getters
https://github.com/detritusjs/client-rest this is the rest client
Which classes though
https://github.com/detritusjs/client this is the gateway client, which implements the rest client
Like i want to update, but keep the normal methods, do i just get getters insode my fork or where
Since i dont want my npm packages to break bcz some depend on the old cache methods
so you just want to have all the regular Map properties available in the base object
?
Yes
yeah this has both
.cache for all discord.js shit that changed and the base ones for everything outside discord.js
if I understand what u mean
yup 😃
it has getter methods for stuff like get, has, set
I dont rlly get "getters" how are they defined
Like the functions or actual "get"
they’re just properties that fetch a value dynamically from somewhere else
get thing() { return 'thing' }
MyClass.thing
Wait get on a clear/delete wouldnt work would it
wdym
Any Script Program?
Deleting via the base, "get" on delete wouldnt work?
I suppose managers introduced members.cache.delete while removing members.delete?
Hmmm..
via getter
Ill just compare the files that changed soon i guess
With my knowledge (and a 9 for javascript in school) i should probably find out how to

