#development

1 messages ยท Page 1954 of 1

earnest phoenix
#

not it is?

#

๐Ÿ‘€

round cove
#

now**

earnest phoenix
#

ah lol

round cove
#

My brain for some reason always does not

earnest phoenix
#

kekw

round cove
#

๐Ÿ˜”

earnest phoenix
#

I might even turn it into an example bot using typeorm and host it

#

I could make an eval command so people can mess around with making their own queries and such using the typeorm methods.

round cove
#

Oh that'd be cool

earnest phoenix
#

I'd have to sandbox it or smth tho mmLol

#

Anyway goodnight guys its almost 10pm

round cove
#

gn

earnest phoenix
#

don't need help with anything, but i thought this would be cool to share PepeHappy

round cove
#

Good job Clap

earnest phoenix
#

So for this, the first embed is in a messageCreate while the 2nd is in a interactionCreate is there a way I can just edit the first embed? interaction.message.edit? or something of that nature..?

earnest phoenix
#

oh alr

earnest phoenix
#

or nah?

earnest phoenix
#

i remember having to do a hacky workaround for something like this, let me see if i still have it

#

though it's probably easier now that interactions are newer

pale vessel
#

it replaces all embeds with the ones you provided

round cove
#

Hmm, @earnest phoenix for later. I'm able to connect to my postgres DB I made on my server. However, when trying to query/manipulate it, it claims the connection default was not found. I think I found some things online claiming that this is a repository thing but I thought your example was to show how to avoid using that and just use the entities themselves?

modest maple
#

oofies is that entity framework for dot net?

feral aspen
#

Can you do this?

const channel = bot.channels.fetch(channel_id);
console.log(await channel);
#

.. or should await be before the fetch method?

pale vessel
#

you can

feral aspen
pale vessel
#

You need to return a string

#

Don't call console.log(), that'll log it to console and return undefined

feral aspen
#

Last question, can you have await before the fetch method with a .then()?

pale vessel
#

yes

#

you can put it before any promises

feral aspen
#

Although, according to Tim, they both do the same thing but cannot be together?

pale vessel
#

they can

feral aspen
#

Ah.

pale vessel
#

you always need to use await if you want to use the return value outside .then()

feral aspen
#

How can I prevent it from logging undefined?

pale vessel
#

It won't log a channel

#

You need to return the channel inside .then()

#

It returned undefined since you never returned anything inside .then()

feral aspen
#

Oh, I get it now.

zenith light
#

Which database would be perfect to make an economy bot, I'm using firebase for now and getting error when creating relations

slender wagon
#

how can i make it so when the image isn't defined it wont put the picture on the embed at all

#
.setImage(image || interaction.guild.iconURL())
earnest phoenix
#
let embed  = new MessageEmbed();
embed.setTitle("title");
if(image) embed.setImage(image);
zenith light
#

Means?!

earnest phoenix
earnest phoenix
slender wagon
#

balls

#

i fixed it

earnest phoenix
#

fixed em balls

earnest phoenix
#

Actually try connecting to your database before anything else

#

Iirc this issue arises when you try using the entities before they are actually created

surreal merlin
#

is there an official twitter api for java? ๐Ÿค”

earnest phoenix
#

there is a twitter api for every language

#

by java you mean a wrapper

old cliff
#

I am setting up lavalink on my vps...
To keep the lavalink process running even if I close the ssh session do I need to use something like docker?

#

is there any other way?

earnest phoenix
#

you can use screens

earnest phoenix
#

Its what I used to do

quartz kindle
#

or a process manager like pm2

earnest phoenix
#

Yea

#

pm2 would also work

#

tim are you always lurking in development

old cliff
earnest phoenix
#

yea, you can make a sh file that executes your java thing and then execute that sh file with pm2 (not sure if there is another way but this is the one i've seen done the most)

quartz kindle
#

pm2 should support anything that runs in the terminal

quartz kindle
pulsar bone
#

Can turning bot on and off multiple times at once get the bot remo banned

#

?

#

Its keep on happening to me a lot

#

Like I am using replit and testing the code after updating and I keep on getting temp banned

#

I am using python

feral aspen
#
TypeError: Cannot read properties of null (reading 'name')
    at P:\Github Repos\discord-bot\TicketEvents\Status-Check.js:26:35
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Query.<anonymous> (P:\Github Repos\discord-bot\TicketEvents\Status-Check.js:24:29)

What does this error, mean?

pulsar bone
#

Can it be because of list element @covert gale

feral aspen
#

In addition, skip indexes (if there is the continue thing on python).

pulsar bone
modest maple
#

checks out

feral aspen
feral aspen
#

Although, I am not sure if this is something you find on Python.

pulsar bone
pulsar bone
last tapir
pulsar bone
feral aspen
#

Ratelimit, most likely.

dry imp
#

rip

pulsar bone
#

What should I do

feral aspen
#

You tell ME, what is some code that is like .fetch() getting looped to cause a ratelimit.

#

.. or as he said; better. (._.)

pulsar bone
#
@client.event

    if message.author.id == 571027211407196161:
        if message.embeds:
            if "User Status" in message.embeds[0].fields[0].name:
                user_anigam = message.embeds[0].footer.text.split("ID: ")
                user_anigame= str(user_anigam[1])
                
                if str(user_anigame) in db.keys():
                    del db[str(user_anigame)]

                else:
                    db[str(user_anigame)] = [
                        message.embeds[0].fields[2].value,#level
                        message.embeds[0].fields[3].value,#exp
                        message.embeds[0].fields[4].value,#gold
                        message.embeds[0].fields[5].value,#diamond
                        message.embeds[0].fields[6].value,#Clan Rubies
                        message.embeds[0].fields[8].value,#stamina
                        message.embeds[0].fields[9].value,#location
                        message.embeds[0].fields[11].value,#team selected
                        message.embeds[0].fields[13].value#cardselected
                    ]
                    print("Data stored:- \n User:"+ str(user_anigame) + "<>\n channel:" + str(message.channel.name)+ "\n type: Anigame")
    if message.content.startswith("$self level"):
      if str(message.author.id) in db.keys():
        user = str(message.author.id)
        info = discord.Embed(title="Profier",
                           url="",
                           description="Following is your Stats respected " +  message.author.name + " ji")
        info.add_field(name="Anigame",
                    value="level =>" + str(db[user][0]),
                    inline=False)
      
        await asyncio.sleep(0.5)                  
        await message.channel.send(embed=info)
      else:
        await message.channel.send("user not found")            
keep_alive()
client.run(os.getenv('TOKEN'))
dry imp
#

ooo replit database

feral aspen
#

Ooo.. I don't understand python at ALL. ;-;

dry imp
#

famous for getting your data corrupted

pulsar bone
#

The code is above tell me , help me, release me from my suffering

#

That's the entire code

dry imp
#

bruh

pulsar bone
#

Beside import and stuff

dry imp
#

@pulsar bone what do you have on your on_ready func?

#

if you have on_ready func

spark flint
#

You did @client.event

#

But not async def <event>

#

async def on_message(message)

pulsar bone
pulsar bone
pulsar bone
spark flint
#

No

#

Youโ€™re already done it good

pulsar bone
#

Where is the problem that causing temp bannes I an gonna strick the wall with my head if this keep on

#

turkvarmi (why this emoji is here its offensive to humanity )

dry imp
#

do kill 1 in terminal

pulsar bone
dry imp
#

basically refresh your container

#

replit uses shared ips so thats why people get rate-limited easily

pulsar bone
quartz kindle
dry imp
pulsar bone
quartz kindle
#

when you say you got temp banned, what is the actual error that comes up?

pulsar bone
pulsar bone
#

That's what it said

#

Sorry I don't have the screenshot I will try to find the same error on net

dry imp
#

discord.errors.HTTPException: 429 Too Many Requests (error code: 0): You are being blocked from accessing our API temporarily due to exceeding our rate limits frequently.
is that the error?

pulsar bone
#

Yes

dry imp
#

ok its fine then

pulsar bone
#
  • kill 1 giving syntax error in console
dry imp
#

uhh

#

dont do it in console

quartz kindle
dry imp
#

do it in shell

quartz kindle
dry imp
#

there is a async def ....

dry imp
#

anyway did it work @pulsar bone ?

pulsar bone
dry imp
#

wdym it work but not sure?

pulsar bone
dry imp
#

they might, that is the problem with replit

#

if you don't want to get rate-limited easily you should use another machine

#

or hosting services

pulsar bone
dry imp
lucid trench
#

i sent all files except the /ticket that is an embed with a button to create the ticket

pulsar bone
modest maple
#

no

dry imp
round cove
#
await createConnection({
      name: 'default',
      database: 'rolebot-beta',
      type: 'postgres',
      url: 'postgres://panku:panku@192.168.50.36:5432/rolebot-beta',
      entities: [ReactMessage, ReactRole, Category, GuildConfig],
    })
      .then(() => {
        this.log.debug(`Successfully connected to postgres DB.`);
      })
      .catch((e) => {
        this.log.critical(`Failed to connect to postgres.`);
        this.log.critical(`${e}`);
      });```
@earnest phoenix gm
round cove
#

yes

feral aspen
#

Did he leak his IP or something? ๐Ÿ˜‚ (or am i stupid)

round cove
#

Yeah if you can connect to my local IP ;p

feral aspen
#

Successfully connected

pulsar bone
earnest phoenix
round cove
#

I tried it without name/database btw.

earnest phoenix
#

Just make sure that you are connecting before anything that uses the entities

#

e.g before logging into the client

round cove
#

It is.

earnest phoenix
#

that is my rule of thumb

#

I've never had to supply the name or database prop

#

Hm well you are correct it is a repository issue but BaseEntity iirc basically just creates the repository thing anyway.

round cove
#

Hmm.

#

I guess I'll show a piece of each.

earnest phoenix
#

Does ur current configuration work or?

round cove
#

I mean it says it connects, and if I change the local ip to something fake it fails to connect.

#

So I assume so.

earnest phoenix
#

Try mutating data

#

or querying for something

round cove
#

Querying/mutating fails.

#

That's when it throws the connection default was not found

earnest phoenix
#

I assume startShards gets called after client login?

round cove
#

Before-ish?

earnest phoenix
#

Which means it will try and use the entities before htey actually get created

dry imp
round cove
#

Nothing calls any of the DB methods at the start.

earnest phoenix
#

I have ran into this issue before as well

#

and nothing called the db at the start either

round cove
#

Hmm

earnest phoenix
#

Just try starting the connection directly before client login it might help

round cove
#

This should be absolutely separate from the discord bot logging in. Would not make sense for them to be tied.

earnest phoenix
#

Well wherever you are querying for info relies on the bot to be logged in no?

#

It runs when the bot runs

round cove
#

Data only gets queried if specific commands are ran so like.

earnest phoenix
#

Shrug you dont have to listen to what im saying but I am just saying from my past experience that was the issue

round cove
#

I'm trying to say that it already is connecting before the bot logins.

earnest phoenix
#

I thought so as well

#

turns out it wasn't

round cove
earnest phoenix
#

Well I don't know the solution then. Only time I ran into this issue was at the very beginning of using typeorm and the solution was to connect before everything else

round cove
#

Hmmmm

earnest phoenix
#

essentially I just made the connection at the very top of my main file

round cove
#

Right, which I had originally in my index file and same issue so I thought it'd be cleaner to put at the start of the shardHandler.

earnest phoenix
#

If you have a repo I can take a look at it real quick

round cove
#

Let me push up.

#

27 changes

earnest phoenix
#

Ight mmLol

pulsar bone
#

@dry imp how you got that custom link for your bot

dry imp
round cove
modest maple
round cove
#

stay mad

#

fuck typo'd

modest maple
#

gj

round cove
#

Are you handling all your slash commands in some server thing? Lol

#

With the endpoint?

modest maple
round cove
#

I'd like to but like I use the client for basic stuff so like what's the point

#

For example I use the client for all the emojis the bot has Xd

modest maple
#

oofies

round cove
#

Yeah ๐Ÿ˜ฆ

#

I wonder if I somehow can though..

earnest phoenix
#

ngl dylan your code is so confusing

round cove
#

๐Ÿ™‚

#

please what part viviooaahh

#

Does it need even more comments

earnest phoenix
#

you have 2 different ways to start the bot it seems

#

but only use 1

round cove
#

There's only one way

earnest phoenix
#

then whats up with the bot-start file

#

๐Ÿ‘€

round cove
#

the creates the bot instance and actually calls the start function

#

the sharding manager needs a file with the bot starting?

#

At least that's what the docs showed.

earnest phoenix
#

but you only call index.js file

#

which starts the shard handler by the looks of it

round cove
#

Well, yeah? The shard handler calls bot-start for me

earnest phoenix
#

Oh

round cove
earnest phoenix
#

Im not even going to tyr and understand this code rn I only got 20m left

round cove
earnest phoenix
#

gotcha

#

I forgot about that bs

round cove
#

Which are you using?

earnest phoenix
#

I use detritus sometimes

#

which has an auto sharder

round cove
#

Oh right we talked about this.

earnest phoenix
#

it spawns shards when it needs em iirc

#

or some shit like that

#

I don't get how it works myself I just use it mmLol

round cove
#

the starting process is kinda fucky now that I added the shard thing but I think if I move the handler to the service folder it'd be fine

#

And maybe rename bot-start

earnest phoenix
#

also using - in a database name is annoying ๐Ÿ˜ฉ

round cove
#

I just did that on a whim when I was told i needed to shard

earnest phoenix
#

psql doesn't like the use of colons

round cove
#

Is it?

#

Hmm

earnest phoenix
#

I tried doing
CREATE DATABASE rolebot-beta; in psql

#

and it was like Nah fam

round cove
earnest phoenix
#

kekw

#

it is just annoying for me since I use psql

round cove
#

That is psql

earnest phoenix
#

How did you create your db?

round cove
#

I did sudo -u postgres createdb rolebot-beta

earnest phoenix
#

oh

#

that is why

round cove
#

๐Ÿง

earnest phoenix
#

I used the psql cli directly

#

and made my own sql query

round cove
#

Lemmie create a non hyphenated one.

earnest phoenix
#

I did myself mmLol

round cove
#

Obviously for my server >:((

earnest phoenix
#

Lawl

#

So dylan

#

It doesn't even create the entities

#

omg dylan

round cove
#

?

earnest phoenix
#

One sec im confirming if this is true

round cove
#

crying

earnest phoenix
#

I might of found ur issue

#

and if so it was a 1 line solution

round cove
#

ggs (guilty gear strive)

earnest phoenix
#

Well it creates the entities now

#

How do I test if it works?

#

What were you doing to get that defaultt connection error

round cove
#

just react to a message

earnest phoenix
#

any message I send?

round cove
#

yeah

#

or previous emssage

#

doesn't matter

earnest phoenix
#

Ok so didn't fix it

round cove
#

poggers

earnest phoenix
#

But hey now the entities actually get created mmLol

round cove
#

Hmm

#

I don't think I saw your example creating them so I don't see why I would've needed to?

earnest phoenix
#

for a dev environement you set syncronize to true so it actually creates the entities

#

I think I told you that last night

#

So the only thing i can think of is that the connection isnt "established" yet so it is trying to find a default one? (maybe I can't exactly tell)

#

Though I don't see why this is being like this ๐Ÿค”

round cove
#

Hmmmmmmmmmmmmmmmmmmmm ๐Ÿง

earnest phoenix
#

I can't help any further right now as I have school here in a few

round cove
#

Lmao don't worry. Any and all help was appreciated. ๐Ÿ™‚

#

What did you add exactly to create the entity again?

earnest phoenix
#

synchronize: true

round cove
#

Man I don't see how that would create them by adding that one option. So weird.

earnest phoenix
#

it synchronizes the database

#

But always and I mean always set it to false when in a production environment

#

Never have it as true on the public bot

round cove
#

Why exactly?

earnest phoenix
#

Unless you want it to have a chance of wiping your tables when you do something to the tables

round cove
#

Lmfao

earnest phoenix
#

Every time the bot restarts it will resync the database

#

setting it to false in a production environment will just create the tables and nothing more.

#

You will have to use migrations from then on if you wanna edit the tables

round cove
#

Ah I see.

earnest phoenix
#

Sorry I couldn't find the solution to the issue with the default connection

#

I was pretty limited on time mmLol

round cove
#

Lmao no worries, I'll throw random crap at it praying it works.

earnest phoenix
#

Ima try something stupid real quick

#

So uh

earnest phoenix
round cove
#

Oh?

earnest phoenix
#

I no longer get that default connection error

round cove
#

OH??

earnest phoenix
#

I moved connecting to the db into the bot-start file and moved it above creating the RoleBot instance

#

and it seems to work

round cove
#

So it's running it more than once then?

#

Since that file gets called N times with the shard number

earnest phoenix
#

Oh shit really?

#

yikes

round cove
#

Yes lol

earnest phoenix
#

Well from what I can tell is

#

The solution is to somehow call it before instancing RoleBot

round cove
#

Well it's doing that in the index.ts file in the start function

earnest phoenix
#

It seems like it is

round cove
#

It connects before the shardhandler even starts.

earnest phoenix
#

But it s actually not

#

Just because it logs that way doesn't necessarily mean it is

feral aspen
#
const channel = await bot.channels.fetch("758978182807420938");
console.log(channel.name);

TypeError: Cannot read properties of null (reading 'name')
I'm genuienly lost, wtf.

earnest phoenix
#

It could still be trying to connect even after

feral aspen
#

It's correct. ;-; (can't believe I spent 4 hours with 7 breaks in between and yet can't find an answer)

round cove
#

Where is bot coming from?

earnest phoenix
#

But it does appear connecting directly before creating an instance of RB works

round cove
#

Let me try.

earnest phoenix
#

Well I gtg for a while cya bois

round cove
#

holy siht

#

I don't understand it though

#

?????????

earnest phoenix
#

Did what I say work?

round cove
#

yeah but

#

what about sharding

#

???

earnest phoenix
#

Why does it matter?

#

Once connected you can use the db across shards anyway

#

lmao

round cove
#

I know but does it not freak out if called 50 times

#

tf

earnest phoenix
#

Is it creating a connection 50 times?

#

If so that is bad

round cove
#

Well

#

Again N times

#

N being the number of shards

#

because the shard manager from d.js calls that file

earnest phoenix
#

Does it call it every new shard?

round cove
#

Yes.

earnest phoenix
#

๐Ÿค”

round cove
#

Hmm

#

inb4 it just works because it's running as js OMEGALUL

earnest phoenix
#

well i gtg before im late

#

eek

round cove
#

glhf <3<#<3

#

What if because of how the shard manager calls the file, is it a threading issue?

earnest phoenix
#

Mmmm not entirely sure

round cove
#

I think that might be it???

#

Because it works when anywhere where the bot client is made / at

drowsy flume
#

Hey, just wondering how I would check if someone has manage guild perms in a command

wicked pivot
#
console.log(args[2].join(' '))```
#
    at Object.module.exports.run (F:\fiverr\proguides\assets\cmd\gess\edit-gess.js:8:25)
    at module.exports (F:\fiverr\proguides\assets\events\discord\messageCreate.js:30:25)
    at Client.emit (node:events:394:28)
    at MessageCreateAction.handle (F:\fiverr\proguides\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
    at Object.module.exports [as MESSAGE_CREATE] ```
round cove
round cove
wicked pivot
round cove
wicked pivot
#

yes

round cove
#

Look up array splicing.

compact pier
#

or slice()

#

would be easier

earnest phoenix
#

help mee it took over 20mins to start

#

with this thing

#

hwo to fix it??

compact pier
#

try to log the event debug

earnest phoenix
#

ok

earnest phoenix
earnest phoenix
compact pier
#

the bot is working?

#

but the distube not working?

earnest phoenix
#

no

#

all waorking

#

working*

#

but it is taking a lot of time

#

to start

#

idk why

compact pier
#

well that is api issue

#

u need to wait

earnest phoenix
#

api hmm

compact pier
#

it happend to me a lot

#

just wait 30min - 1hour

earnest phoenix
#

is there any way to fix it?

compact pier
#

u mean anyway to fix discord

#

my answer is no

earnest phoenix
#

hehe

compact pier
#

i know

#

but your bot is interacting with discord

earnest phoenix
#

hmm

#

yeah

compact pier
#

but discord is not reponsding

#

u can't do anything

earnest phoenix
#

should i chnage the api?

compact pier
#

to what?

earnest phoenix
#

everything

compact pier
#

there is only 1 api tho

#

:))

earnest phoenix
#

yeah

compact pier
#

just wait

earnest phoenix
#

ok

compact pier
#

or use another network

#

or restart ur pc

#

it might work, idk

earnest phoenix
#

wait

#

wait

#

i got idea

#

lemme make it 24/7

#

lol

compact pier
#

yeah

earnest phoenix
#

uptime robot

compact pier
#

deloy it to cloud

earnest phoenix
#

hmm

#

yeah

#

right

compact pier
#

don't use that

earnest phoenix
#

ok

earnest phoenix
compact pier
#

no problem :))

earnest phoenix
compact pier
#

not something serious to spend money :))

azure lark
#

is there anyway of find out what connections someone has on their account with djs?

torn vigil
#

So what server perrmits need to be enabled for twitter bot, it works on mmy own channel but not for a friend?

compact pier
azure lark
torn vigil
#

never mind then

#

ignore me

compact pier
#

@azure lark i think not

azure lark
#

f

quartz kindle
#

meaning, oauth2

#

connections allows /users/@me/connections to return linked third-party accounts

azure lark
#

oh ok, so i couldnt make it just as a bot?

compact pier
#

but that is direct interaction with api right?

quartz kindle
#

its an oauth2 scope

#

you'd need to make a page where the user has to "login with discord"

#

to give you permission to access their connections

azure lark
#

๐Ÿฅฒ ok

compact pier
#

so u need a website for that

#

:))

azure lark
#

how do i send a ephemeral message as message.channel.send({ content: 'Pong!', ephemeral: true }) is not working

wheat mesa
#

You canโ€™t do that

#

You can only reply to interactions like that

earnest phoenix
round cove
#

I'm somewhat certain it's because of how shardManager runs it. Pretty sure it making it a separate process breaks the connection and explains why it works when put into the code that is handled by d.js shardManager

#

Tested with multiple shards and it works fine.

#

I found out how to do the foreignkey stuff too

earnest phoenix
#

Oh good

round cove
earnest phoenix
#

I told you I knew the issue :^)

round cove
#

:^)

sudden geyser
#

orms are scary

true summit
#

hey i trying to made a iframe for my bot page and y having this error

eternal osprey
#

hey why is this actually returning me a \r after each gameid? ```js
const readFileLines = gameids =>
fs.readFileSync("./gameids.txt")
.toString('UTF8')
.split('\n');

        let arr = readFileLines('gameids.txt');
        console.log(arr)```

The game id used to be 250252252 and afterwards i have an array that contains: 250252252 \r

quartz kindle
#

because the gameids.txt file was created in windows

#

windows uses \r\n as a line separator, where linux uses only \n

modest maple
#

dos2unix is your friend

sudden geyser
#

Or for sanity
/\r?\n/

idle coral
#

Heya its me again

#

I have an issue with my evaluate command.

#

"invalid syntax"

sudden geyser
#

why do you just cut it off halfway through

#

can't tell what the rest of that textwrap indent is or what local_variables is supposed to be used in

idle coral
#

mk

earnest phoenix
#

mention?

#

can I make math.random() pick the numbers I want?

#

like I want from 27 to 30

#

but If I use ```js
let trophiesWin = Math.floor(Math.random() * 27) + 3;

spark flint
#

apparently Math.random() * (max - min) + min; works

#

according to stack overflow

earnest phoenix
#

oh

#

max will be 30 or 27?

sudden geyser
earnest phoenix
#

then I just swap it?

sudden geyser
#

You probably want to flip those two.

earnest phoenix
#

ok

wheat mesa
#

I'd probably just create a function like this

function randomRange(min: number, max: number) {
  return Math.random() * (max - min) + min
}
``` if that stackoverflow thing is right
sudden geyser
#

It looks correct

round cove
#

wrong

#

Math.random() * (max - min + 1) + min

#

there you go

#

:^)

sudden geyser
#

only difference is it doesn't chop off decimals

wheat mesa
#

if you want whole numbers you can just round

#

or truncate

round cove
#

You would floor.

wheat mesa
#

yeah floor

round cove
#
function rand(min: number, max: number) {
  return Math.ceil(Math.random() * (max - min)) + min
}```
#

There

#

If we use ceil we don't have to do +1 to get the range.

wheat mesa
#

do you even need to do the +1? seems to work just fine for me when I was testing

round cove
#

+1 if you do floor

#
Math.floor(Math.random() * (5 - 3)) + 3
= (max random is 1) + 3 = 4 (But we set 5 as our max???)```
wheat mesa
#

I seem to be misunderstanding

round cove
#

Math.random() times 5 for example.

#

without floor or ceil

#

Can go to 5., but good luck

wheat mesa
#
Math.floor(Math.random() * (5 - 3)) + 3
= (max random is 1) * (5 - 3) = 2, then 2 + 3 = 5
round cove
#

So we don't care about decimals

#

You see

#

Math.random() * 2 will never give 2

wheat mesa
#

idk I'm bad at random stuff

round cove
#

and if we .floor it

#

It'll always be either 1 or 0

sudden geyser
#

the floor/ceil/plus 1 really only matters if you care about (in/ex)clusion

round cove
#

Yeah

sudden geyser
#

I've found it best to just do:

function random(min, max) {
  return Math.random() * (max - min) + min;
}
#

random(5, 10): It won't reach 10 but will still reach 5

#

a simple function too

#

with overloading it'd be even cooler

round cove
#

But it has decimals

sudden geyser
#

that's a good thing

#

if you want decimals use them

#

if you don't just chop them off

#

and if you really distaste them:

function randomInt(min, max) {
  return Math.floor(random(min, max));
}
round cove
#

I don't think decimals make good for most random cases since I don't know why you'd want those decimal places anywhere. Hence the floor and ceiling and wanting to be correct with your min and max

sudden geyser
#

people have their use cases

#

if it turns out you need the decimals, will you be able to use the random with the floor/ceiling?

#

nope

earnest phoenix
#

how can I get the iconUrl for a specific card?

#
GETTING JSON
   let info = await 
    node_fetch(`https://api.clashroyale.com/v1/cards`, {
        method: 'GET',
        headers: {
            'Authorization': `Bearer ${process.env.API_KEY}`, /* La api key la pueden conseguir aqui -> https://developer.clashofclans.com/#/ Crean su cuenta y listo */
            'Accept': 'application/json'
        }
    });
#

JSON ```json
{
"items": [
{
"name": "Knight",
"id": 26000000,
"maxLevel": 14,
"iconUrls": {
"medium": "https://api-assets.clashroyale.com/cards/300/jAj1Q5rclXxU9kVImGqSJxa4wEMfEhvwNQ_4jiGUuqg.png"
}
},
{
"name": "Archers",
"id": 26000001,
"maxLevel": 14,
"iconUrls": {
"medium": "https://api-assets.clashroyale.com/cards/300/W4Hmp8MTSdXANN8KdblbtHwtsbt0o749BbxNqmJYfA8.png"
}
},
{
"name": "Goblins",
"id": 26000002,
"maxLevel": 14,
"iconUrls": {
"medium": "https://api-assets.clashroyale.com/cards/300/X_DQUye_OaS3QN6VC9CPw05Fit7wvSm3XegXIXKP--0.png"
}
},
{
"name": "Giant",
"id": 26000003,
"maxLevel": 12,
"iconUrls": {
"medium": "https://api-assets.clashroyale.com/cards/300/Axr4ox5_b7edmLsoHxBX3vmgijAIibuF6RImTbqLlXE.png"
}
}

sudden geyser
#

depends

#

Your goal is to find some data in some data structures

#

arrays and maps

earnest phoenix
#

any example?

sudden geyser
#

If your specific card name was Goblins, you could use the .find method on arrays to check if the card.name === "Goblins"

#

If something was found, you'd have a map, which you can easily access the icon as .iconUrls.medium

#

A more robust example would look like:

info.items.find(...).iconUrls.medium;
earnest phoenix
#

oh

#

thx

#

I've used that but without find

earnest phoenix
#
(node:1523) UnhandledPromiseRejectionWarning: TypeError: Giant is not a function
#

Giant exists

quartz kindle
#

if Giant doesnt work, try a Dwarf, or an Elf

boreal iron
earnest phoenix
#

@round cove Helping out a lot more here eh?

#

Seems since ur no longer mod u started talking here more

round cove
#

Ironic.

#

Honestly.

earnest phoenix
#

kekw

round cove
#

Yeah.

#

Well this week has been slower at work and I have 2 days off this week so been trying to get this bot working how I want.

earnest phoenix
#

Ah yea, thats sweet

#

I tried calling Social Security to setup an appointment to get my new social security card but them bitches be busy from open to close so I never got through ๐Ÿ˜ฉ

round cove
#

Oh jeez did you lose your SSN? (card)

sage bobcat
#

One message removed from a suspended account.

round cove
#

Hi

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

earnest phoenix
#

My dad holds onto that stuff and his wallet got stolen so ye

round cove
#

I purged most people I don't talk to often.

earnest phoenix
#

Not yet 18, got a bit to go

earnest phoenix
#

๐Ÿ˜ฉ

round cove
#

That's not fun at all.

earnest phoenix
#

Yea, it sucks

#

Prevented me from getting a job I basically had in the bag

#

I just needed to give em my social security card (a copy of it) and I would of had it :c

round cove
#

:/

#

Not fun

earnest phoenix
#

Yea

boreal iron
#

Social security card?! WTF

#

Are you a listed terrorist?

earnest phoenix
#

No?

round cove
#

Wtf?

earnest phoenix
#

Not sure if its just because im under the age of 18, but you have to give them a social security card to go on some type of form they have to make as part of you being an employee of their company

round cove
#

Nah you have to do that over 18 too.

earnest phoenix
#

Yea

quartz kindle
#

i never had anything similar to a social security @_@

earnest phoenix
#

Figured

round cove
#

Poor tim

quartz kindle
#

what does social security even do?

round cove
#

SSN is your unique identifier.

quartz kindle
#

the only things i have is passport, id, tax id, and driver license

round cove
#

It's how the government tracks you.

#

It's essentially your tax id

quartz kindle
#

oh?

round cove
#

Yeah they're basically the same.

quartz kindle
#

but i dont think this tax id is used for anything related to security/health

round cove
#

Nah but it uniquely identifies you.

#

Now places that USE the SSN as a way to identify you are bad because they're using it as a unique identifier.

earnest phoenix
#
TypeError: Cannot read property 'name' of undefined
    at /home/runner/Clash-Chest/commands/user/card.js:19:27
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
``` ```js
 url = cards.items.name.find(card.name).iconUrls.medium;
``` without name it says find undefined
boreal iron
round cove
#

cards.items is undefined.

quartz kindle
#

you were given a link explaining how to use it

#

you didnt check the link

sudden geyser
#

r/therewasanattempt

quartz kindle
boreal iron
#

My goshโ€ฆ snow again eww

quartz kindle
#

nice

#

i mean

round cove
#

Get off your phone ๐Ÿง

quartz kindle
#

not nice to drive in

earnest phoenix
#

Are you sure that is fucking snow

#

looks like ice

round cove
#

Could be

quartz kindle
#

cold be

round cove
#

:^)

earnest phoenix
#

shut up tim

#

bad pun

#

;c

quartz kindle
#

noice

earnest phoenix
boreal iron
#

Driving a RWD

#

So itโ€™s fucking much fun

quartz kindle
#

as long as you dont start sliding i guess

boreal iron
quartz kindle
#

do you have chained wheels?

boreal iron
#

I do that intentionally lol

round cove
#

Okay, but who asked. ๐Ÿง

boreal iron
#

I got some with me for complicated cases

quartz kindle
#

cool cool

boreal iron
quartz kindle
#

hi bored im dad

boreal iron
#

Sharing my day you know

#

lmao

#

Hi dad whereโ€™s mom?

quartz kindle
#

in the kitchen, where else?

#

:^)

boreal iron
round cove
quartz kindle
#

jk im the one in the kitchen

dry imp
earnest phoenix
#

When did this channel become family-development

quartz kindle
#

since fake started driving in the snow

#

it derailed the entire chat

#

:^)

earnest phoenix
#

Ah, they're still driving?

boreal iron
#

Yeah

#

As always at this time

quartz kindle
#

did you spend christmas and new years eve driving? i actually did lmao

boreal iron
earnest phoenix
#

lets ignore that

#

Sent it in the wrong channel

boreal iron
#

Just to help out others

quartz kindle
#

dayum

#

i drove quite a lot those two days but nothing compared to you

#

just about 6 hours a day

boreal iron
#

Currently no time to go on trying out autocomplete and other shit

#

Itโ€™s just frustrating

#

Not that this shit even has a priority but yeah

#

Damn I wanted to ask you something but completely forgot what it was oldEyes

earnest phoenix
#

Yeah cards.items is undefined

#

but cards exists

quartz kindle
#

show code

earnest phoenix
#
api.getCards()
    .then((cards) => {
        console.log(cards.items)
        url = cards.items.find(name => name === card.name).iconUrls.medium;
    })
    .catch((err) => {
        console.log(err)
    })
#

i've defined url above

quartz kindle
#

and what is the full error?

earnest phoenix
#
TypeError: Cannot read property 'find' of undefined
    at /home/runner/Clash-Chest/commands/user/card.js:19:27
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
quartz kindle
#

does "undefined" appear anywhere in your logs, right before the error?

boreal iron
#

Donโ€™t see card being defined anywhere

earnest phoenix
#

yep

earnest phoenix
#

cards.items is undefined

quartz kindle
#

if you have "undefined" in your logs right before the error, then cards.items is indeed undefined, try logging cards instead

earnest phoenix
#

when I log cards, it's totally fine

#

it returns the json

quartz kindle
#

but does it error too?

#

try it

#

and if it errors, show what is logged right before the error

earnest phoenix
#

logging? console.llog, right?

quartz kindle
#

yes

boreal iron
#

Is it just unparsed text ?

quartz kindle
#

just change console.log(cards.items) to console.log(cards)

boreal iron
#

Might just be text instead of a parsed JSON

quartz kindle
#

probably yes

earnest phoenix
#

oh wait ty

#

there is no items in the logs but in the docs there is

#

i'll remove .items and check

boreal iron
#

Check the docs if items is optional

earnest phoenix
#

umm what ```js
TypeError: Cannot read property 'iconUrls' of undefined
at /home/runner/Clash-Chest/commands/user/card.js:19:53
at processTicksAndRejections (internal/process/task_queues.js:97:5)

#

in the logs this time there is IconUrls

boreal iron
#

Show what you log shows

earnest phoenix
quartz kindle
#

just show what console.log(cards) shows

earnest phoenix
#

that's what the logs shows

quartz kindle
#

thats all of it?

boreal iron
#

Wut

earnest phoenix
#

no

quartz kindle
#

the full cards is just that?

#

then show all of it

earnest phoenix
#

all the cards or only 1 card?

quartz kindle
#

what console.log(cards) shows

boreal iron
#

5$ bet on itโ€™s just unparsed text

quartz kindle
#

10$ bet its just unrefined salt

earnest phoenix
quartz kindle
#

so thats what console.log(cards) shows?

earnest phoenix
#

yes

quartz kindle
#

if so, the correct code should be cards.find(...).iconUrls

earnest phoenix
#

and the medium?

quartz kindle
#

what medium?

#

ah

#

inside iconUrls

earnest phoenix
#

yes

quartz kindle
#

its just an object key

#

so just add .medium

earnest phoenix
#

but it's just the same thing from before

quartz kindle
#

what thing

earnest phoenix
#

same error

quartz kindle
#

show code and error

earnest phoenix
#
TypeError: Cannot read property 'iconUrls' of undefined
    at /home/runner/Clash-Chest/commands/user/card.js:19:53
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
quartz kindle
#

that means what ever you searched for in your .find() was not found

earnest phoenix
#

indeed now I deleted iconurls and logged it

quartz kindle
earnest phoenix
#
cards.find(name => name === card.name)
``` this is how it should be (?)
quartz kindle
#

no

#

you have an array of objects

#

meanind .find(item =>) the item here is an object

earnest phoenix
#

object.values?

quartz kindle
#

what you want is "find an item where the name inside the object equals to the name i want"

earnest phoenix
#

ok

#

all is ok I think but why the thumbnail ain't showing?

#

I did .setThumbnail(url)

#

logged url and it returns the card's url

boreal iron
#

Discord sometimes has trouble with fetching external image sources

earnest phoenix
#

but it never shows

boreal iron
#

Well the source webserver may blocks Discords user agent which tries to fetch the images or Discord doesnโ€™t show it for reasons we donโ€™t know

earnest phoenix
#

oh

boreal iron
#

Try to post an image URL in discord manually and see if an image pops up or just the URL

earnest phoenix
#

but many bots are using it

boreal iron
#

Yeah probably still a Discord related issue as I have that issue sometimes, too with new uncached images Discord doesnโ€™t show as icon or thumbnail

earnest phoenix
#

ok

#

oh

#

seems link is empty (?)

#

(node:2657) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message

#

give it something to send

#

I used message.channel.send(url)

#

what is url?

#

the card's url

#

Mmm

#

and when I logged it, it was fine

boreal iron
#

Just show the code again

#

Anything else is just guessing and speculating

earnest phoenix
#

yea

#
        let { chh } = require("../../object.js");

        let cards = chh;

        const card = cards[args.join(" ").toLowerCase()];
   let url;
  api.getCards()
    .then((cards) => {
        
        url = cards.find(item => item.name === card.name).iconUrls.medium;
    })
    .catch((err) => {
        console.log(err)
    })
#

and u are sure url is what you think it is

#

yeah but wait i'll re-log it

#

log it before sending

#

it gives this

#

https://api-assets.clashroyale.com/cards/300/Axr4ox5_b7edmLsoHxBX3vmgijAIibuF6RImTbqLlXE.png

boreal iron
earnest phoenix
#

but it finds

#

yea

boreal iron
#

Iโ€™m this case, maybe not in the one you had issues with before

earnest phoenix
#

?

#

I think i'll add all the 207 links manually...

wheat mesa
#

lmao

#

sounds like a massive pain in the ass for no reason

boreal iron
#

Just edit your find() inside the then clause

earnest phoenix
#

with what do I edit it?

#

I mean what do I edit there?

boreal iron
#

let find = โ€ฆfind(โ€ฆ === card.name);

if(!find) return โ€œcard wasnโ€™t foundโ€;
if(!find.iconURLs || !find.iconURLs.medium) return โ€œno icon URL foundโ€;

#

After both statements
url = find.iconURLs.medium;

#

You should always check if something exists and is not null/undefined before using it if you fetch something from external sources

earnest phoenix
#

ok

#

nope

boreal iron
#

Itโ€™s still required to check if url is not undefined after both your api call

earnest phoenix
#

ok

boreal iron
#

If you send that message only including that picture

#

Make sure url you defined exists

#

if(url) send message

#

Or if(!url) error message

earnest phoenix
#

finally

#

tysm

#

And one more thing, is there a way to whitelist all the ips? Because I want the api to whitelist all the ips (0.0.0.0 doesn't work)

boreal iron
#

You should keep in mind that Iโ€™ve got no clue what youโ€™re talking about.
You gotta explain things if you ask something.
Where do wanna whitelist what?

earnest phoenix
#

I want to whitelist all the ips that request http

#

because i'll be the only one doing it and I don't want to make separate apps for separate ips

boreal iron
#

All IPs that do requests on your API or..?

#

Still havenโ€™t got it yet

#

You do requests at an external API that requires your IP address to be whitelisted?
Or the case mentioned above?

earnest phoenix
#

it requires my ip adress to be whitelisted

#

I don't know replit's ip adress so I can't use the api unless I whitelist it

#

I want replit for test purposes

quartz kindle
#

what api is that?

earnest phoenix
#

aight i'm going to sleep

quartz kindle
#

it seems like they dont want you to use the same api key on different IPs

#

so for each app/ip you need a different api key

earnest phoenix
#

ok

boreal iron
#

lol canโ€™t even open the link

quartz kindle
#

he mispelled it

boreal iron
#

Blocked by my pihole

quartz kindle
#

its developer not developers

boreal iron
quartz kindle
#

anyway you can still use a proxy, that way you can use a single ip to all your apps

boreal iron
#

Guess the domain includes some sort of ads etc.

quartz kindle
#

there are even public proxies for clash api you can use

boreal iron
#

The token is bound to rate limitations and specified IP addresses, so you will need a web server to fetch data from the API and host your application.

quartz kindle
boreal iron
#

I mean you can define multiple IPs for a single API token

#

As long as you donโ€™t run into rate limits

#

This or simply doing a proxy pass for all of your apps to one endpoint redirecting the requests

#

โ€ฆ to the API

boreal iron
earnest phoenix
round cove
#

Say my bot allows emojis from others servers but I start sharding, and one guild is on a separate shard. There's no way I can react to a message with that emoji ID because it's unknown to the sharded instance, correct?

Edit: Apparently the solution is to do <:name:id> when reacting instead of just having the ID.

sudden geyser
#

Stuff

dry imp
#

anything

slender wagon
#

ayo guys can a option on slashcommands have 2 seperate options

zenith light
#
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\pc\Desktop\Discord Bot\node_modules\discord-api-types\package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\pc\Desktop\Discord Bot\src\commands\economy.js:2:33) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' ```
I tried converting all commonjs require to es6 import but the bot is still not working. What should I do??
slender wagon
#

how do i add a option with choices on a slashcommand

near stratus
slender wagon
#

yeah fixed the issue forgot to say

#

is there a way i could change the color of the buttons on discord.js?

near stratus
#

the last time I checked it wasn't possible (except green, red, grey)

earnest phoenix
#

Hi

#

How can i implement my webiste on the top.gg description?

#

Like a page

compact pier
#

you can use iframe

earnest phoenix
#

ty

surreal sage
#

Can you redirect after sendFile on express? and if yes, how?

compact pier
surreal sage
#

response is sent

#

after โ€ฆ redirect

#

not timeout

modest maple
#

you ever think maybe you might wanna rewrite that to be more readable so you have a easier time debugging?

surreal sage
#

im on ipad

#

am on vacation lul

compact pier
#

:v

modest maple
#

and?

surreal sage
#

and no

#

its readable

modest maple
#

EYESwell im sure you know whats wrong then bloblul

surreal sage
#

What?

#

โ€œcannot set headersโ€

pale vessel
#

I'm going to be frank, that code is completelyfcked

spark flint
#

yeah

modest maple
#

just in so many ways

surreal sage
#

Thatโ€™s not my issue

compact pier
#

why u login the bot... in a express app

surreal sage
#

Bot is ran on separate server

#

Why?
port 80 already being used there

modest maple
surreal sage
#

How

#

do

#

you

#

redirect

#

after

#

sendFile

#

.redirect func but cannot set headers

compact pier
#

yeah

#

u send the file

#

and then redirect

compact pier
#

redirect with headers

#

:)??

surreal sage
#

โ€ฆ

#

you dont get it

modest maple
#

you litterally cannot, do what you want to do with that code

#

your code, violates, even JS' forgiving rules

surreal sage
#

??

spark flint
#

html redirect maybe

surreal sage
#

write yeah

spark flint
#

what are you sending

#

a html file?

compact pier
surreal sage
#

yeh

compact pier
#

so chill

surreal sage
#

Yeah that can work

modest maple
#

This is not the way

spark flint
#

<meta http-equiv="refresh" content="timeinseconds; URL=https://www.google.com/" />

surreal sage
#

This is copied from github

#

yeh thanks

#

The oauthpart

#

And the bot

#

is ran on a separate server

spark flint
#

there are easier ways to do oauth

modest maple
#

what You login on EVERY request

spark flint
#

try passport-discord

surreal sage
#

nty

modest maple
#

and you try to return a webpage response IN AN EVENT in a diffrent wrapper

surreal sage
#

I know how to change but dk

compact pier
#

i smell a api violation

spark flint
#

well this code is fucked

compact pier
#

poor api

surreal sage
#

stfu

#

I can just double press home button

compact pier
#

you know what u can do to improve that?

spark flint
#

not use that code

#

find another repo to copy from cringe

compact pier
#

delete ur github project and ur folder

#

and remake it

spark flint
#

please

modest maple
spark flint
#

i will happily provide you with some base code for oauth for you to expand form and work with

modest maple
#

you're a) blocking the request calling login and b) returning a web response which d.js will just never pass back because its a asynchronous event, it doesnt care about your web server.

#

you could remove all of that block and just return the redirect directly, it would do the same thing to the bot, just instead it would actually redirect

#

because your code itself doesn't do anything on the bot's side, you update a cache that gets immediately destroyed (or well not destroyed, until the bot shuts down because you spawn one on each request until each session is logged out)

spark flint
#

how would i go about

#

converting 2022-01-06T09:56:51.000+00:00 into a nicer format

pale vessel
#

be more specific

novel jetty
#

What is this error supposed to be? Im confused

spark flint
#

like instead of 2022-01-06T09:56:51.000+00:00

6th Jan 2022 09:56 UTC

#

or just 6th Jan 2022

pale vessel
#

in what language

spark flint
#

nodejs

pale vessel
#

could just use the Date constructor

spark flint
#

ty

slender wagon
#
 .setDescription('Adds a item to the shop (Sellers Only)')
            .addStringOption((option) => option.setName('url')
                .setDescription('Insert the url of the nitro you are listing!')
                .setRequired(true),
            )
            .addStringOption((option) => option.setName('price')
                .setDescription('Insert the price of the item you are selling can go from 20 - 50 Cips!')
                .setRequired(true),
            ),

ok so i've updated this a few hours ago and it is still not updating on the bot, any explation

spark flint
#

@solemn latch so i found out you can use custom domains for backblaze

#

you must use cloudflare

#

and you point a cname at the friendly url, then set a transform rule and bam it works

jade anvil
#

What do I need to do to open the bot?

spark flint
#

What bot?

jade anvil
spark flint
#

@zinc fable -wrongserver moment

zinc fable
#

-wrongserver @jade anvil

gilded plankBOT
#

@jade anvil

Hey! We think you have our server mistaken. We do not provide support, help, or advice for any bot. You need to click on the "Discord" button on the bot's page of the bot you need support for, not the "Join Discord" button at the top of our website. If there isn't a button that says "Discord" or nothing else mentioned about a support server, the server invite is invalid or you were banned from the bot's support server, then we can't help you. Sorry :(

jade anvil
spark flint
#

you are in the wrong server

winged mica
#

I made v13 slash help command with select menu but I don't know how to reply or update the select menu I don't know what to write in maine can anyone help

frosty valve
#

Slash commands has IDs right?

#

Flaze. Yk how I can fetch those in discord.js?

#

Canโ€™t find anything easily on mobile in the docs

pale vessel
#

Aren't they cached

frosty valve
#

Iโ€™ll check later when I have a easier way to read docs

zenith light
# frosty valve Flaze. Yk how I can fetch those in discord.js?

My file containing the require statement is being treated as an ECMAScript module and not Commonjs. And I'm having trouble registering the slash commands. So I changed my package.json and added "type": "module" but still it's not working.

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');```
What will be the es6 import statements for that???
The following code isn't working idk why? Can somebody help? Please 
I have been asking the same question from days but no-one has replied yet. ๐Ÿ˜‘
#

HIGHLY CONFUSED

frosty valve
#

I canโ€™t help you

#

"type": "module" makes it ECMAscript btw

zenith light
frosty valve
#

And if files are named .jsm or .mjs, itโ€™s also esm

zenith light
#

Ik that too

frosty valve
#

Remove the type: module and check if the file extension is .jsm or .mjs, thatโ€™s all I can help you with

zenith light
#

But same error

frosty valve
#

Then why you told me that you added "type": "module"