#development

1 messages · Page 1742 of 1

umbral zealot
#

Personally I even prefer better-sqlite3 which is sync and blocking but the performance and synchronous nature more than offsets that cost imho.

quartz kindle
#

yes i use it too

#

because with synchronous-off, the blocking is extremely short

#

writes are simply handed to the OS

#

it doesnt wait for the write to actually happen before it unblocks

stiff lynx
#

@zenith terrace

umbral zealot
#

you're not providing a URL or connection string or anything

#

Mongoose can't magically guess where to connect and what credentials to use

umbral zealot
#

Where?

#

not in this code you're not

stiff lynx
#

I have It in my main

umbral zealot
#

Right, but not HERE

stiff lynx
#

but why shoul I connect again, my .beg and every command works withoht connecting in every command

umbral zealot
#

You're using const collection = new Collection(); in every single command that connects to the database?

stiff lynx
#

no

umbral zealot
#

Ok so why here then

stiff lynx
#

because I need It for my leaderbord

umbral zealot
#

Ok no but my question is, why are you requiring mongoose here and doing new Collection();, empty, no name, as a brand new connection

#

should you not be exporting/importing that existing mongoose connection as a module or something

pale vessel
#

that's just how mongoose works

#

¯_(ツ)_/¯

stiff lynx
pale vessel
#

to evie

#

you don't need to link it

stiff lynx
pale vessel
#

yes

#

but not exporting it

umbral zealot
#

ugh mongoose is so damn weird

stiff lynx
slender thistle
#

Or as we say here

#

fax

stiff lynx
#

return message.reply(Devi aspettare ancora ${(time_left.toFixed(0)/60)} secondi prima di usare ${command.name} 😢);

#

the output of this cooldown is too long

#

@stiff lynx, Devi aspettare ancora 59.86666666666667 secondi prima di usare beg 😢

#

like this

#

how can I have less output numbers?

cinder patio
#

use toFixed after you divide by 60

quartz kindle
#

(time_left / 60).toFixed(2)

#

if you dont want decimals at all, better to use Math.floor or Math.round

#

Math.round(time_left / 60)

pale vessel
#

Math.trunc() :troll:

#

wack

earnest phoenix
#

Hello, i have a question,

How can i get count of value in a array.
example:
array = ["10", "20", "10"]

the console return me :
10 = 2
20 = 1

cinder patio
#

loop through the array and keep a map with all values and their respective count

pale vessel
#

reduce bro

#

your fav method

cinder patio
#

🤮

#

great for simple things

quartz kindle
#

array.reduce((a,b) => { if(!a[b]) { a[b] = 0; }; a[b]++; return a; }, {})

#

only works for strings tho, because object keys are stringified

stiff lynx
cinder patio
#

doesn't look like you're doing that anywhere? or am I blind

#

oh I see, I think

#

there's really no point in using map

#

just a regular for loop

#

And also I'd use an object instead of a collection

eternal osprey
#

hey at how many users is sharding a good thing to do?

pale vessel
#

you mean guilds?

eternal osprey
#

no shards

pale vessel
cinder patio
#

guilds instead of users

#

is what flaze meant

eternal osprey
#

oowh yeah

cinder patio
#

users don't matter

eternal osprey
#

how many guilds is a good amount to start sharding your bot?

quartz kindle
#

recommended is 1500

#

required at 2500

eternal osprey
#

alright, thanks.

stiff lynx
cinder patio
#

You have to first sort the users in the database, then get the first 10, then turn it into an array, this is all built-in in mongodb:

const users = await <Collection>.sort({bank: 1}).limit(10).toArray();
#

Afterwards just loop over users

lusty quest
#

lol this convo is still going

cinder patio
#

Not sure why you'd want to count all duplicates though

eternal osprey
#

who made mee6?

#

Is that user in here

cinder patio
#

not really a development question

#

you will probably get an answer in #general

lusty quest
#

yes he is here

sudden gyro
#

Where i make my own bot

cinder patio
stiff lynx
cinder patio
#

It'd be better to use map and join here - so you send a single message

#

<Array>.map((user, index) => `${index++} ${user.name}`).join("\n")
for example

eternal osprey
cinder patio
#

but yes

stiff lynx
cinder patio
#

I don't know your user structure - but replace user.name with what makes sense to you

stiff lynx
#

but how I get the userID in the First Array?

#

in that const users= etc I get Also the userID?

cinder patio
#

user.userId, according to your schema

#

you don't have to do any of that

#

just

#

<Array>.map((user, index) => `${index++} <@${user.userID}>`).join("\n")

limber cobalt
#

guys i need help in something

pale vessel
#

not index++

#

that wouldn't work

stiff lynx
stiff lynx
pale vessel
#

it only increments the value and return the original value (not the incremented one)

#

which is useless as the value is regenerated at the next iteration and it will still start with index 0 instead of 1

stiff lynx
#

because the output Is at the beggining

limber cobalt
#

so my bot needs to access the channel.members, cause i need to know what members are currently in a voice channel. Do i need the Privileged Intent?

stiff lynx
#

ops, nope

cinder patio
#

I usually don't spoon-feed people but I feel like you won't leave me alone until your code works so here u go

limber cobalt
#

I cant find it anywhere

stiff lynx
limber cobalt
#

.py*

#

but i cant find it

stiff lynx
#

ops

#

idk so

limber cobalt
#

i really dont know

#

:/

#

thx anyway

earnest phoenix
#

So, I don't think the privilege intent is really necessary

stiff lynx
#

UnhandledPromiseRejectionWarning: TypeError: profileModel.sort is not a function

#

because I get this

cinder patio
#

Maybe mongoose has a different way of sorting, I only use mongodb

#

you need to get all first before sorting

#

so find({}).sort(...

zenith terrace
#

I did mention it above somewhere...

cinder patio
stiff lynx
stiff lynx
lyric mountain
#

now you gotta feed the whole meal KEKW

stiff lynx
#

I love programming because my parents hates me for no reason

#

and for them I m a failure

#

for that I'm so insistent

#

I'm always trying my best

lyric mountain
#

like, you should try to troubleshoot the errors you come across instead of depending on other people writing code for you

#

programming is 80% googling

stiff lynx
#

I never asked

#

but I would like to know what I'm doing

#

trust me are kinda 2 weeks that I'm trying to do this leaderboard

#

but never worked

slender thistle
#

Maybe that says that you should take a step back and take your time getting hang of the basics

#

You particularly don't want to try to cram everything together and pray it works, case in point being me with my projects that failed because I try to learn on the go

blazing flame
#

hello !

slender thistle
#

JS, MongoDB drivers, you know it

#

Both

#

There's no universal best when it comes to libraries

stiff lynx
#

I've watched a video of 8 hours

#

Is this damned mongodb

#

I never come to a conclusion

#

It is always a problem for me

slender thistle
#

What's the issue again

stiff lynx
#

I think the issue is my life

slender thistle
#

As in the issue at hand

lyric mountain
stiff lynx
#

UnhandledPromiseRejectionWarning: TypeError: profileData.sort is not a function

slender thistle
#

value?

#

Why do I keep thinking of dumb shit today

lyric mountain
#

like, a leaderboard, people with higher score stay on top

zenith terrace
#

yes

slender thistle
#

I literally just now thought of filtering for whatever reason, then got to something like lb.values().sort()

zenith terrace
#

higher the money, higher on the leaderboard

stiff lynx
#

the variable that I created for my schema that is called profileModels

slender thistle
#

Could you show your code?

zenith terrace
#

see also the problem you had with what I showed is that you had other code inside of it

stiff lynx
zenith terrace
#

lemme send a srcbin to show you what I wanted you to try

#

@stiff lynxwhats in the const profileModel = require ('../models/profileSchema'); file

#

models/profileSchema

median moss
#

does anyone here knows Canvas and d.js?

pale vessel
#

Just ask your question

median moss
#

I am making a image manipulation, and I want to know how to declare the new image, so I add it on .setImage of the Embed

const context = canvas.getContext('2d');

const background = await Canvas.loadImage('https://cdn2.bulbagarden.net/upload/thumb/f/f4/Safari_RTDX.png/1200px-Safari_RTDX.png')

const gif = await Canvas.loadImage('https://play.pokemonshowdown.com/sprites/xyani/' + rand.toLowerCase() + '.gif')

context.drawImage(background, 0, 0, canvas.width, canvas.height);
context.drawImage(gif, 0, 0, canvas.width, canvas.height);```
pale vessel
#

you need to upload the image

median moss
median moss
#

ok

vale garden
#

hi does anyone know why my bot is going offline and online back to back

pale vessel
#

for the setImage() you use atachment://filename.extension

vale garden
#

cuz ive never seen that happen before

median moss
#

and I put the .attachFiles inside the new Discord.MessageEmbed?

pale vessel
#

your embed.attachFiles() should look like attachFiles([{ attachment: canvas.toBuffer(), name: "image.png" }])

median moss
#

ok

#

ty

#

what is canvas.toBuffer btw?

pale vessel
#

it generates a buffer of the canvas for you to upload

median moss
#
const context = canvas.getContext('2d');

const background = await Canvas.loadImage('https://cdn2.bulbagarden.net/upload/thumb/f/f4/Safari_RTDX.png/1200px-Safari_RTDX.png')

const gif = await Canvas.loadImage('https://play.pokemonshowdown.com/sprites/xyani/' + rand.toLowerCase() + '.gif')

context.drawImage(background, 0, 0, canvas.width, canvas.height);
context.drawImage(gif, 0, 0, canvas.width, canvas.height);

let avatar = message.author.displayAvatarURL({format: 'png'});
  const embed = new Discord.MessageEmbed()
        .attachFiles([{ attachment: canvas.toBuffer(), name: "hunt.gif" }])
        .setTitle('Pokémon')
        .setColor('#1eb346')
        .setDescription(`${message.author} congratulations, you caught a ` + rand + `!`)
        .setImage('attachment://hunt.gif')
        .setTimestamp()
        .setFooter('Gotta catch em all')
        .setAuthor(message.author.tag, avatar);
  await message.channel.send(embed);```
#

is this correct?

pale vessel
#

try it and see I guess

median moss
#

ok

pale vessel
#

note that it's not going to be a gif since canvas will turn it into a static image based on the first frame of the gif

#

you need to use an encoder like gifencoder to work with gifs

median moss
#

it is giving this error:

UnhandledPromiseRejectionWarning: TypeError: Canvas.getContext is not a function
at Object.exports.run (/home/runner/Bulba-Bot-Recover/commands/hunt.js:79:24)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:1085) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1085) [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.

earnest phoenix
#

You have to create a canvas to get its context

median moss
#

oh, perhaps because I put before the images

earnest phoenix
#
- <canvas>.getContext(...)
+ <canvas>.createCanvas(...).getContext(...)```
earnest phoenix
#

Your error, you're calling getContext() on the canvas itself, not an instance of the canvas, you first have to call createCanvas() to create a canvas instance and then call getContext() to get the context

pale vessel
#

they might have misspelled it

#

the code they sent says canvas while the error says Canvas

median moss
#

I changed everything to Canvas

umbral zealot
#

you literally have a variable called context ....

median moss
#

const idk = createCanvas()

#

?

umbral zealot
#

oh canvas not context. I see

median moss
#

;-;

earnest phoenix
#

...

const canvas = require('canvas');

const context = canvas.createCanvas(...).getContext(...);

...```
median moss
#

oof

#

so I must change everything that is Canvas to canvas

#

?

earnest phoenix
#

Or you can just rename the variable canvas in my example to Canvas

median moss
#

ok

#

and what should I replace the dots?

#

(...)

earnest phoenix
#

With whatever parameters those methods require, the last ... part is whatever code you want after it

median moss
#

I am so f*cking lost 😩 I thought canvas was easier

earnest phoenix
#

canvas.createCanvas(width: number, height: number) -> canvas.createCanvas(100, 100) for example

median moss
#

ok

lament stump
#

does anyone here know anything about repl and website hosting

median moss
#
const context = canvas.createCanvas(100, 100).getContext(100, 100);```
#

like that?

earnest phoenix
earnest phoenix
median moss
#

oh

#

ok

earnest phoenix
#

There's a lot of tutorials out there that can teach you the correct usage of node canvas, so perhaps look at those

median moss
#
    at Object.exports.run (/home/runner/Bulba-Bot-Recover/commands/hunt.js:90:44)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:1229) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1229) [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.```
#

😔

lament stump
#

yeah so, i switched back to repl, cuz no money for vps and i cloned my new github repo into my repl.

const server = express();
const port = 3000 || 3001;

const superagent = require('superagent');

server.set('views', __dirname + '/views');
server.set('view engine', 'ejs');

server.get('/', (req, res) => {
    res
        .status(200)
        .sendFile(
            path.join(__dirname, '..', 'HexagonRepl', 'pages', 'landing-page.html')
        );
});

server.get('/commands', (req, res) => {
    const commands = getCommands();
    res.status(200).render('commands', { commands });
});
server.get('/friends', (req, res) => {
    res
        .status(200)
        .sendFile(
            path.join(__dirname, '..', 'HexagonRepl', 'pages', 'cool-people.html')
        );
});

server.get('/terms-of-service', (req, res) => {
    res
        .status(200)
        .sendFile(
            path.join(__dirname, '..', 'HexagonRepl', 'pages', 'privacy.html')
        );
});

server.get('/changelog', (req, res) => {
    res
        .status(200)
        .sendFile(
            path.join(__dirname, '..', 'HexagonRepl', 'pages', 'changelogs.html')
        );
});

server.get('/snake', (req, res) => {
    res
        .status(200)
        .sendFile(path.join(__dirname, '..', 'HexagonRepl', 'pages', 'snake.html'));
});

/*server.get('/dashboarddevelopertests123', (req, res) => {
res
        .status(200)
        .sendFile(
            path.join(__dirname, '..', 'HexagonRepl', 'pages', 'test.html')
        );
})*/

function keepAlive() {
    server.listen(port, () => {
        console.log('Server is Ready!');
    });
keepAlive();
}```

This does not work. It gives me the error: "Error: listen EADDRINUSE: address already in use :::3000"
#

This is the same web code that I used before, which worked

median moss
lament stump
#

But now it does not

median moss
#

try another port

#

3060

lament stump
#

i did

median moss
#

idk

pale vessel
#

isn't it process.env.PORT or something (at least for heroku)

#

or 8080

median moss
#

I use 3000

#

but process.env.PORT yes, I guess

pale vessel
#

ig it doesn't matter as long as it's open?

median moss
#

🤔

lament stump
#

i declared port as a normal const

#

not a thing i put in my .env

median moss
pale vessel
earnest phoenix
pale vessel
#

at least in heroku

median moss
pale vessel
#

might be same for repl.it, i'm not sure

pale vessel
median moss
#

oh

lament stump
#

Yeah, repl doesn't accept any port rn

#

Any ideas?

median moss
#

no 😦

#

@earnest phoenix it worked now, except that the image is empty

#

I replaced .gif for .png too

earnest phoenix
#

Show current code

median moss
#
const context = canvas.createCanvas(100, 100).getContext('2d');

const background = await canvas.loadImage('https://cdn2.bulbagarden.net/upload/thumb/f/f4/Safari_RTDX.png/1200px-Safari_RTDX.png')

const gif = await canvas.loadImage('https://play.pokemonshowdown.com/sprites/xyani/' + rand.toLowerCase() + '.gif')

context.drawImage(background, 0, 0, canvas.width, canvas.height);
context.drawImage(gif, 0, 0, canvas.width, canvas.height);

let avatar = message.author.displayAvatarURL({format: 'png'});
  const embed = new Discord.MessageEmbed()
        .attachFiles([{ attachment: context.canvas.toBuffer(), name: "hunt.png" }])
        .setTitle('Pokémon')
        .setColor('#1eb346')
        .setDescription(`${message.author} congratulations, you caught a ` + rand + `!`)
        .setImage('attachment://hunt.png')
        .setTimestamp()
        .setFooter('Gotta catch em all')
        .setAuthor(message.author.tag, avatar);
  await message.channel.send(embed);```
earnest phoenix
#

<canvas>.width and <canvas>.height is not a thing, because its not a canvas instance

median moss
#

so I just delete the context.DrawImage stuff?

earnest phoenix
#

<CanvasRenderingContext2D>.canvas.width and <CanvasRenderingContext2D>.canvas.height

median moss
earnest phoenix
#

Basically, canvas.width -> context.canvas.width and canvas.height -> context.canvas.height

median moss
#

ok

#

bruh

#

broken image

#

😐

earnest phoenix
#

Broken?

median moss
#

yes

earnest phoenix
median moss
#

it was supposed to have a background

#

and the pokemon format is strange

#

😔

earnest phoenix
#

Wdym format?

median moss
#

this is the normal

earnest phoenix
#

Also you're drawing both on top of each other, if the pokemon image doesn't have a transparent background, the image that was drawn before the pokemon image wouldn't appear

earnest phoenix
#

how can i add screen shots to my bots description?

median moss
#

oh

#

nvm

#

html

#

.-.

earnest phoenix
#

he told me to come here

earnest phoenix
# median moss and how to fix that

The pokemon image you're loading is actually a gif which gets converted into a png that applies a white background to it, try loading the first frame of the gif first or manually get the first frame and load it

pale vessel
earnest phoenix
median moss
pale vessel
#

<img src="url" alt="alt text"> or ![alt text](url)

earnest phoenix
#

in the description or bot?

#

In the long description

median moss
earnest phoenix
#

ok thx

pale vessel
#

how can i add screen shots to my bots description?

median moss
pale vessel
#

why would it be in your bot

earnest phoenix
#

oooof for me

median moss
#

@earnest phoenix I loaded the gif first but it keeps on that way

#

😔

earnest phoenix
#

¯\_(ツ)_/¯

median moss
#

so what should I do then?

wheat loom
#

hi. so im a big php fan and its the language i love the most
i was wondering if DiscordPHP has any performance issues

wheat loom
#

i see it uses ReactPHP for making things asynchronous. afaik ReactPHP always did well on all of my projects

limber cobalt
#

so i can access all users in a voice chat at a given moment without the privileged Members Intent?

limber cobalt
#

can i safely remove the members intent then?

#

@earnest phoenix

stiff lynx
#

in the sourcebin is swhou

lament rock
#

I was not meaning a small amount. I was meaning a ton

lusty quest
#

lol the convo is still going

zenith terrace
#

yep

cosmic forum
#

Hello! Anyone know what the dom property is to style scrollbars with js?

earnest phoenix
earnest phoenix
pale vessel
#

just use canvas?

#

is it not transparent

earnest phoenix
#

Using canvas to load a gif and draw it automatically casts it to a png format, which applies a white background instead of a transparent one

deep mantle
#

Hey I use discord.py and I am editing an image with PIL and want to send it as the image of an embed, but it doesnt work

    e = discord.Embed()
    with Image.open('baseForProfile.png') as im:
        newim = im.copy()
        newim = newim.filter(filter=ImageFilter.BLUR)
        
    e.set_image(newim)
    await ctx.send(embed=e)
earnest phoenix
#

Try replacing e.set_image with e.setImage(newim)

deep mantle
pale vessel
earnest phoenix
# pale vessel No?

Strange, seems like that only happens when drawing an image before drawing the image from the gif

pale vessel
#

like this?

#

not sure what you mean

earnest phoenix
pale vessel
earnest phoenix
deep mantle
#

Thanks!

deep mantle
snow urchin
lyric mountain
#

"dangerouslySetInnerHTML"

umbral zealot
#

yeah React doesn't like when you set HTML directly

#

but it's necessary sometimes

quartz kindle
#

because its vulnerable to injections

earnest phoenix
#

does react allow dangerouslySetInnerHTML on custom components

cinder patio
#

hmm... it looks unnecessary here

#

Replacing a part of a string with a custom react element...

quiet pawn
#

anyone got suggests for a cheap vps to host my bot on (js)

pale vessel
#

GalaxyGate, Contabo

quiet pawn
#

because i just realized i cant use my mongodb on heroku

quiet pawn
#

what one should i use?

cinder patio
#

...what's that url about

quiet pawn
#

its my image hoster

#

just being ass

#

wont embed

cinder patio
#

takes me to something sus

quiet pawn
#

its a image hoster

#

pays.host

#

its supposed to embed it inyo a image

#

ill try again

#

workkk

#

there

cinder patio
#

how big is your bot

lyric mountain
#

side toolbar

quiet pawn
cinder patio
#

server

quiet pawn
#

190

#

with over like 70k users

cinder patio
#

And how much servers is it getting added in per day

quiet pawn
#

umm

#

2 - 6

cinder patio
#

do you cache everything?

quiet pawn
#

i gained 40 in last 3 days

quiet pawn
#

lmao

cinder patio
#

Get the cheapest one

quiet pawn
#

so the 3$ one?

cinder patio
#

yep

quiet pawn
#

oki thank you

lyric mountain
#

galaxygate is quite expensive tbh

quiet pawn
#

well cheaper then most i have seen

#

i would just moved to paid heroku

#

but thats like 40$ CAD

#

@cinder patio sorry got ping quick question is there a suggested time ishould upgrade from 3$?

#

because of how fast my bots growing

lusty quest
#

if you are get to 40$ better get a Root Server

#

better Price/performance

quiet pawn
#

im trying to keep as low as i can on price

cinder patio
quiet pawn
#

im a student money isnt the best

#

lmao

quiet pawn
#

i saw

lusty quest
#

ive needed to get some faster CPU bcs of Machinelearning, and the only thing Digitalocean offers as the "cheap" upgrade costs already 40$/Month for 43$/Month i can get a Root server

quiet pawn
#

damn

cinder patio
#

Most discord bots aren't CPU intensive

#

they do be memory hogs tho

lusty quest
#

you can make them relatively efficent tho

#

ask tim

cinder patio
#

of course

#

tho

lyric mountain
quiet pawn
#

yea

quiet pawn
#

shouldi get a ram plan then?

lusty quest
#

ive got started with 1GB ram, worked for a while but if you can afford more ram is not bad

cinder patio
#

I would wait until your bot grows and uses at least 1 GB

quiet pawn
#

oki

cinder patio
#

otherwise you'd be wasting money

quiet pawn
#

yea

#

makes sense

#

with vps do you move your files

#

or can u link like a git

cinder patio
#

git is ideal

quiet pawn
#

epic thats what i use rn witrh herouku

#

so shouldnt be bad

cinder patio
#

but you can also use FileZilla or similar tools to transfer files via sftp

quiet pawn
#

yea

clear marlin
#

git is da best

quiet pawn
#

i'd rahter kms then use FileZilla that just me lmaoo?

lyric mountain
#

I'd not trust ftp for source-code transfer

quiet pawn
#

anyone got ideas for being abel to edit my code anyways

#

insead of just on desktop

#

like if i needa use my laptop

lyric mountain
#

just use git to keep all the places in sync

quiet pawn
#

i used repl for a bit to edit code then send it to git then it would update in heroku

#

but repl stopped working didnt supprot some of my pakages

lyric mountain
#

clone ur repo locally

quiet pawn
#

but then if i edit on desktop

#

thjen go on laptop and edit

lyric mountain
#

yes

quiet pawn
#

it just deleted everything new i did on desktop

lyric mountain
#

that's what git is for

quiet pawn
#

and replaces with laptop

lyric mountain
#

no

#

git knows how to merge stuff

quiet pawn
#

you mean like pull it before i do?

lyric mountain
#

that too, but even if you forget to do it git 99% the times can auto-merge the code

quiet pawn
#

o

lyric mountain
#

the last 1% it'll ask you to choose which line to keep

quiet pawn
#

that crashed my bot before thats why i stopped

#

it started duping files

#

and code

#

but yea ill try again, thank you

verbal vault
#

what is c#?

umbral zealot
#

A programming language.

verbal vault
#

how many different ones r they?

umbral zealot
#

There's... .a few hundred of 'em

verbal vault
cinder patio
#

millions

sudden knoll
#

If I'm using postgres for a db, should I open a connection and close on each transaction/query or should I just have one connection and leave it open the entire time?

cinder patio
#

the latter

sudden knoll
#

okay thanks

#

the same thing with the cursor? or should I close the cursor?

cinder patio
#

cursors time out after a certain period of time

#

so there's no need to close em

#

oh wait postgres cursors not sure about those

sudden knoll
#

okay thanks

#

regardless though, I should make a new cursor on every transaction

cinder patio
#

yea

deep mantle
#

Hey I want to paste the avatar of a user on an image using PIL, but its giving me the ValueError: Cannot determine region size, use 4-box item
My code:

    with Image.open('baseForProfile.png') as im:
        newim = im.copy()
        
        
    
    newim = newim.paste(ctx.author.avatar_url)
    newim.save('newprofile.png')

Anyone know how to fix this?

neon swift
#

You want to download/read the image from the avatar_url and read the bytes into a PIL image

dense spire
#

does the bot.commands have a command queue somewhere? I want to not allow overlapping commands but dont want to make my own queue if i dont have to

#

for python

slender thistle
#

Oh oops

slender thistle
dense spire
#

for not wanting overlapping commands? certain commands change different but potentially overlapping info within my database so i want the commands to wait for the changes of one before going with the next.

#

I was hoping that the discord bot libraries had natural support for a command queue but if not ill just try implementing asyncio stuff

#

currently im using cooldown

#

but i want the commands to be able to run after the other

#

instead of just denying it

slender thistle
#

I'm not aware of any built-in command queue that d.py provides

dense spire
#

rip

#

alright thanks

slender thistle
solemn latch
#

i believe one of the virus checker bots on py uses redis queue iirc.

slender thistle
#

You can write one with just asyncio yourself

cosmic forum
#

Hi! Anyone willing to give me some feedback on the design and layout for my site? https://aakhilv.me/

feral aspen
#

Good job on the website, dude.

umbral zealot
#

WHY. WHY DO YOU TAUNT US SO

dense spire
#

Ive been fooled

umbral zealot
#

Also, ads. ads4ads. ads on ads. ads in ads.

#

This "Reduce on hover" is... weird.

dense spire
#

I agree

umbral zealot
#

Material Design would say this is supposed to grow not shrink .

feral aspen
#
// file "a"
import { add } from "./functions.js";

// file "b"
const add = (a, b) => { return a + b };
export { add };

export default fail() { return "I failed" };

How in the world is export default going to work here?

umbral zealot
#

what do you mean how is it going to work?

feral aspen
#

It's a fallback value, how is it going to work?

umbral zealot
#

import fail, { add } from 'a';

feral aspen
#

Ah.

#

I was wondering how I will import both add and fail.

#

🤷‍♂️

umbral zealot
#

and now you know 😄

feral aspen
#

Thanks for that! 🙂

#

Is the fallback value variable always first defined?

#

import { add }, fail from 'a';

#

Is this allowed?

umbral zealot
#

yeah both work fine, it's not a question of order, thankfully.

feral aspen
#

What about this?

#
const { add } = require("a");
#

I think it would work right?

umbral zealot
#

yes, that would also work.

feral aspen
#
const fail, { add } = require("a");
const { add }, fail = require("a");
#

Sweet!

wooden shoal
#

How would I assign a role based off of a user's custom status?

quartz kindle
#

you'd need the presences intent

wooden shoal
#

I have that lol

quartz kindle
#

then just access their status

wooden shoal
quartz kindle
#

what library are you using?

wooden shoal
#

djs

slender thistle
quartz kindle
#

usually people only have one activity anyway, unless they're like listening to spotify or something

#

the activity contains name, details, type, emoji, etc

wooden shoal
#

I'm tryna use the presence update event

quartz kindle
#

sure

#

same thing

#

the event gives you 2 presences, one before the update, and another after the update

#

either one of them should have a .activities array

wooden shoal
quartz kindle
#

you have to pick one of the activities from the array, usually the first one works

#

so activities[0]

#

that will give you an activity object, which contains name, details, type, emoji, etc

#

the actual text of the custom status will be in one of those, i dont remember which

#

just console.log the entire activity object

zealous egret
#

Is that right?

wooden shoal
#

How do I define the user within the presence event or is it already done? @quartz kindle

sudden geyser
wooden shoal
#

I'd think presence.member right?

quartz kindle
#

yes it should be presence.member

#

or presence.member.user if you want the actual User and not the Member

sudden geyser
#

or just presence.user

#

though both are nullable

sudden geyser
#

You found out your issue.

#

bot is not a variable in scope.

#

So you probably forgot to define your discord.py bot instance.

zealous egret
sudden geyser
#

The name can be anything. It's a matter of you creating an instance of the appropriate class.

zealous egret
umbral zealot
#

hold up, bot.topggpy.guild_count is not your guild count

#

or it shouldn't be?

sudden geyser
#

Like I said,

The name can be anything. It's a matter of you creating an instance of the appropriate class.

This depends on what you're using: a regular bot instance or a command bot instance.

umbral zealot
#

stop moving around like a fish out of water and stick to #topgg-api ?

wooden shoal
#

@quartz kindle user.presence.activities[0].name is not a function

quartz kindle
#

name is not a function

#

its a property

sudden geyser
#

Though if I had to assume, you may be lacking in experience with Python.

zealous egret
#

and how can I know what I have to replace with bot

slender thistle
sudden geyser
zealous egret
#

so what I have to replace with it§

cosmic forum
quartz kindle
#

your bot variable is whatever name you gave it

#

when you created a new Discord client

#

you have to always use the same name you created

#

its something you decide

#

not someone else

zealous egret
#

okay so if this will be MEE6

#

I had to replace it with MEE6

quartz kindle
#

lol

zealous egret
#

?

quartz kindle
#

its your code

#

i dont know your code

zealous egret
#

it was example

quartz kindle
#

its whatever you put in your code

sudden geyser
#

how do we go from a variable name to mee6

zealous egret
#

and where I ca nsee it because I still don t understand

slender thistle
#

Let's say, for example, if you created an instance of a discord.py client under a variable client, you'd use client

quartz kindle
#

how did you create your discord client?

zealous egret
quartz kindle
#

in your code

zealous egret
#

how can I know it

quartz kindle
#

lol

zealous egret
#

with developer protal

quartz kindle
#

no

#

in your code

zealous egret
#

I don t know what you mean

quartz kindle
#

where did you create a new Discord Client from the discord.py package

#

you import discord.py, then you create a new client

zealous egret
#

how can I know it??

quartz kindle
#

show that code

sudden geyser
#

The answer you need is not how to define your Discord client: it's experience.

zealous egret
#

okay

quartz kindle
zealous egret
#

okay

#

this or???

quartz kindle
#

show where you create the client

#

scroll down

zealous egret
#

and whre?

quartz kindle
#

just show your code

#

and i'll tell you where

zealous egret
quartz kindle
#

yes

#

this

zealous egret
#

and what is with it?

quartz kindle
#

you see

#

client is the name you created

#

so everywhere, you have to use client

#

so instead of bot, you use client

#

if you did xyz = commands.BOt()

#

then instead of bot you would write xyz

zealous egret
#

I want still using client.command not bot.command

quartz kindle
#

it doesnt matter

#

the name on the left side

#

is a name that you create

zealous egret
#

So what i have to replace with that bot error

#

this is my code now

quartz kindle
#

this has to be the same as the name you created

#

if you created client then it has to be client.topggpy

zealous egret
#

okay

quartz kindle
#

yes

#

you still have a bot there

zealous egret
#

and now put token in it and it wil works?

quartz kindle
#

this has to be client also

zealous egret
#

like this? I am right

#

?

quartz kindle
#

yes looks better now

#

looks like you still have other errors tho

zealous egret
#

and do you know why?

quartz kindle
#

no i dont

#

whats the error now?

zealous egret
#

wait I am gonna cehck it

wooden shoal
#

Omg

zealous egret
#

still this is error

quartz kindle
#

you didnt save your code lol

wooden shoal
#

Here's what it says now @quartz kindle

zealous egret
#

okay I am go to

sudden geyser
#

There are no activities

quartz kindle
#

yes, you need to check if the user has any activity first

lunar solar
#

can sqlite3.executescript have parameters for values?

quartz kindle
#

if(presence.activities.length) or if(presence.activities[0])

wooden shoal
#

This activity shit is confusing for me

lunar solar
quartz kindle
zealous egret
wooden shoal
#

I'ma make it multi-guild support where people can set what role to award for whatever status they want

umbral zealot
quartz kindle
#

so you either didnt save, or you saved the wrong file

zealous egret
#

and how can I save it?? everytime this wrked as save

umbral zealot
#

Usually CTRL+S in your editor

zealous egret
umbral zealot
#

Then it's clearly not updating the code then

#

not much we can do about that if it can't even bother to save the things you're writing.

quartz kindle
#

did you update the code in the right place?

zealous egret
#

there isn t something like save

quartz kindle
#

show line 59

umbral zealot
#

Or link us your repl. kekface

zealous egret
#

I have token in btw but now i didn t put it in

quartz kindle
#

did you press the stop and run buttons in replit?

umbral zealot
#

why does this still say BOT

quartz kindle
#

@_@

zealous egret
#

Okay I am gonan agai n

#

rewrite it

zealous egret
#

Love you guys

#

and thank you for help : D

slender thistle
#

I really should get the new version done along with docs and an announcement

quartz kindle
#

amen jesus shiva krishna budha alah quetzacoatl

umbral zealot
crimson vapor
earnest phoenix
#

oh god

lyric mountain
slender thistle
#

@earnest phoenix Do I honestly need a custom JSON decoder for DataDict to make it serializable?

sudden knoll
#

could you pickle it?

quartz kindle
earnest phoenix
earnest phoenix
slender thistle
#

I don't subclass dict as of right now but

#

I'm thinking about it

half bear
#

i want to code an +rep system with +rep numbers and -rep numbers. how can i make that and which database should i use (like localstorage or mongodb etc.) (discord.js)

earnest phoenix
#

Can't you json.dumps __dict__

slender thistle
#

Oh probably

#

Let me get back on laptop

near stratus
near stratus
half bear
#

only for my server

#

how can i learn mongo

solemn latch
near stratus
half bear
near stratus
#

Otherwise I was gonna tell you to learn mongoose Schemas

half bear
#

which can i choose here

#

mongo's website is a little bit weird to be honest

near stratus
#

On your VM or Their system (atlas)

half bear
#

windows server 2012 i have my own server rn

half bear
near stratus
half bear
#

oh god finally a short lesson in w3schools

woeful pike
#

those of you who learned programming on a phone, do you have any resources you can recommend for someone learning programming without a computer?

#

There are some tutorials and stuff on udemy but they all require you to follow along with a computer which kinda makes things harder

fair axle
#

Is there any way to edit or delete interaction (message sent by bot)

marble juniper
quiet pawn
#

i just bought a VPS with galazygate and im trying to get my bot on it i have nmever used a vps before and am super confused and cant find much on it can anyone help?

prime mist
quiet pawn
#

dont wanna wait 3 - 8 weeks

#

lmaoo

#

thats why i came here

fair axle
slender thistle
#

Especially considering the fact that users will have to work with it

quiet pawn
#

@cinder patio do you mind helping u suggested it earlier

woeful pike
marble juniper
#

hope the site has a copy paste button

#

and use that

#

and run ur code on something like repl.it

prime mist
marble juniper
#

lol

woeful pike
#

does replit work on mobile?

slender thistle
#

Enough to the point where some people use it

woeful pike
#

interesting

#

probably good enough then

marble juniper
#

it works on mobile

#

lol

earnest phoenix
marble juniper
#

obviously not as well as on pc cuz screensize

#

but like it works ig

marble juniper
#

u can easily switch between code and console and so on

sudden knoll
quiet pawn
#

never used python

marble juniper
#

and like no need to download stuff locally since its replit

slender thistle
#

Don't know where users will have to work with it, but having to do json.dumps(data.__dict__) doesn't look convenient

quiet pawn
sudden knoll
earnest phoenix
#

Thought it's meant to be sent to topgg

slender thistle
#

And to be quite far, what's the harm in subclassing dict?

#

It can go both ways, actually

#

Unless I split it into RequestData and ResponseData? 👀

#

Seems redundant tbh

sudden geyser
#

What's another combo for "from" and "to"?

earnest phoenix
# slender thistle And to be quite far, what's the harm in subclassing dict?

The first one is that it duplicates the data. Your last implementation was binding the value to the key as well as setting it as an attribute iirc. While that might only store the reference, that's not a good option imho. And, the second one, I'm not sure if it's still an issue, but you can inherit https://docs.python.org/3/library/collections.html#collections.UserDict instead. If you subclass a dict, the __init__ and the update method don't call the __setitem__ method. Also, with UserDict, you only have to implement __getitem__ and it'll work the same when you subscript it or calling the get method or doing key in operator (no need to re-implement get and __contains__ method.

prime mist
earnest phoenix
#

I still haven't got the big picture of what you're trying to achieve

sudden geyser
#

It has to be used in the context of a source (from) and a target (to)

prime mist
#

lol. source / target then?

sudden geyser
#

I could just use source and target as well

slender thistle
#

I'll play around tomorrow and see what could fit

#

And sorry for annoying you so early KEKW

prime mist
#

Naming things is one of the hardest parts of programming.

earnest phoenix
#

xd no worries

sudden geyser
#

we can solve all the problems in the world except for naming

prime mist
#

The bot developer's life lol.

pale vessel
#

I bet this Tim is smart too

prime mist
#

I see what you did there.

quaint wasp
#

hey

#

I go this

#
fetch('(something here)')
  .then(response => response.json())
#

but says fetch is undefined.

#

I tryed doing something like const fetch = require('fetch')

#

But it didnt work.

#

😐

#

:.

crimson vapor
#
const fetch = require('node-fetch')
earnest phoenix
#

Which dependence should I use to play Twitch lives.

lyric mountain
#

None, you can't play videos

pearl trail
#

except if you want to use lavalink

lyric mountain
#

No, like, you can only play audio, not videos

pearl trail
#

yeah, audio only ofc

half bear
prime mist
#

*in Node.js anyway

half bear
#

me with bad english: the what

#

oh okay understand it

#

btw i want to make +rep and -rep commands that players can use for other players. i want to show that for every user (if its not created, it will show probably 0 i can make that) but i don't know how to make it with numbers (localStorage)

cosmic forum
#

So I'm using some emojis in my site, and I'm wondering, is there any way that I can keep the emojis in the Microsoft form, and not change into the Apple, Google, etc. emoji forms for all devices?

lyric mountain
#

There's no "microsoft" or "apple" form

#

Emojis are just unicode characters that are parsed by the browser/system

cosmic forum
#

ah

rocky hearth
#

is this also true for class components?

wooden shoal
#

Bruh

rocky hearth
#

does js has something opposite of [].flatMap()

#

I want to convert an array into 2D matrix

crystal wigeon
#

hey umm

#

anyone know how to chain async functions?

#
class Instance {
    async updateOne() {
        return this;
    }
    async set(data) {
        console.log(data);
    }
}```

Lets say this is my instance where i use it like

x = new Instance()
but now to call the functions i have to use it like await (await x.updateOne()).set()

but i wanna use it this way -> await x.updateOne().set() // this throws a ".set" is not a function error
#

@quartz kindle @cinder patio

#

sorry for the pings

rocky hearth
#

conat data = await updateOne().then(val => val.set())

crystal wigeon
#

but

#

how does

#

mongoose do it then

#

they have multiple methods on the same instance

#

like new user().save().something()

rocky hearth
#

now data will have the return value of set

crystal wigeon
#

ik, using then is same as putting parens

#

await (await func1()).func2()

#

same thing

rocky hearth
crystal wigeon
#

the mongoose

#

.find().where().equals()

rocky hearth
#

Ooh, that is called Builder design pattern

crystal wigeon
#

i seee

#

ill check those

#

easier to search now

#

thanks!

rocky hearth
#

behind the scene there're just updating the query, with each function call. Finally awaits it

crystal wigeon
#

yeah but i couldn't reproduce that behaviour

rocky hearth
#

yeah, it will not be very usefull for async tasks

prime mist
#

Anyone here deploy their bot on kubernetes?

cinder patio
cinder patio
rocky hearth
#

so in class components refs are only useful, for referencing dom elements

quiet pawn
glad cobalt
#

hello! I'm making a discord bot in java script and I'm having trouble finding out this error

#

anyone down to help me

#

the error

#

unexpected token )

#

take out a set of `

#

I see

#

i am not using vsc

#

it's like vsc

#

but ig mentally dumb

#

def not

#

forgot that exists

#

should i send a ss

#

or the code

#

k

#

the whole code

#

or the error part

#

client.commands.get(command).run(client, message, args);

      catch(error){
      console.errorerror;   
  }
}

})

wheat mesa
#

Um

glad cobalt
#

what

#

oh god

wheat mesa
#

Use 3 backticks and then paste your code, it’s easier to read

#

(Just a tip going forward)

glad cobalt
#

uh ok

#

thanks ig

craggy pine
#

adding js or what language you use after the three ticks highlights things

wheat mesa
#

^^

craggy pine
#
let likeThis
rocky hearth
#

console.error(error); <--

glad cobalt
#

ok

#

that would make alot or sense of sence whatever

#

._.

rocky hearth
#

u need to provide more code....
and paste that code here between
```js
// below here

glad cobalt
#

so the full line of code

#

that's giving the error

craggy pine
#

tis true tbh. The missing extra ) your error is talking about is not quite visable with your code example.

#

Just do the whole thing if you wish shrug

glad cobalt
#

alr

#

`client.on("message", async message => {

if(message.author.bot) return;
if(message.channel.type == 'dm') return;

if(message.content.startswith(prefix)) {
  const args = message.content.slice(prefix.length).trim().split(/ +/);

  const command = args.shift().tolowerCase();

  if(!client.commands.has(command)) return;


  try {
      client.commands.get(command).run(client, message, args);
     
      catch(error){
      console.errorerror;   
  }
}

})`

craggy pine
#

not quite.

#

I got you.

wheat mesa
#

3 backticks

craggy pine
#
client.on("message", async message => {

    if(message.author.bot) return;
    if(message.channel.type == 'dm') return;

    if(message.content.startswith(prefix)) {
      const args = message.content.slice(prefix.length).trim().split(/ +/);

      const command = args.shift().tolowerCase();

      if(!client.commands.has(command)) return;


      try {
          client.commands.get(command).run(client, message, args);
         
          catch(error){
          console.errorerror;   
      }
    }
})
#

there.

glad cobalt
#

time to be humiliated

#

._.

#

wait

#

i fixed the bottom part

#

so just imagen i did

craggy pine
#

I updated it

glad cobalt
#

lol

craggy pine
#

probably wrong for the console part bec i'm not a js duder but what ev.

glad cobalt
#

its giving the catch part

craggy pine
#

oh good to know lol

#

never used it b4 ngl

glad cobalt
#

catch(error){
^^^^^

unexpected token 'catch'

wheat mesa
glad cobalt
#

oof

craggy pine
#

I think it's try {} catch {} is it not

rocky hearth
#
client.on("message", async message => {

    if(message.author.bot) return;
    if(message.channel.type == 'dm') return;

    if(message.content.startswith(prefix)) {
      const args = message.content.slice(prefix.length).trim().split(/ +/);

      const command = args.shift().tolowerCase();

      const commandToRun = client.commands.get(command)
      if (!commandToRun) return;
      try {
          await commandToRun.run(client, message, args);
      } catch(error){
         console.log(error); 
      }
})
craggy pine
#

ya I was right.

wheat mesa
#

You have to do try{} catch(error) {}

craggy pine
#
try {
          commandToRun.run(client, message, args);
      } catch(error){
         console.log(error); 
      }
})
#

is where u messed up

#

that's the correct way of doing it

glad cobalt
#

i see

prime mist
#
client.on("message", async (message) => {
  if (message.author.bot) return;
  if (message.channel.type == "dm") return;

  if (message.content.startswith(prefix)) {
    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift().tolowerCase();

    if (!client.commands.has(command)) return;

    try {
      client.commands.get(command).run(client, message, args);
    } catch (error) {
      console.log(error);
    }
  }
});
glad cobalt
#

oh I see now

prime mist
#

There, I ran prettier over it as well. You can have that for free.

glad cobalt
#

didn't have to...

craggy pine
#

pretty code is good code

wheat mesa
#

Linters are nice

prime mist
#

I had too, it was making me twitch funny.

frigid mountain
#

What does this error mean?

prime mist
#

It means a native module was compiled for another platform.

#

Probably npm install was run on another machine?

dense spire
#

anyone one know the proper way to pop a function from an asyncio queue

#

pop and run

frigid mountain
prime mist
#

rm -rf node_modules && npm install

#

If that doesn't work, ask someone else lol.

frigid mountain
glad cobalt
rocky hearth
#

u hv an syntax error

#

at which line it is coming from?

glad cobalt
#

40

#

or 1 line after the })

#

and when i go to }) its after that

rocky hearth
#

u have an extra ) somewhere in ur code

#

figure it out. start counting the parenthesis

glad cobalt
#

alr

craggy pine
#

If you use VSC you can click each one and it will show you the closing )
quite handy.

wheat mesa
#

Making a js discord bot is easier in visual studio code

sudden knoll
#

nah, notepad >>>

wheat mesa
#

Rather than relying on your own eyes

#

It’s easy to miss small things

rocky hearth
#

isn't ur vsc complaining about anything?

#

any red lines?

craggy pine
#

he doesn't use vsc

#

said abve.

glad cobalt
#

ya there's a red line

rocky hearth
#

then start using it today. U'll save alot of time

craggy pine
#

red line = bad

glad cobalt
#

yep I can def use vsc

sudden knoll
#

what do you use that doesn't highlight () though

#

that seems pretty standard to me

glad cobalt
#

when I hover over it it's still saying unexpected token. ')' so let me find it

#

found it

craggy pine
#

So delete the ) where the red line is mexShrug

glad cobalt
#

I'm really confused now

craggy pine
#

similar to my code here, red line usually means not right

wheat mesa
#

Think of it like this

#

For every ( there is a ) to match it

craggy pine
#

^

glad cobalt
#

ik that

wheat mesa
#

If you have an extra ) in there, it’ll mess everything up and throw a syntax error

glad cobalt
#

now this aint make a damn cent

#

it's saying that somehow client.login("token")

#

is wrong

#

wtf

craggy pine
#

do you define "token" in a .json or something?

glad cobalt
#

token is my bots token btw

wheat mesa
#

Did you fix the error before that

glad cobalt
sudden knoll
#

what's the exact error statement?

wheat mesa
#

What’s the error

glad cobalt
#

unexpected end of input

wheat mesa
#

Can you paste the code