#development

1 messages · Page 1945 of 1

spark flint
#

then double or smth for each rarity

sudden geyser
#

Would look something like this:

Array(...).fill("naga");

... is the number of times naga should be present in the array. You can determine that by the rarity @earnest phoenix

versed gulch
#

Follow up to Klay

if (chss.rarity == 'Common') chr = Array(19).fill('nada');
if (chss.rarity == 'Rare') chr = Array(30).fill('nada');
if (chss.rarity == 'Epic') chr = Array(46).fill('nada');
if (chss.rarity == 'Legendary' || chss.rarity == 'Champion') chr = Array(103).fill('nada');
chr.push('chr');
sudden geyser
#

An even simpler solution would be to assign each rarity a number then make one call to Array fill

winter pasture
#

So if it picks nada they don't get it, if it is chr they get it. There will never be any other it wants to pick from?
Would something like this work?

const isWin = (type) => {
  switch (type) {
    case 'COMMON':
      return Math.random() >= 0.5
    case 'RARE':
      return Math.random() >= 0.6
    case 'EPIC':
      return Math.random() >= 0.7
    case 'LEGENDARY':
      return Math.random() >= 0.8
    case 'CHAMPION':
      return Math.random() >= 0.9
    default:
      return false
  }
}

Would need the chances tweaked tho, in this example COMMON would have a 50% win rate.
Just something from the top of my head, could probably be done better.

earnest phoenix
#
let array = ["chr"]

//AFTER FILLING
["chr", "nada","nada","nada","nada","nada","nada","nada","nada","nada"]
``` so there will be more chance of getting "chr", right? Or the order isn't important?
#

or the fill works different?

sterile lantern
#

Is it possible to select 100 random users with a certain role in a discord server and put them in a txt file and send it? I feel like there's some sort of JS function for it but I can't find any thonk

wheat mesa
#

if you're selecting by random index, then order doesn't matter

sterile lantern
#

Maybe Math.Random an array

earnest phoenix
wheat mesa
#

Yes

#

You're selecting an index of the array randomly

#

So it doesn't matter where it is

earnest phoenix
#

ok

wheat mesa
#

I don't see why you wouldn't just select the character if Math.random() is lower than a certain number, and select nada if it's not though

#

Like ```js
if(Math.random() < 0.1) {
return "chr";
} else {
return "nada";
}

#

probably a lot less computationally expensive but idk

winter pasture
#

Sound extremely inefficient filling an array just to then randomly pick out a value
Try this: #development message

Pass in the rarity type, COMMON , RARE etc, and it will return true if a person won, false if they lost.

wheat mesa
#

^^

winter pasture
#

Well, chr or whatever that means

#

console.log(isWin("COMMON") ? "chr" : "nada")

earnest phoenix
#

they will be winning chr randomly

wheat mesa
#

if you wanted to be fancy and avoid errors you could use an enum 😉

earnest phoenix
#

they haven't already won it

wheat mesa
#

the point is that you don't have to fill an array and select a random index

#

it accomplishes the same thing

#

but with less work

winter pasture
sudden geyser
sterile lantern
#

I mean

#

I just want to do

#

message.guild.members.fetch() (which gets all the IDs)

and then just get 100 of them

#

theres abt 300 ppl in the server

sudden geyser
#

Do you still want to filter by their role ID and get a random sample of them, or something else.

#

Fetching is what you just wrote.

sterile lantern
#

So basically just fetch the members, make sure they have a certain role, then pick them

#

About 300 people have that role

#

let guildMembers = await message.guild.members.fetch()

How would I get just the user ID from here

earnest phoenix
#
const isWin = (type) => {
  switch (type) {
    case 'COMMON':
      return Math.random() >= 0.5
    case 'RARE':
      return Math.random() >= 0.6
    case 'EPIC':
      return Math.random() >= 0.7
    case 'LEGENDARY':
      return Math.random() >= 0.8
    case 'CHAMPION':
      return Math.random() >= 0.9
    default:
      return false
  }
}
``` finally I understood it
#

thx

sudden geyser
sterile lantern
#

Oh yeah, ty

winter pasture
earnest phoenix
#

ok

#

so 0.1 would be like hard to get?

sudden geyser
#

If you also want to filter by if they have a role, just use filter.

guildMembers.filter((member) => member.roles.has(...));

And you can compose that with map and sort like I showed above.

winter pasture
#

0.5% is 50% win rate. So 0.1 they would win 90% of the time

earnest phoenix
#

oh

sudden geyser
#

now you can't read it

earnest phoenix
#

but what is type?

#

ok

#

and one last question

sterile lantern
#

Like I write it all to a txt file

#

With only 100 IDs

earnest phoenix
#

how do i check if the card is common, rare, etc..? before i used "card.rarity === "Common"

#

okk

sudden geyser
sterile lantern
#

ohh ok ty

sudden geyser
sterile lantern
#

Hmm member.roles.has doesn't work

#

Neither does member.roles.cache.has

sudden geyser
#

That's weird. It should.

sterile lantern
#

For reference I'm still using Discord.js 12.5.3 bc im lazy ;-;

#

It's an old bot so I didn't bother to rewrite most of it

sudden geyser
#

It should still work in that version.

sterile lantern
sudden geyser
#

Can you verify what member is.

sterile lantern
#

guildMembers.filter((member)

sudden geyser
#

Can you show more of your code

sterile lantern
#
const g = guildMembers.filter((member) => member.roles.has("Verified"));```
sudden geyser
#

Ah now I see

#

You said that member.roles.cache.has doesn't work, but that should be the solution.

#

And .has takes a snowflake/role ID

#

Not the name of the role

sterile lantern
#

Oh ic

#

Hmm it doesn't seem to work

#

Just prints []

#

Let me check my intents one secc

#

Yeah my intents are on

#

Weird

#

g.map((member) => member.id);

#

Would this work

#

After I filter out the members w/ the role, then I get their ID?

#

Because rn it doesn't write anything to the txt file

#

ah wait nvm got it

sterile lantern
#

Okay so now i have a txt file of all the users like this

(1,2,3) etc

How can I make it so it adds a role for every user in the txt file

#

Im thinking of for x in the array something like that

pearl trail
#
for (let userId of <that txt>.split(",")) {
// get the member first from userId, then add the role
}
pearl trail
#

forEach do thing in the same time, but for loop, not. (if you use await)
example:
forEach
request 1, request 2, request 1 done, request 2 done
but for loop
request 1, request 1 done, request 2, request 2 done

#

CMIIW

#

also forEach will execute the code below it even the Promises is not yet resolved

wheat forum
#

Hey, just got a question in my mind, looked into the python library of topgg(for sending guild count and these stuff), and if I'm not wrong, the bot sends the guild count, it means the bot also can send fake guild count to topgg servers right?

pearl trail
lyric mountain
#

For smaller tasks it's fine, but for larger datasets or heavy processing you'll want to use normal for

royal pawn
#

So it's like int(time.time())?

#

So is it like this?

    e = discord.Embed(title="", description='{}'.format(int(time.time() + time)))
    await channel.send(embed=e)```
#

It's showing me this error

gentle condor
#

do some basic debugging

#

like printing

#

and you can also make a variable for it and then use it in the description

royal pawn
gentle condor
#

yes try

gentle condor
#

sorry for ping i just wanted to know

royal pawn
royal pawn
gentle condor
#

btw you can use other discord wrappers because discord.py is discontinued

royal pawn
#

Yeah but I am used to python

gentle condor
royal pawn
gentle condor
#

they'll probably shift like I'm doing

royal pawn
gentle condor
#

I'm using nextcord

#

they literally add every new feature

#

it's not been a week since discord added timeout feature and nextcord already added it

royal pawn
#

oh ok

gentle condor
royal pawn
gentle condor
#

yes

#

you'll have to do some changes though

#

everything which was discord you'll have to change them to nextcord

#

try it

#

its kinda fast too

royal pawn
#

ok

gentle condor
#

well but it's your choice

#

I'm not gonna force

royal pawn
gentle condor
#

yes

#

they have literally everything

#

buttons,dropdowns

#

but buttons in nextcord are really a lot different from discord_component buttons

royal pawn
#

They literally said this.

gentle condor
royal pawn
#

k thx

earnest phoenix
royal pawn
#

Can you give me full coding?

earnest phoenix
earnest phoenix
# royal pawn Can you give me full coding?

No, spoonfeeding is no good for ya. Besides, it's against the rule. The most I can do is give you directions. First off, take a look at https://docs.python.org/3/library/time.html#time.time. It returns the UNIX timestamp in seconds as you can see, so you can just add up the user input which also in seconds to get the "giveaway end timestamp." Then just cast it to int to remove the floating point and format it to a string so it becomes <t:THE_TIMESTAMP:R>

lyric mountain
#

Why tf does something returns unix as a float?

earnest phoenix
#

Precision You tell me

lyric mountain
#

Really, I can't see a single upside to that KEKW

#

Like, if u need more precision use millis

#

If u need even more use nano

#

But tf floating timestamp?

woeful pike
#

sounds like a js timestamp divided by 1000

lyric mountain
#

Someone forgot to floor the result probably

sudden geyser
#

Or maybe someone pushed the code as a joke

#

but realized they couldn't undo it later due to breaking changes

earnest phoenix
#

Now you made me thinking

lyric mountain
#

That code is very alien

#

Are those pointers I see there?

#

Ah nvm, sometimes I forget python is backed by c

earnest phoenix
#

Yeah, CPython is the ref impl

sudden geyser
#

The curly braces should've thrown you off.

lyric mountain
#

Yeah, my brain basically stopped the moment I read the code

#

C is alien enough, mix that with pointers and lodash and u get me hanging

#

define HAVE_CLOCK_GETTIME_RUNTIME __builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
bruh

#

Enough C for today

earnest phoenix
#

Lmao, you're still reading it?

woeful pike
#

that's enough C for the rest of my life

earnest phoenix
#

just write in D

sudden geyser
#

or torture yourself with C++

quiet cosmos
lyric mountain
#

Tf shameless survey

#

Also I feel the survey is a liiiiiiiiittle biased toward JS

slender thistle
lyric mountain
#

Idk if that's against the rules, it's just odd to ask like that

#

Plus all that data was already gathered by someone and probably available online, so a little search would yield results with a sample way bigger than he'd ever be able to get

gentle condor
#

hello i have an afk command and it stores the user's id and afk in db but as soon as it use it says welcome back

#

how do i prevent the bot from removing the data for sometime

#

after the command is used

lyric mountain
#

Store in db

gentle condor
lyric mountain
#

Then what's the issue exactly

#

Cuz data in db won't simply "vanish" after a while

#

UNLESS

slender thistle
#

inb4 cachedb

gentle condor
#

it actually take the command too as a message

#

and removes the data

slender thistle
#

Oh you

#

You want the afk message to retain after "un-afk" happens?

lyric mountain
#

That's exactly what you're supposed to store in the db

#

I don't get how it'd be deleting unless you're purposely doing so

gentle condor
#

idk

lyric mountain
#

...you're the dev, how don't u know?

gentle condor
#

as soon as I type -afk it gives me a message that I'm afk and another message that welcome back

lyric mountain
#

Show the code where u send welcome message

gentle condor
#

ok wait

earnest phoenix
#

Hey so Im having this issue with webhook decoding

gentle condor
#
  @commands.Cog.listener()
  async def on_message(self , message):

    keys = db.keys()

    id = f"{message.author.id}"


    if id in keys:

      del db[f"{message.author.id}"]

      await message.reply(f"Welcome back **{message.author.name}** ,I removed your afk")

    for member in message.mentions:
      if member != message.author:
        mid = f"{member.id}"
        if mid in keys:
          reasonf = db[f"{member.id}"]
          await message.reply(f"Mentioned user is afk right now | Reason : **{reasonf}**")
#

this code

lyric mountain
lyric mountain
earnest phoenix
# lyric mountain Decoding, yes

So I have a webhook sending json to discord, is there an easy way to decode it into human readable text or do I have to make a custom bot for that?

#

Also merry christmas ^^

gentle condor
lyric mountain
#

First, you don't decode a json cuz it's not encoded
Second, depends on what data we're talking about

#

Merry xmas

lyric mountain
#

Remove that line and it'll no longer delete

gentle condor
#

this is what i meant

earnest phoenix
#

Its pretty basic stuff

  "dispatchTimestamp": "2021-12-25T04:42:54.703Z",
  "value": "10"
}```

My original thought was to make an autoresponder but I would need the autoresponder to read one channel and respond in another channel.
lyric mountain
#

Usually you'd have a third column holding a boolean value for whether the user is afk or not

gentle condor
#

i do not want this to happen

lyric mountain
#

Remove del db

gentle condor
#

then how will it delete the data when a message is sent

lyric mountain
#

Then u can get the data and process however u want

lyric mountain
gentle condor
#

huh

lyric mountain
#

Don't delete, simply flip the switch off

gentle condor
#

ok

#

it doesn't work

#

still it replies as soon as I type the command

lyric mountain
lyric mountain
gentle condor
#

it's a key-value database

lyric mountain
#

And did u filter results to show only values with enabled afk?

#

For god's sake, tell me it's not a json database

gentle condor
#

nope

lyric mountain
#

Mongo?

gentle condor
#

replit database

lyric mountain
#

...I need specs sir

#

What kind of database is it?

gentle condor
#

just a simple database which stores key and the value not more than that

#

kinda fast

#

so I used it

lyric mountain
#

Pretty sure it'll fail fast later on due to increased amount of required data per key

#

But whatever, time will make u switch eventually

gentle condor
#

hm so should I be using mongo db

lyric mountain
#

Well, given the lack of info, try using a json structure as value

gentle condor
#

i know how to use it

lyric mountain
gentle condor
#

idk how to setup sql

#

i would've used it

lyric mountain
#

Nobody knows until learning

gentle condor
#

i tried googling

lyric mountain
#

Not that you need a degree in CS, but database stuff is not THAT straightforward for first timers

gentle condor
#

how much storage do i get on sql

#

and ram

lyric mountain
#

And while mongo feels easier, you can equally mess everything up if u don't know what you're doing

lyric mountain
#

Sqlite can run in a microchip without trouble

gentle condor
#

lol

#

another thing I need your help in

lyric mountain
#

Research about database types, don't simply go for sql because I said

#

Different needs, different databases

#

Baeldung covers a lot abt sql in general

#

W3schools too iirc

#

Idk where to find about mongo, but probably w3schools talk abt it too

gentle condor
#
async def get_prefix(client,message):

  try:
    with open("prefixes.json","r") as f:
      prefixes = json.load(f)

      return (*prefixes[str(message.guild.id)],"grabe ")
  except:
    return (*"-","grabe ")
  


intents = nextcord.Intents.default()  
intents.members = True 
client = commands.Bot(command_prefix = "-",intents = intents)
client.remove_command("help")

I have this code when i type return commands.when_mentioned_or(*prefixes[str(message.guild.id)],"grabe ") i get an error

lyric mountain
#

Is that a pointer?

#

What is *prefixes supposed to be?

gentle condor
#

more than one prefix

lyric mountain
#

And what error are u getting?

gentle condor
#

that it cannot take a function

lyric mountain
#

Why the star?

gentle condor
#

holdone lemme show you the error

#

lmao it worked

lyric mountain
#

?

gentle condor
#

not working

earnest phoenix
#

I dont think I can format my questions to the point where I'd be able to not sound like an idiot so Im gunna have to look into this another time.

#

Goodnight guys

lyric mountain
#

Are u using js?

gentle condor
#

Error command_prefix must be a plain string,iterable of strings or callable returning either of these not function

lyric mountain
#

Show where u define command_prefix

gentle condor
#

command_prefix is a way for adding a prefix to discord py bot

lyric mountain
#

But where u define it

gentle condor
#

i didn't define

lyric mountain
#

Hm

earnest phoenix
#

I feel like its kind of odd that there isnt a prebuilt bot that reads json and replies with a well formatted embed.

lyric mountain
earnest phoenix
#

Alright

lyric mountain
gentle condor
#

I'm new

#

sorry

lyric mountain
#

Print it

#

print(prefixes) IINM

gentle condor
#

print it's working

lyric mountain
#

Right after u load it

#

What did it show?

#

Hide the ids if u must

gentle condor
#

{"guild id":"+"
"guild id":"-"}

lyric mountain
#

That's not a valid json

#

Missing ,

gentle condor
#

huh

#

missing what

lyric mountain
#

,

earnest phoenix
#

Read from #webhook

  "dispatchTimestamp": "2021-12-25T04:42:54.703Z",
  "value": "10"
}

auto reply #generaI:
"Something occured"

gentle condor
#

i forgot to type

lyric mountain
#

Show exactly what it did print

#

Just hide the ids

earnest phoenix
#

I'm not a javascript guy, obviously. I dont know where to start for this.

gentle condor
#

ok

#

wa

#

{'oid': '-', 'oid': '+'}

#

this is

#

what

#

it print

lyric mountain
lyric mountain
#

Print prefixes[str(message.guild.id)]

gentle condor
#

yes i did this

lyric mountain
#

What did it show?

gentle condor
#

oid is just guild id

lyric mountain
#

Wait

#

Print prefixes returned what?

gentle condor
#

{'id': '-', 'id': '+'}

#

this

lyric mountain
gentle condor
#

wait I'm doing

gentle condor
lyric mountain
#

Probably

#

Iirc python doesn't require () for print tho

gentle condor
#

literally my

#

ide crashed

lyric mountain
#

?

#

How?

gentle condor
#

i have a low end pc

#

i Can't print it

lyric mountain
#

Printing it causes a crash?

gentle condor
#

too much Ram usage

gentle condor
#

says error

#

invalid syntax

lyric mountain
#

What error

#

Ok, where

#

Usually it tells the exact position of the error

gentle condor
#

in print prefixes[str(message.guild.id)]

lyric mountain
#

Put parentheses then

gentle condor
#

working

lyric mountain
#

What did it print

gentle condor
#

{'oid': '-', 'oid': '+'}

#

this

lyric mountain
#

You have an issue there then

gentle condor
#

wait

#

wrong

#

it print

lyric mountain
#

You didn't remove the old print

gentle condor
#

{'gid':'+'}

#

just removed the id

lyric mountain
#

Weird

#

Are u sure that's how u access a json file in python?

gentle condor
#

i tried it again

#

it print "+"

lyric mountain
#

Oh my

gentle condor
#

lmao

lyric mountain
#

Ok, what does * mean there?

#

Did u try without it?

gentle condor
#

wait lemme

#

not working

#

wait I'll comeback after sometime

lyric mountain
#

What error now?

#

Well I'll go sleep then, return in around 8hrs

gentle condor
#

gn

sly sierra
earnest phoenix
#

Hey @sly sierra would you be able to lend a hand?

#
  "dispatchTimestamp": "2021-12-25T04:42:54.703Z",
  "value": "10"
}

I have this webhook output from a website. All Im looking to do is make the output human readable

When a response comes in trying to make it say "Something Happened @ this time"

#

its not a json file, its a json response. I added the webhook to discord using integrations

#

I want to take the json responses from one channel and automatically reply to another channel with "something happened @ timestamp"

gentle condor
#

linux

earnest phoenix
# earnest phoenix its not a json file, its a json response. I added the webhook to discord using i...

The way you would do this really depends on the programming language you're using

  1. Listen to the responses containing JSON input
  2. Validate if it's a valid JSON and cast to JSON
  3. Take the timestamp from the JSON input and convert it into an actual date instance
  4. Use date/time functions to make the date instance into a human readable form

If you're using JavaScript:

  1. Get JSON input
  2. Validate and cast the JSON input by parsing using the JSON.parse() method
  3. Convert the timestamp into a date instance using the global Date constructor
  4. get the human readable form of the date instance using the <Date>.toTimeString() method

You can take the same approach in other programming languages based on the features they provide

slender thistle
slender thistle
#

You don't need the asterisk in that case

#

The command prefix could also be an iterable of strings indicating that multiple checks for the prefix should be used and the first one to match will be the invocation prefix.

earnest phoenix
#

I'm not entirely sure how to get started

earnest phoenix
#

If you tell me the Discord API library you're using for your bot, I can show an example of how you can achieve that in code

slender thistle
#

Mm?

eternal osprey
#

Hey guys, how do i add 4 shards to my bot in v12?

#
const bot = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"] });``` this is how i currently define the client
quartz kindle
#

how many guilds?

earnest phoenix
#

shardCount:4 ig for max 10k guilds

  • Tim knows better
eternal osprey
#

3k* sorry

#

but the commands are really intensive and the bot is overall performing really slow

#

so i wanted to shard it

quartz kindle
#

if you have 3k guilds you already have some kind of sharding

#

its not possible to have more than 2500 without sharding

#

do you use the ShardingManager?

earnest phoenix
#

I need it to give "chr" or otherwise "nothing"

#

like i'm using ```js
if(functioned === "chr") {
....
...
..
.
} else {
....
...
..
.
}

eternal osprey
quartz kindle
#

you need to create a new file

#

this file will start the sharding manager, then the manager will run your bot file once for each shard

analog tinsel
#

{"player":[{"id":"1","name":"11"},{"id":"2","name":"22"}] how i can get id by name? im trying to make command !search name and want to give result as id

earnest phoenix
#

for now it's working better than before with only a few lines of code

#

before there were like 20+ lines

earnest phoenix
#

help

#

3 cards in 3 chests

#

continuesly

#

it's too easy to get cards now

#

?

quartz kindle
tiny lily
#

why isnt it recommended to shard ur bot before 1k servers?

earnest phoenix
#

servers* and every shard you create means more mem usage and cpu usage

#

and its useless to shard when your bot isnt even in 1k server

spark flint
#

no need to use sharding before 1k servers

#

its a waste of resources too

tiny lily
#

i see, okay ty. i just needed to confirm this with my friend

#

ty for ur help

solemn latch
#

Generally speaking I reccomend waiting until 2k guilds, not 1k

earnest phoenix
#

that's what i was about to ask

solemn latch
#

Excluding cases the bot is growing extremely fast. Which is uncommon

spark flint
#

^

tiny lily
#

ight, ty

earnest phoenix
quartz kindle
#

discord recommends sharding at 1500

earnest phoenix
#

it's far away for me so I can rest until 1500 servers

eternal osprey
#

or didn't they change anything

quartz kindle
#

the basics should be the same

#

one of the things that changed is broadcastEval, but you only need to worry about if if you need to use it

earnest phoenix
#

I learned that 0.1 and 0.10 are the same thing

quartz kindle
#

yes 0.1 and 0.10 are the same thing

spare shoal
#

Hey, people that have both SFW and NSFW commands to your bots, how are you handling the transition to slash commands?
Is there a way to only display some commands in NSFW channels?

earnest phoenix
quartz kindle
#

idk what those numbers mean

#

what is the context?

earnest phoenix
#

oh

#

idk too but johand said that 0.5 is 50%

#

and 0.1 is 90%

#

so 0.9 is 10% maybe

quartz kindle
#

are you talking about Math.random()?

#

show the code

earnest phoenix
#
function isWin(type){
  const h={"Common":0.5,"Rare":0.6,"Epic":0.7,"Legendary":0.8,"Champion":0.9}
  return (h[type]<=Math.random())?"chr":"nada"
}
let chra = isWin(chss.rarity)
quartz kindle
#

Math.random() gives you a random number between 0 and 1

#

including decimals

#

meaning it can be 0.000000001 for example

#

or 0.04816487263874

#

you are checking if your number is smaller or equal to Math.random()

#

meaning if your number is 0.5, then you have pretty much a 50% chance that Math.random() gives you a number smaller than that

#

because it can only generate numbers between 0 and 1

#

and 0.5 is right in the middle

#

if you give it 0.1, that means you only have a 10% change of getting a number smaller than that

#

because 0.0 to 0.1 is only 0.1, while from 0.1 to 1 there is 0.9 possibilities

earnest phoenix
#

oh

quartz kindle
#

you can give it as many decimals you want

#

for example if your number is 0.001

#

what are the chances Math.random() gives you a number smaller than 0.001?

earnest phoenix
#

0.009?

quartz kindle
#

no?

#

from 0.001 to 1 there are 999 possible numbers

earnest phoenix
#

oh yeah

quartz kindle
#

so from 0 to 0.001 there are 0.001 possibilities

#

meaning 0.1%

#

one in one thousand

earnest phoenix
#

1 in 1000 of getting a card?

quartz kindle
#

yes

earnest phoenix
#

that's insane

#

ty for the explanation

quartz kindle
#

so yes, in your current code, 0.1 does equal 10%

#

so if you do 0.01 it becomes 1%

#

0.05 would be 5%

#

etc

earnest phoenix
#

ty

split hazel
#

I know a better random number generator

#

women

#

aha aha get it

#

because they're unpredictable at times

boreal iron
earnest phoenix
split hazel
karmic raft
#

dug me i check my bot?

spark flint
karmic raft
spark flint
#

yeah

#

what about it

#

your bot can get verified from 76 servers

earnest phoenix
#
db.set(`giantt_${author.id}`, true);
db.set(`archers_${author.id}`, true);
db.set(`minions_${author.id}`, true);
db.set(`arrows_${author.id}`, true);
``` Can I do the same thing in another and less lines code?
sudden geyser
#

Yes

earnest phoenix
#

I'm changing my whole code to a more smoother one

karmic raft
earnest phoenix
#

so I'm wondering if there is a way

sudden geyser
#

Put each string (giantt, archers, etc.) in an array and iterate over it doing the same operation

earnest phoenix
#

oh

#

ok

vivid fulcrum
#

or an even smarter approach

#

don't use 4 entries to save a bool

#

instead have something like flags_USERID and use bit flags

#

saves much more space and performance

boreal iron
#

The evil term "bit flags" again

earnest phoenix
spark flint
#

is me buying a server for colocation worth it

#

i have free colocation

crimson vapor
#

im going to have to agree with the bit flags approach

spark flint
#

ok so

#

const check = await database.find({ userid: userid, "data.primary":req.user.id })

#

that would work wouldn't it?

earnest phoenix
#

what database

spark flint
#

mongo

earnest phoenix
#

shouldn't it be findOne

spark flint
#

well yes and no

#

i'm doing this so it checks if the data exists

#

it then does js if (check > 0) { // does shit }

earnest phoenix
#

put an !! on there to make it a bool

spark flint
#

where

earnest phoenix
#

!!(await database.delete(/* ... */))

spark flint
#

i'm not deleting tho hmm

slender thistle
#

What does findOne return when no document was found?

#

null? {}?

earnest phoenix
#

null

slender thistle
#

Sweet. Just check for that with findOne and you're good, no?

#

If no data exists that matches your filter, then why bother with .find?

lyric mountain
slender thistle
#

Pointless

lyric mountain
#

Non null is already truey

slender thistle
#

It's just unnecessary converting

spark flint
#

I don’t mean that

#

I mean it’s not retuning anything even tho it exists

#

I think I did the selection but wrong

#

Bit*

slender thistle
#

Are you sure you're searching in the right collection?

spark flint
#

Yes

rose needle
#

yo! i have a discord bot hosted on heroku currently, and the way i test the bot is by scaling the dynos down to 0, and then i can test locally. this makes the bot go down, though. is there a way to keep the production bot up while testing a different version locally?

wheat mesa
#

You should create a new bot used for beta testing and push updates to your main bot when you’ve rolled out new features

#

And only host the beta bot locally, since it only needs to be up during testing

lyric mountain
#

production testing is the only real testing

spark flint
#

testing on live sites is always the answer

split hazel
#

saves time

boreal iron
earnest phoenix
#

Why the db restarts for some users? (it restarts for random users) like they got 100 cards and a few hours or days later they don't have anything (coins, cards, etc..)

finite bone
earnest phoenix
#

ok

lyric mountain
#

my first guess is: you're using heroku + file-based db

earnest phoenix
#

nope not heroku

#

but yeah file-based db

#

idk mongo

lyric mountain
#

then give more info

earnest phoenix
#

the db is quick.db

lyric mountain
#

quick.db is backed by sqlite

#

definitely not mongo

earnest phoenix
#

yeah

#

i meant to say "I don't know how to use mongo"

lyric mountain
#

...and why would I suggest mongo?

earnest phoenix
#

why?

lyric mountain
#

quick.db is shit indeed, but any db will suffice

#

all it changes is how quick the bottleneck will come

#

but that's not the point

#

where is the bot running?

earnest phoenix
#

replit

lyric mountain
#

you can't use file-based dbs on replit probably

earnest phoenix
#

so you recommend me passing to mongo?

lyric mountain
#

mongo is file-based

#

and why such obsession with mongo?

earnest phoenix
#

idk

#

there is no obsession

#

i just thought mongo wasn't file-based

#

Mongoose topgg_codebase

#

The db works fine though

lyric mountain
#

thing is

earnest phoenix
lyric mountain
#

file-based dbs arent persisted on replit

#

so you'll always return to the earlier state of it upon restart

earnest phoenix
#

You can use MongoDB atlas

earnest phoenix
lyric mountain
#

anything outside of replit will work

earnest phoenix
#

ok

#

but i have no idea about replit, better get a vps

lyric mountain
#

damn you could even use github as database holder

#

it'll yell at u due to constant pushes tho

#

but general rule is, you want to get a vps asap

#

it's not expensive, and will solve 99% of the issues you have

earnest phoenix
#

Atlas 512 MB free

lyric mountain
#

use atlas to store a serialized sqlite db KEKW

#

then unserialize on startup and use in-memo

raw nest
#

Am I allowed to use apple emojis on my website? And will they get also displayed right on windows/android devices? 🧐

lyric mountain
#

that's an unicode thing that you need to check each device's catalogue

#

nothin guarantees an emoji will be in all 3 devices

#

I mean, unless you compare the palettes

raw nest
#

Okay, but don't I get trouble if I use them? For any use like personal, commercial etc.

lyric mountain
#

don't think so, since they'll show different for each device

#

emojis are unicode, the device just fancify it

#

like \😄

#

this is how it shows for me (w11 version)

#

for u it could be different

raw nest
#

yes for me it looks like the apple smile emoji since I'm on a MacBook

#

alright^^ thanks 🤝

lyric mountain
#

yw

#

just note that if the emoji is not present for the viewer it'll appear as a square

raw nest
#

quick question, how does this site look to you? https://aliabdaal.com/ does it also show apple emojis or windows ones?

lyric mountain
raw nest
#

ohhh okay^^ thank you very much

#

good to know xD

sudden geyser
#

I get Apple emojis

raw nest
#

you're on an iPhone, iPad, MacBook etc. right?

sudden geyser
#

MacBook

round cove
#

@low orbit it's because it's getting your hour (24 hour format) on your computer.

#

It's 6:30pm for me so it returns 18, etc.

#

Cool. 🙂

#

getTime uses UTC

#

the date is transforming it to your time isn't it? (yes)

#

Passing the time to the date constructor will make it be in your timezone.

#

Right.

#

Um

pale vessel
#

Dylan has stopped working.

round cove
#

You can create a UTC date object by passing the year/month/day/hour/minute (lol) to Date.UTC() and then setMinutes on the date object.

#

I would just use a library like moment (which they've stopped developing) and do the like 1 line solution

pale vessel
#

You don't have to do that

#

Use new Date() + setUTCMinutes()

round cove
#

is that fr

#

I never use date lmfao

quartz kindle
#

timestamps are always in utc

#

just do timestamp + minutesInMs

round cove
#

I was trying to remember how to mutate the timestamp and gave up lmao

#

thanks tim

solemn latch
#

I really would suggest reading the djs guide from beginning to end before trying to move to v13

#

thats the guild you want non global commands to go to

#

for example if you want eval, you can have eval only show in one server.

#

I think its covered on that page

#

or the next one

#

(also you dont want global commands for testing, they can take an hour to update)

#

so I register all my commands once in a test server for development.

#

it can be

pale vessel
#

Slash commands along with components

solemn latch
#

fast

earnest phoenix
#
if (interaction.member.roles.cache.has('847248675389702204' || '896044829438533673')) {
#

Is || not a thing?

#

Cause it only reads the first role.

#

djs v13

sudden geyser
#

It's working as intended.

#

|| works by evaluating expressions from left to right

pale vessel
#

Not as you intended though.

sudden geyser
#

So it's evaluating the first string and the second string

#

But that's clearly not what you wanted.

earnest phoenix
#

o-o I wanted it to look if they have both roles

#

I also tried && but 🤷

#

or like one of the roles I mean*

sudden geyser
#

You should check the general .has twice

earnest phoenix
#

hm

sudden geyser
#

e.g. ```js
if (cache.has(...) || cache.has(...)) {
// ...
}

earnest phoenix
#

if (interaction.member.roles.cache.has('847248675389702204') interation.member.roles.cache.has'896044829438533673')) {

#

ah

#

with the ||

#

alr

sudden geyser
#

If you want to check if the member has both roles, you should use && instead of ||.

#

There are other methods of achieving this.

#

For example, instead of using .has(...), you could use .hasAll(...).

#

Which accepts an array of IDs.

#

Which would accomplish the && part.

neat ingot
#

do i need GUILD_PRESENCES to check for total members of a guild? wth?

sudden geyser
#

No.

#

Well, it depends.

#

Do you want all the members, or just the number of members in a guild?

#

You can get an approximate without guild presences.

earnest phoenix
#

do I need to enable any privileged for my bot to fetch audit logs?

sudden geyser
#

I don't believe so.

neat ingot
#

@sudden geyser yea, i was able to get just the total members without it, thats all i needed really 🙂

harsh tusk
#

why is it when i use npm init id ont work

#

wait

grand panther
#

hullo

harsh tusk
#

its says 'npm' is not recognized as an internal or external command,
operable program or batch file.

grand panther
#

so ```js
guildMember.timeout(0, reason)

should be work, right?
harsh tusk
#

i got node

grand panther
#

i couldn't get it exactly

harsh tusk
#

do i got to get npm/

solemn latch
#

did you restart the terminal after installing node?

harsh tusk
#

i opened it after i got the node

solemn latch
grand panther
#

yeah it didn't work actually

#

also tried NaN and null tho

solemn latch
#

NaN and null removes the timeout, are you trying to remove a timeout or set one?

grand panther
#

i want to remove timeout

solemn latch
#

does your bot have that permission?

grand panther
#

yes

solemn latch
harsh tusk
#

idk what to do anymore

#

ok

solemn latch
grand panther
#
Error: val is not a non-empty string or a valid number. val=null 
#

when i tried null i got this ^

harsh tusk
#

ok now let me try

#

npoe

round cove
#

Genuinely why do people shit on d.js caching system, real answers only.

harsh tusk
#

?

solemn latch
round cove
#

:^)

#

So do you claim v13 to be better?

solemn latch
#

100x better

round cove
#

Do you have any comparisons?

harsh tusk
#

i might just give up

solemn latch
#

tim would be able to explain it kek

solemn latch
harsh tusk
#

ok

#

no

solemn latch
#

you didnt install node

harsh tusk
#

i did i got the itl one

#

i think that whats the verson is called

solemn latch
#

then the install failed

#

try installing again I guess

solemn latch
harsh tusk
#

should i do current version

solemn latch
#

LTS

harsh tusk
#

ok

grand panther
#

i tried already

harsh tusk
#

yea i think failed last time, as it did go a little fast

#

ok got it

solemn latch
harsh tusk
#

o wait i see

#

ok imd dumb wait

#

should i have it auto install it needed versions

#

?

grand panther
solemn latch
#

I couldn't either

#

might be best to re-ask the question so someone who knows can help

spring arch
#

What permission should I use for mute command?

sudden geyser
#

depends

#

If you're using a role, how about checking if the user can manage that role?

#

And if they can apply it to the target?

spring arch
#

manage_roles?

sudden geyser
#

more specific

wheat mesa
#

I believe the recommended permission for most commands is the permission it would require for the user to do it manually

sudden geyser
#

If using timeouts, how about that new permission Discord added

spring arch
#

Hmm

wheat mesa
#

MODERATE_USERS I don’t think is right necessarily

#

MANAGE_ROLES or that is probably fine

spring arch
#

add_reactions
administrator
attach_files
ban_members
change_nickname
connect
create_instant_invite
deafen_members
embed_links
external_emojis
kick_members
manage_channels
manage_emojis
manage_guild
manage_messages
manage_nicknames
manage_permissions
manage_roles
manage_webhooks
mention_everyone
move_members
mute_members
priority_speaker
read_message_history
read_messages
request_to_speak
send_messages
send_tts_messages
speak
stream
use_external_emojis
use_slash_commands
use_voice_activation
value
view_audit_log
view_channel
view_guild_insights

solemn latch
#

Value is my favorite permission

spring arch
#

I found this in another bot have been declined

#

Should I follow this?

sudden geyser
spring arch
#

Original

sudden geyser
#

Then you should consider migrating to a fork like Nextcord or Pycord

spring arch
#

Hmm

sudden geyser
#

As they've probably added the permission

#

And added support for other stuff, like slash commands

spring arch
#

I will think about it cause it will change the full code

#

For this time I will use manage_roles but maybe I will change

grand panther
#

@solemn latch ahh my bad... i fixed it thank you for ur patience

harsh tusk
#

my bot is not comming online when i do node .

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'no';
const PREFIX ='';

bot.on("ready", () => {
    console.log('i am online!')

    
})
bot.login(token)
harsh tusk
#

?

quartz kindle
#

what happens when you do node .

#

what comes up?

harsh tusk
#

alot of stuff

quartz kindle
#

well, show that stuff

harsh tusk
#

am i supposed to past it here?

quartz kindle
#

yes

wheat mesa
#

Is there a way to play an audio buffer using lavacord?

quartz kindle
#

probably yes

wheat mesa
#

the problem being connection.play() expects a string as a parameter

#

so obviously I've gotta do it some other way

quartz kindle
#

you have to check the source code and see what .play() does internally

#

somewhere in there is a function that plays audio from a stream

#

so you can call that function directly instead

wheat mesa
#

agh

zenith knoll
#

for sql should i store discord ids as varchar or BIGINT?

#

i feel like a type of int is better cause a id is a number

#

but id have to use bigint cause the numbers too large?

wheat mesa
#

perhaps I should just not use lavacord since my only intention is to play mp3 files

quartz kindle
#

if the library uses string ids, then you're gonna have to convert them back and forth all the time

#

which honestly isnt that bad

wheat mesa
#

my brain is completely fried

#

I hate discord audio

#

My goal is to take an mp3 file as an attachment and play it in a vc which is proving to be much more difficult than I thought

wheat mesa
#

I wonder if there’s a way to save the buffer of the attachment into memory without having to download the file through a request. I’m probably missing something here but I’m going to go to bed instead of doing more of this

quartz kindle
#

i forgot lavalink is an audio server

#

meaning lavacord is just a client for lavalink, it does not actually play any audio

#

it only sends instructions for lavalink to do it

#

so you will need to either stream the audio buffer to lavalink somehow, or save it as a file and tell lavalink to play it

#

if you are on linux, you can write the audio files to /tmpfs

#

which is basically a ram disk, writing and reading on it should be as fast as ram

wheat mesa
#

Yeah I think I’m going to move away from lavalink and just use my own stuff for this

#

Since I’m not by any means intending to do anything other than stream audio from a given mp3 file

#

If I was getting audio from YouTube or something like that then I’d use lavalink but I think it’s better to just throw together some spaghetti code and improve it over time

lyric mountain
#

If you were using Java, there's lavaplayer

#

Which is made by the same lavalink guy, and basically a standalone (well, kinda) lib

harsh solstice
#

i need a help

lyric mountain
#

No, you need to ask it first

pale vessel
earnest phoenix
#

L

compact pier
#
Request.post(authOptions, async (error, response, body) => {
  if (!error && response.statusCode === 200) {
    this.token = body.access_token;
  }
});
if (this.token) return this.token;

Any one have clue how I can wait for the request?

#

because it just return undefined

pale vessel
#

if (this.token) return this.token; needs to be inside the callback

#

You need to make sure that the check is done after the token assignment

compact pier
#

but it still return undefined in the function

#

the the request in a function

#

like the function return undefined

pale vessel
#

That means that either it errored/the status code wasn't 200 or access_token isn't a property inside body

compact pier
#

hmm

#

when I console.log it

#

the body.access_token

#

it return normal

earnest phoenix
#

You can also use the reject method the promises provide to reject the promise if the token wasn't available

compact pier
earnest phoenix
#

You can return the promise as the value of the function and resolve the token with the resolve() method provided, then the token will be directly returned as the value of the function after you resolve it's promise

compact pier
#

ohh

#

ok thank you, I will try it

raw nest
#

Quick Question, I recently informed myself about NextJS and I'm wondering if I can use the same server for frontend and backend. Because like there's the /api folder etc. 🤔

neat ingot
#

how do i check if a bot has slash commands registered for a specific guild using discord.js? is that even possible?

surreal sage
#

I want a span with </ as content, how do I do that?

spark flint
#

literally "</"

#

as the visible content

surreal sage
#

works like a charm :/

spark flint
#

<span></</span>

raw nest
#

maybe with space? 🤔

surreal sage
#

Not what I want...

raw nest
#

<span> </ </span>

#

hm

surreal sage
#

Going to use < instead

feral aspen
#

Is there a way to get the date of when a document in a model, in MongoDB, was created?

#

Like the date of when this document was created?

spark flint
#

i don't think mongo has a way of tracking when a document was created

feral aspen
#

Unfortunately, I can't update 600 documents. :/

spark flint
#

AH

#

ok

#

ignore my shit copy paste KEKW

feral aspen
spark flint
#

its the _id

#

<object>._id

#

that would work

feral aspen
#

Ohh, makes sense.

feral aspen
spark flint
#

i'll have a look

#

lemme do some testing rq

#

console.log(data[0]._id.getTimestamp()) worked for me

#

in my instance, i did js const data = await accounts.find({username:username}).toArray(); console.log(data[0]._id.getTimestamp())

#

so <object>._id.getTimestamp()

feral aspen
#

Alright, I'll check it out now, Discord currently lagging. Thanks, though. 🙂

cinder patio
spark flint
#

because they won't have the actual dates of the signup saved

#

with the ID, you can get the time stamp

cinder patio
#

They can get the original date with the ID...

#

then save it another property so they don't always get it from the ID

spark flint
#

i mean thats true

feral aspen
#

Is there a function to convert 2021-08-17T07:55:58.000Z to a human readable time?

#

Nevermind, found it.

earnest phoenix
#

new Date().ToString()

feral aspen
#

Is there a way to convert 1st to first with st small up.

spark flint
#

what language?

feral aspen
#

Javascript.

#

I have this function.

#
function ordinal_suffix_of(i) {
    var j = i % 10, k = i % 100;

    if (j == 1 && k != 11) {
        return i.toLocaleString() + "st";
    } else if (j == 2 && k != 12) {
        return i.toLocaleString() + "nd";
    } else if (j == 3 && k != 13) {
        return i.toLocaleString() + "rd";
    };

    return i.toLocaleString() + "th";
};
spark flint
#
const nth = function(d) {
  if (d > 3 && d < 21) return 'th';
  switch (d % 10) {
    case 1:  return "st";
    case 2:  return "nd";
    case 3:  return "rd";
    default: return "th";
  }
}
#

found that

compact pier
#

lmao that variable naming

spark flint
#

wait thats probably not helpful pain

feral aspen
#

I want something like this.

#

Not 1st.

#

Is that possible?

compact pier
#

oh the symbol?

spark flint
#

OHH

feral aspen
spark flint
#

Subscript

feral aspen
#

I can't find it. :/

#

Subscript?

compact pier
#

I guess you gotta google it

#

for those symbol or emoji

spark flint
#

2 secs

feral aspen
#

1ₛₜ

#

Goodness, that's small.

spark flint
#

what are yo using it in?

compact pier
#

:))

feral aspen
spark flint
#

oh a bot

#

ig

feral aspen
#

Yes, can't be something else. shruganimated

spark flint
#

i mean it could be a website 😳

feral aspen
#

At this case, nope.

compact pier
#

well 90% ppl here are bot devs tho :))

spark flint
#

ˢᵗ

#

ˢᵗ

feral aspen
#

1ˢᵗ

compact pier
#

damm

feral aspen
spark flint
#

ˢᵗ
ⁿᵈ
ʳᵈ
ᵗʰ

#

1ˢᵗ

#

2ⁿᵈ

#

3ʳᵈ

#

4ᵗʰ

modest maple
#

dude

#

shut the fuck up

earnest phoenix
spark flint
feral aspen
#

It's superscript.

feral aspen
spark flint
feral aspen
#

Thank youuu.

spark flint
compact pier
#

my brain just extended a lil bit

#

:0

feral aspen
#

Same. lmao

eternal osprey
#

hey how do i attach these 2 avatars next to each other?

  var images = [`https://cdn.discordapp.com/avatars/${user1[1].user.id}/${user1[1].user.avatar}.png`, `https://cdn.discordapp.com/avatars/${user2[1].user.id}/${user2[1].user.avatar}.png`];```
#

I cannot use jimp or anything as it's a link to a file. not the file itself

#

Tryna get the profile pics next to each other, but it's not working out for me

spark flint
#

unless you use canvas or something to put the images next to eachother

#

as the images are both going to be square, you could technically do a 512x256 image and have both images together

long lagoon
#

Guys! Is it possible to convert an image URL to emoji for embed message directly through code using dpy?

spark flint
long lagoon
#

Yes

real rose
#

Yeah that should be possible.

spark flint
#
#save the image first
with open("saved image name", 'rb') as fd:
    await ctx.guild.create_custom_emoji(name='emoji name', image=fd.read())```
long lagoon
#

I'm getting the icon URL as response, i wanna use that like an emoji on the embed message

spark flint
#

you can then remove the image using OS

#
import os

os.remove("image name")
long lagoon
#

Oh so it creates the emoji in the server each time ?

#

right ?

spark flint
#

You would ideally make it validate that the message contained an attachment

#

if it did, get the attachment url, save the image from that, then open image and add emoji like i did above

#

keep the discord emoji image size limit in mind tho

long lagoon
#

I see

#

Lemme try rq

long lagoon
spark flint
#

it is but not the easiest

#

the easiest way is to save the image and then remove at the end

#

after adding the emoji you would do os.remove("image name")

long lagoon
#

OKay! Lemme try

#

Thankssss

earnest phoenix
sudden geyser
#

mac gang

spark flint
#

ok so

#

what would be the best way to encrypt a password to then store it

gilded olive
spark flint
#

also is an upgrade from a GeForce GTX 1050Ti 4 GB to a GeForce GTX 1650 4 GB worth it?

quartz kindle
spark flint
#

its £150 for the 1650

quartz kindle
spark flint
#

i've had the 1050 for 3 years now

#

and it needs an upgrade KEKW

winter pasture
spark flint
#

thanks

quartz kindle
spark flint
#

i'll have a look

spark flint
#

then how would i check password on login

#

am using mongo

winter pasture
#

By comparing the hash

spark flint
#

ah ok thanks

winter pasture
spark flint
#

thanks

winter pasture
#

bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
// result == true
});

spark flint
#

i'll have a go later

sudden geyser
#

security is scary

#

it is dangerous to go alone

winter pasture
quartz kindle
#

its not that scary if you know how things work

sudden geyser
#

that's why it's scary

#

we don't know

quartz kindle
#

its recommended if available and convenient to use

winter pasture
#

Ah, any performance benefits? Or basically user controllable?

quartz kindle
#

not recommended if you need to go overboard to make it work

quartz kindle
spark flint
#

whats likely to be the best for my login system

quartz kindle
#

whichever of the three is easiest for you to implement and use: bcrypt, scrypt, argon2