#development

1 messages · Page 1748 of 1

lyric mountain
#

first of all change this to```js
if (data.Claimed) {
...
} else {
...
}

#

then do whatever u want inside the else

vivid fulcrum
#

even cleaner approach

wooden shoal
#

Here's what I meant, I have a schema that stores my boolean, I just wanna know how to correctly store the code and wether it was claimed.

clear marlin
#

for example, you have 10 coins stored, you add another random value to the 10 coins

vivid fulcrum
#
if(condition) {
  ...
  return;
}

//the code got to this point if the condition didn't pass
#

you avoid going down an indentation level

#

which produces cleaner code

wooden shoal
solemn latch
#

👀 whats with the obsession with cleaning up the code.

lyric mountain
#

also, that's twice as much boolean comparations as necessary

clear marlin
#

Your storing a numeric value into a boolean What

wooden shoal
#
const mongo = require("mongoose")

const Schema = new mongo.Schema({
    Guild: String,
    Code: String,
    Claimed: Boolean,
})

module.exports = mongo.model('code', Schema)
clear marlin
#

ahh

wooden shoal
#

That's my schema.

#

I wanna know how to correctly store the data though.

lyric mountain
#

that's the code's schema

#

where's the user's schema?

solemn latch
#

dont think he is worried about user right now

solemn latch
#

hes/shes working on the code generation

lyric mountain
#

but he wants to increase whoever uses the code's balance by 1-10 coins

solemn latch
#

you cant do everything at once

#

he needs to get code generation working first to do that

clear marlin
#

well

const data = <mongoClient>.findOne({
guild: message.guild.id
})
if(!data){ /* do something */}
if(data){
if(data.Claimed){
// do whatever you want
}
}
solemn latch
#

still not helping, hes working on GENERATION

lyric mountain
#

yeah, ik, I'm just addressing the original question

clear marlin
#

he wants to check weather its claimed

#

so shruganimated

#

it would be user tbh

#

my bad

lyric mountain
#

the code generation

wooden shoal
clear marlin
wooden shoal
clear marlin
#

you see if its true or false

lyric mountain
#

inside else, set the Claimed prop to true and store in the database

#

then get the user's data, increase amount of coins and save to database

wooden shoal
#

I don't think you guys understand. It's not checking anything, because I don't know how to store it in the database.

lyric mountain
#

so you don't want to CHECK, you want to know how to STORE it in first place

wooden shoal
#

I know how to store the guild and code, I just don't know how to store if it's claimed or not.

clear marlin
#

you do

await data.save()
solemn latch
#

👀 isnt that what ive been saying.

wooden shoal
lyric mountain
clear marlin
#

confusing

lyric mountain
solemn latch
#

hes looking for find one and update

wooden shoal
lyric mountain
#

data.Claimed = true

clear marlin
#

that's what

solemn latch
#

👀 if it happens down the line data wont exist will it?

clear marlin
#

supposed to be done

wooden shoal
frigid mountain
#

My error says missing semicolon for

message.delete()
wooden shoal
#

I don't know what to store in claimed

clear marlin
#

store true in claimed

clear marlin
#

since it is variable type boolean

wooden shoal
clear marlin
#

ok, now I understand

wooden shoal
clear marlin
#

what you are tryna do

clear marlin
wooden shoal
#

Ok let's say someone does >Claim {Code}

How do I let the database know that the code was claimed?

#

That's all i'm asking

clear marlin
#
claimedCodes: [string]
solemn latch
#

ttl and whatnot

wooden shoal
#

I was thinking

if(message.content.includes(code)) {
  data.Claimed = true;
  data.save()
}
frigid mountain
#
{
   "languages" : ["English",  "Spanish"],
  "translations" :  {
    "THE_SUM_IS {
      "english" :  "The sum is", 
      "spanish" : "LA suma se" 
     } 
  } 
}
clear marlin
lyric mountain
#

lang as in "programming lang"

clear marlin
clear marlin
frigid mountain
lyric mountain
clear marlin
#

javascript, java

#

c#, python, c++, golang, rust

frigid mountain
lyric mountain
#

then it shouldn't cause that error

#

js doesn't require semicolon

#

show a bigger snippet of the code

clear marlin
#

unless eslint hehe_pepe

latent heron
#

anyone wanna make an irc with me

#

pls

#

oh

#

@drifting shell

#

u

clear marlin
#

in php

latent heron
#

no

#

C#

clear marlin
#

hell ya

#

but I'm already making one myself

#

¯_(ツ)_/¯

frigid mountain
#

Line 150

lyric mountain
#

could u show the error too?

frigid mountain
lyric mountain
#

still

#

show the whole stacktrace

drifting shell
latent heron
#

shit dude that's all you had to say

lyric mountain
sage bobcat
#

One message removed from a suspended account.

drifting shell
sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

drifting shell
#

Jokes on me I do Java 90% of the time

drifting shell
sage bobcat
#

One message removed from a suspended account.

latent heron
#

i mean

#

php >

lyric mountain
#

people who use glasses

latent heron
sage bobcat
#

One message removed from a suspended account.

latent heron
#

wanna make a php irc?

lyric mountain
#

you don't have the rights to use that emote

#

because it's blurred

drifting shell
sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

sage bobcat
drifting shell
#

Does that mean it’s a date

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

drifting shell
solemn leaf
#

How would I loop through an array in order 0-inf

solemn latch
#

language?

drifting shell
#

For index loop

solemn leaf
#

javascript

drifting shell
#

Or foreach

solemn leaf
#

foreach didnt work

#

nor did mappin

drifting shell
#

What

solemn latch
solemn leaf
#

yeah and Ive tried alot

lyric mountain
solemn leaf
#

no

#

that will run for ever

#

and I think it would crash too

lyric mountain
#

well, there're infinite values between 0 and inf

subtle river
solemn leaf
#

I said inf as an example

lyric mountain
#
for (let i = 0; i < <array>.length; i++) {
  ...
}
fringe coyote
#
Humble Bundle

Enjoy a collection of Springer Azure books including Getting Started with Containers in Azure & Azure SQL Revealed. Plus, pay what you want & support charity!

lyric mountain
#

that's a book bundle

#

not hosting

solemn leaf
#

when books started costin 1000 dollars

fringe coyote
#

I know, but it's information

lyric mountain
#

who buys coding books nowadays mmLol

solemn leaf
#

when pieces of paper glued together costed 1000 dollars

#

can I do then on a for loop @lyric mountain

clear marlin
solemn leaf
#

how

solemn latch
#

do you mean like you want to resolve a promise inside the loop?

solemn leaf
#

When the loop is finished I want to log that

lyric mountain
solemn latch
#

can just put it under the for loop, unless you do something async inside each loop(afaik)

lyric mountain
#

yeah, iteration will be stuck inside the for loop until it finishes or you break it

#

anything after the loop will only be ran after it finishes

solemn leaf
#
    async function addRow() {
        try {
            if (!sheet.title == date) return sheet = await doc.addSheet({ title: date, headerValues: Headers }).then(async () => addRow());
            for (let i = 0; i < hosts.length; i++) {
                ping.sys.probe(hosts[i], async (isAlive) => {
                    await sheet.addRow({ Time: dateFormat(new Date().now, "h:MM:ss TT"), Price: 'N/A', Item: 'N/A', Site: host, Status: isAlive ? 'Alive' : 'Dead' }, { insert: true });
                }, { timeout: true });
            }
                await sheet.addRow();
                console.log("Done");
        } catch (e) {console.log(e); }
    }
solemn latch
solemn leaf
#

I just did promises

#

that is what the image was

#

and it wasnt in order

#
    async function addRow() {
        try {
            if (!sheet.title == date) return sheet = await doc.addSheet({ title: date, headerValues: Headers }).then(async () => addRow());
            await Promise.all(hosts.map(async (host) => {
                ping.sys.probe(hosts[i], async (isAlive) => {
                    await sheet.addRow({ Time: dateFormat(new Date().now, "h:MM:ss TT"), Price: 'N/A', Item: 'N/A', Site: host, Status: isAlive ? 'Alive' : 'Dead' }, { insert: true });
                }, { timeout: true });
                await sheet.addRow();
                console.log("Done");
            })).then(() => {
                await sheet.addRow();
                console.log("Done");
            });
        } catch (e) { console.log(e); }
    }
solemn latch
#

oh, i see.
are you using a library which has access to inserting multiple rows at once?
google sheets api(what i presume you are using) allows the insertion of many rows at once.

#

since its just one call, it all happens in order.

solemn leaf
#

yeah no

#

Im not doing that

solemn latch
#

👀 okay, then youll need to make your own promise queue.

solemn leaf
#

and why doesnt mapping it work

solemn latch
#

you are mapping promises, so the actual promises may resolve out of order, even if they all happened in order

#

thats just the nature of promises

solemn leaf
#

is there a way to get a sheet

#

by its name

pale vessel
#

use a for loop

#

await each call

solemn leaf
#

you cant lol

solemn latch
#

for loops also have this issue iirc.

solemn leaf
#

wait nvm which are we talking about

pale vessel
#

why are you using async function inside map

#

it won't run asynchronously

solemn latch
solemn leaf
#

so a for loop wouldnt work?

solemn latch
lusty quest
solemn leaf
#

bruh

solemn latch
#

just a heads up, it will be slower this way. if your doing 30+ rows, it will take longer.
since you have to wait for each api request to complete, your just waiting for awhile.

solemn leaf
#

I said that like an hour ago

#

How does addRows work then

solemn latch
#

👀 what library are you using.

solemn leaf
#

I think

#

google-sheets

pale vessel
#

Why don't you just use addRows()

solemn latch
#

thats what i suggested awhile ago pandasad

pale vessel
#

It's google-spreadsheet

solemn leaf
#

I would still need the loop

pale vessel
#

For?

solemn leaf
#

and it would still be out of order

pale vessel
#

It won't

solemn leaf
#

to loop through all the sites and add the messages

solemn latch
#

the out of order is because of promises, not because of the methods used.

pale vessel
#

Construct the array with the for loop (since you want it to be async) and pass the array to the addRows() method

#

One API call

solemn leaf
#

give me a second to find where the hell it is listed in the docs

solemn latch
#
const moreRows = await sheet.addRows([
  { name: 'Sergey Brin', email: 'sergey@google.com' },
  { name: 'Eric Schmidt', email: 'eric@google.com' },
]);

the example is that simple.

#

you just pass it as the array of objects

pale vessel
solemn leaf
#

yeah the docs are shit on the github you cant find anything

pale vessel
#

The docs is good and well documented though amandathink

solemn leaf
#

you have to open the worksheet then methods

#

thats why it took me long

crimson vapor
sage bobcat
#

One message removed from a suspended account.

crimson vapor
sage bobcat
#

One message removed from a suspended account.

solemn leaf
#

then you know c sharp

solemn latch
sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

solemn latch
#

I really just havent been deving as much as I used to do, so not spending as much time learning new things.

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

astral crown
#

In python how to make a bot leave a server?

quartz apex
#

Does someone know how i display the number of servers my bot is in? PepeSantaRun

#

When I try this my bot displays 0

zenith terrace
#

servers

#

not guilds

#

oh wait

quartz apex
#

thx

zenith terrace
#

it is guilds

solemn latch
#

👀 nice one star

zenith terrace
#

ez find

quartz apex
#

thxxx Smart p_kissasf

deep mantle
astral crown
deep mantle
#

?

quartz apex
#

It still displays 0

deep mantle
#

use client.get_guild then use await (serverthing).leave()

astral crown
#

What did I do wrong here?

frigid mountain
#
const Discord = require("discord.js");
const config = require("../../botconfig/config.json");
const ee = require("../../botconfig/embed.json");

module.exports = { 
    name: 'meow', 
    category: "Games",
    aliases: ["cat"],
    cooldown: 2,
    usage: "meow",
    description: 'random kitty', 
    run(message, args){ 
        message.channel.send(randomMessage);
    }
}
const messages = [
    "meow",
    "kittie's",
    "Lucky Meow 777",
];

const randomMessage = messages[Math.floor(Math.random() * messages.length)]; 
deep mantle
vivid fulcrum
#

also

astral crown
vivid fulcrum
#

randomMessage will always be the same

deep mantle
pale vessel
#

shouldn't the ID be int?

#

try casting the ID to int

deep mantle
#

oh yeah

pale vessel
#

(ctx, id: int)

deep mantle
#

^

frigid mountain
#

Thx solved the problem

astral crown
astral crown
eternal osprey
#

hey! How do i attach a variable to a message.attachment to eventually send that variable to a channel?

vivid fulcrum
#

you don't

#

what do you want to do

eternal osprey
#

i want to save a user's sent image, to immediately redirect to another channel

vivid fulcrum
#

re-upload or just send the link

eternal osprey
vivid fulcrum
#

do you want to re-upload the image or just send the link to the image

eternal osprey
#

nvm, i already got the solution. Message.attachments is an object with a url property.

#

so i will just use that to send. Thanks

vivid fulcrum
#

it's a collection

#

a message can have multiple attachments

#

ironically the only platforms that support it are mobile lmfao

upbeat summit
#

Hi i am new here like development

vivid fulcrum
#

hello new here like development, i'm dad

solemn leaf
#

Anyone good with promisify

#

For nodejs

vivid fulcrum
#

what is there to be good at

solemn leaf
#

Idk how to use ut

#

And I kinda need to

vivid fulcrum
#

have you tried reading the docs?

solemn leaf
#

Yea

vivid fulcrum
#

so what don't you understand

#

you get a concrete example

solemn leaf
#

All

vivid fulcrum
#

what is all

#

which part of it don't you get

sudden geyser
#

Do you want to convert a callback into an async function?

solemn leaf
#

const isAlive = await util.promisify(ping.sys.probe)(Hosts[i], { timeout: true });

sudden geyser
#

What's wrong with the statement?

solemn leaf
#

Its null

vivid fulcrum
#

what is null

#

the result?

solemn leaf
#

isAlive

sudden geyser
#

The use of util.promisify looks correct, but the context in the expression is ambiguous. We don't know what ping, ping.sys.probe, Hosts[i], etc. is

solemn leaf
#

Ping

#

Npm

#

It checks if a site is online

sudden geyser
#

Do you have the link to the documentation for .probe

solemn leaf
#

Uh

eternal osprey
#

hey! I am trying to get a due date in djs, but it is returning me numbers: Due date: 1621065462601 Code: ```js
const currentday = new Date();
const test = currentday.valueOf() + msseconds; // which was set to 12h

quartz kindle
#

new Date(test)

eternal osprey
#

owh what really?

sudden geyser
# solemn leaf Npmjs.com/package/ping

There's an asynchronous alternative built into the package.

var ping = require('ping');

var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];

for(let host of hosts){
    let res = await ping.promise.probe(host);
    console.log(res);
}

Your current answer is incorrect because util.promisify acts on the callback as if it's the last parameter of the function, but probe uses the second argument (preceding options) instead.

haughty sorrel
#

How do I make a topgg stats command?

sudden geyser
#

Depends on what you want to do with the stats

#

If you want to display details on a bot, you'll need an API key (generating for each bot) and hit the API to receive bot details.

solemn leaf
#

What

#

So I cant use probe to do this

sudden geyser
#

The solution is built right into the library—asynchronously process the probe by returning a promise instead of passing a callback.

#

You don't need util.promisify

solemn leaf
#

Sum it up i dont understand

quartz kindle
#

lol

sudden geyser
#

TL;DR - Learn to read the documentation.

snow urchin
#

@lavish briar oi

#

dm

quartz kindle
#

what about this dont you understand?

solemn leaf
#

That doesnt return if the site is up actually

quartz kindle
#

wat

solemn leaf
#

Test it

sudden geyser
#

res should be a boolean.

#

You're the one using the library. You should be the one to try it out.

#

Our answer was about using the library asynchronously—not if the ping actually worked.

quartz kindle
vivid fulcrum
#

which like

sudden geyser
#

ah

vivid fulcrum
#

you really don't need the library anyways

#

you can use node-fetch and chances are that one of your deps already uses it

solemn leaf
#

The for loop

#

The reason i needed to promisify

quartz kindle
#

you dont...

solemn leaf
#

So it would loop and unshift the array

alpine hornet
#

Hey guys! I'm trying to set up a dm command with a preset message, does anyone know how to do it?

quartz kindle
#

just await it

solemn leaf
#

Before it added to the speeed

quartz kindle
#

???

vivid fulcrum
#

you generally shouldn't interact with users unless they started the interaction first

alpine hornet
vivid fulcrum
#

ah

#

which lib are you using

alpine hornet
#

I figured it out. @vivid fulcrum

eternal osprey
#

what is the opposite of array.push?

vivid fulcrum
#

pop

eternal osprey
#

but that removes everything except the last element

vivid fulcrum
#

no it doesn't

eternal osprey
#

i need to remove one specific element

vivid fulcrum
#

otherwise it wouldn't be called pop

placid iron
#

Development

eternal osprey
#

``const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];

console.log(plants.pop());
// expected output: "tomato"``

vivid fulcrum
#

yes

#

because pop returns the popped element

#

read further than the first two lines

eternal osprey
#

oowh alright

#

i did

vivid fulcrum
#

but if you're looking to remove a specific element and you're unsure of its position

#

you can use findIndex and then throw whatever findIndex returned into splice

#

findIndex can return -1 if the element isn't found though, keep an eye out for that if you're going to use it

cedar rose
#

is it possible to connect two webhooks to a topgg server page, a faucet that checks who's voted and a vote reminder that checks who's voted

vivid fulcrum
#

im fairly certain you can only use one

#

but why would you use two anyways

#

make it a monolith

#

a single listener that does both things

cedar rose
#

because the vote reminder has already been made and the faucet hasn't

#

why topgg no allow multiple webhook??

solemn latch
#

thats pretty standard for webhooks(one per application)

cedar rose
lyric mountain
#

I can count in my hand services that allow multiple webhooks

solemn latch
#

generally its up to you to handle everything after the webhook. afaik thats pretty standard with api's and webhooks.

cedar rose
#

interesting info

tulip ledge
#

Dang Woo ur a moderator now? congrats

cedar rose
#

does external bot rewards apply to server voting

solemn latch
#

like vote for x server, get rewards for another?

cedar rose
#

like we just want to reward server voters

cedar rose
solemn latch
#

thats not external, so thats fine.

cedar rose
#

so vote for x server get rewards for y server is not allowed

solemn latch
#

thats not ok, yeah.

cedar rose
#

thanks

earnest phoenix
#

I'm having trouble at making this

#

It is basically to make the bot disconnect if the server song queue is empty

sudden geyser
#

.dispatcher is null, so you may want to look up the type of .connection

earnest phoenix
#

thanks

ivory dove
#

g!help

earnest phoenix
#

Jokes the problem is that when the bot is playing music it randomly stops and the commands won't work anymore

quaint wasp
#

My code is this

#
if (error) {
    message.channel.send(`I got an error. Bruh. How are you even getting these?! \n Error: **${e}**`)
}```
#

says error undefined..

#

😐

earnest phoenix
#

you should consider using try except

quaint wasp
#

how?

#

try {error} {
//
}

#

?

quaint wasp
weary crypt
#
try
{
  //code
}
catch(Exception ex)
{
   //code
}

//this is optional...
finally
{

}
#

When you do this it is cached, so I usually tend to stay away from it unless a user has input, because people will try to break anything.

earnest phoenix
#

I'm guessing actually

#

wait actually not

#

but that's d.
py syntax

#

anyway

weary crypt
#

I am not sure what he was using, he should kinda look it up for himself though. They aren't hard to learn, but useful for user input etc...

opal plank
#

@earnest phoenixfirst, python comments are # not //
second, thats js syntax

py is try/except
js is try/catch/finally

#

didnt look further, but either you or that other guy legit did an oopsie

#

and a big one at that

opal plank
#

@earnest phoenix so, yeah, you tripping hard mate

weary crypt
#

Yea Js looks a lot like C# syntax wise

opal plank
#

cuz it may be an object

#

js considers an empty object truthy

quaint wasp
#
module.exports = {
    name: 'poll',
    execute: async (client, message, args) => {



        if (!message.member.hasPermission('ADMINISTRATOR')) {
            return message.channel.send("You can't use that! You **have** to have **Administrator** prommision.");
        };

const Discord = require('discord.js')
const pollchannel = message.mentions.channels.first()
if(!pollchannel) {
    return message.channel.send("You didn't provide a channel... \n Bruh")
}
const question = args.join(" ").slice(21)
if(!question) {
    return message.channel.send('You did not provide a question.')
};

const polle = new Discord.MessageEmbed()
.setTitle('New Poll')
.setDescription(`**${question}**`)

.addFields(
    { name:'Author', value:`${message.author}`, inline:false},
)
.setColor('RANDOM')
let msg = await pollchannel.send(polle)
await msg.react(':thumbsup:')
await msg.react(':thumbsdown:') 

message.channel.send(`New poll had been created in ${pollchannel} by ${message.author}`)
//////////////////////////////////////////////////////////////////////////////////////////////////////
//ERROR
if (error) {
    message.channel.send(`I got an error. Bruh. How are you even getting these?! \n Error: **${e}**`)
}
//ERROR
//////////////////////////////////////////////////////////////////////////////////////////////////////
console.log("Poll command had been ran..")
}

    }

#

wait- wait wait wait

#

I should not require in there

weary crypt
#

I am confused, where do you set 'error' at?

opal plank
#

yeah you need to properly catch stuff

#

in a try/catch block

#

actually

#

it'd be bad to do that. properly catch each individual promise

crimson vapor
#

Hi Airwin

opal plank
#

<promise>.catch((e) => {console.log(e); error=e});

#

log ur errors and set it to a variable in the code

#

then run that messgae.channel.send() thing

opal plank
crimson vapor
#

Hi

quaint wasp
#

o

#

thanks

#

still doesnt know what error is.. when I put error on promis..

#

wait

#

how do you make it a variable?

dense linden
#

Uh i have an error in vote

latent heron
#

@drifting shell so wanna join me with the IRC project? 👀

#

i don't mind collabing 👉🏻👈🏻

latent heron
#

making an IRC

crimson vapor
#

Ah

latent heron
crimson vapor
#

@pale vessel do you have much experience with slash commands?

austere zealot
#

aah mb for ping but i got this error

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 1348, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: parameters are of unsupported type
lyric mountain
#

can't help much more than that

austere zealot
#

hm ye, i just saw something related to this on stack and said to add a , without the space

#

:\

rocky hearth
#
class Square {
  isEmpty = true
  piece: Piece | null
  constructor() {
    this.piece = null
  }
}

const square = new Square()

if (!square.isEmpty) {
  const piece = square.piece
  // Here, piece is of type Piece | null
  // How do I make sure that it always return a Piece when the square is not empty
} else {
  // Here square.piece must always be null
}
winter thorn
#

#user 836651794939379712

#

!user 836651794939379712

vivid fulcrum
#

and just check if the piece is null

#

if it's null it means it's empty

rocky hearth
#

yeah, but I want it to be a little bit easier to read and understand

vivid fulcrum
#

if you really wanna be verbose and go with the isEmpty route, make isEmpty return a boolean based on the value of the piece

rocky hearth
#

I could make it a getter, but still the same problem

vivid fulcrum
#

it wouldn't be

#

because isEmpty is directly coming from the comparison on the piece

rocky hearth
vivid fulcrum
#

yeah

#

you're now sure that it's going to have a value

#

the compiler isn't smart enough to understand that

rocky hearth
#

square.piece is still a nullable value in the if block. which I dont want

vivid fulcrum
vivid fulcrum
#

you're overcomplicating

#

you can let typescript know it has a value by using !

#

but again just omit isEmpty if you want clean code

rocky hearth
#

if the square is not empty, than there must a Piece not still Piece | null, in the if block

vivid fulcrum
#

i understand lol

#

the intellisense isn't smart enough to understand that piece has a value inside of that block because you're using isEmpty

#

however

#

if you omit isEmpty and just check the piece directly

#

type problems will get fixed

#

then intellisense will understand that it has a value inside of the if block

rocky hearth
#

but there is a way, which some react library do.
Like if we add prop to an JSX.Element it may or may not require other props as well, depending on the initial prop we provided.

#

the required props, changes dynamically

vivid fulcrum
#

that's because of type overloads

#

different thing than what you're trying to do

rocky hearth
#

So how can I use that, here

vivid fulcrum
#

i don't understand why you're being so stubborn about not checking piece directly

#

it's a cleaner and a more "proper" way

#

alternatively use the assertion operator

#

this produces ugly code though

#

but it's exactly for your use case

rocky hearth
#

Does C++, C# also has this problem?

vivid fulcrum
#

they don't

sudden geyser
#

Unless you plan on adding more rules for what counts as "empty" for your square class, you should be directly checking if piece is null as cry has said.

#

You're making your program more complicated for trivial benefits.

vivid fulcrum
#

c langs are typed at their core, null isn't its own type, it's a value

#

you'll just get an exception if trying to access something on a null object

rocky hearth
#

I want to know, if dart can solve this problem.
Have u used dart, to compile down to js?

sudden geyser
#

Dart has implicit and forced nullable casting.

#

Forced is the same idea as the ! assertion.

#

Implicit is being able to do something like: ```dart
int? maybeFive = 5;

if (maybeFive is! null) {
// ... => maybeFive is int; not int?
}

#

Though you probably don't need Dart.

#

Just use the solution cry suggested

#

or force cast it

rocky hearth
#

hmmm, ok thanks

crimson vapor
#

rip

#

im testing em

rocky hearth
#

which method is more efficient and recommended to populate an array, with some values?

function populateMethod1(size) {
  const arr = [];
  for (let i = 0; i < size; i++) {
    arr.push(/* Some value of choice */);
  }
  return arr;
}

function populateMethod2(size) {
  return Array.from(Array(size), (_, i) => {
    return /* Some value of choice */
  })
}
lyric mountain
#

Well, loop is the fastest

crimson vapor
weary crypt
clear marlin
#

down

fiery stream
#

is this good enough

pale vessel
#

Looks good

fiery stream
#

cool

errant hornet
#

How would I make it so my bot can single out a mention in a series of mention.

Like for the bot to add a role to every user that I mention in a single message

Discord.js^

fiery stream
#

@errant hornet args.split(/[, ]+/);

errant hornet
#

Yes but how would I split the mentions?

fiery stream
#

like taht...

#

that*

errant hornet
#

So just that?

#

Okay

fiery stream
#

mhm

#

well you need a little function to array out a mentions

runic gyro
#

how can i change the font color in my bot panel?

fiery stream
#

uhm

#

css

runic gyro
#

i did this

#

but

#

i want my font to be black

#

how to do that

old cliff
#

Learn css

#

Use css

#

Live css

royal herald
#

css is love,css is life

old cliff
#

Yeah

weary crypt
runic gyro
#

ik css

#

but i tried the code

#

it didn't change to black

fiery stream
runic gyro
#

i tried this..

#

it doesnt change..

fiery stream
#

Then you’re doing something wrong

runic gyro
#

what can it be

#

should i send u code in dm?

errant hornet
#

How would I remove a character from a response, like if I wanted to have just H from inside [H]

pale vessel
#

use string.replace() with regex and the global modifier or string.replaceAll()

delicate shore
#

how to make a cmd like this

#

I use discord.js

pale vessel
#

sort your guilds by member count and map the sorted collection

lusty quest
frigid mountain
#

What must I change so the command can be run in guilds and dm's?

craggy pine
#

! I'd hope you know what a ! would mean in that line of text.

slender thistle
#

!!!!!!!!

craggy pine
#

if (!!!!!!!!message.guild)

slender thistle
#

oooo fuck yes

#

Make that required

craggy pine
delicate shore
#

and will only run in private admin only channels

#

don't worry bout that

earnest phoenix
#

İt means not

craggy pine
#

So with that little bit of knowledge, it should assist with what you're trying to do.

woeful pike
#

oh you asked this 200 years ago

craggy pine
#

200 years? damn I'm old now

frigid mountain
#

Woah

marble juniper
earnest phoenix
#

but yeah I blame it being 1am of my time since it clearly all js starting from string format to code block itself

oak nymph
#

I want my bot's website to automatically change the number of servers and number of users by itself using the discord api, although the code for the site is written in html css and js, any way possible to do it?

quartz kindle
#

it can be done in many different ways

#

the easiest way is probably to have a small server inside the bot that responds with the data when you send a request to it, and have the website send a request every 5-10 seconds

placid iron
#

Or you can send a post request to your website from the bot with the new guild count every time that changes

#

Or yeah every delta time

#

Whatever you want, if it becomes larger do it delta time

earnest phoenix
#

soo i created another bot and somehow the command wont work

#

is there problems?

#

the prefix is this

copper cradle
#

first of all, you're not doing anything with the prefix

#

that code literally checks if the content of the message is ping

earnest phoenix
#

ok i got it working now

copper sage
#

Can a bot use animated emojis?

copper cradle
#

yes

gritty ice
#

Yeah

copper sage
#

Nice

gritty ice
#

But that emoji you need to add your server then copy the id

copper sage
#

Yes ik

gritty ice
earnest phoenix
#

like

#

and i will copy the id?

brittle hamlet
#

For a memebot (discord.js) is it possible to filter videos and only send photos and gifs from the subreddit?

brittle hamlet
#

Umm How?

clear marlin
earnest phoenix
#

wait how do i do this

clear marlin
#

what lang?

#

@earnest phoenix

earnest phoenix
#

eng

brittle hamlet
#

Programming language.

clear marlin
#

no lol, programming language

earnest phoenix
#

ah

#

vsc

clear marlin
#

discord.js?

earnest phoenix
#

yea

brittle hamlet
clear marlin
#
<Client>.user.setActivity("something",{type:"PLAYING"})
#

lol

copper cradle
earnest phoenix
#

ah

clear marlin
#

if you want it to stream

<Client>.user.setActivity("something",{type:"STREAMING", url:"twitch.tv/pewdiepie"})
copper cradle
#

how can you not know what programming language you're using lol

earnest phoenix
clear marlin
#

its fine, I mean although you could learn a bit of js or nodejs before attempting discord.js

brittle hamlet
#

Yea

copper cradle
#

saying it like that makes discord js sound like a programming language, when it's just a library

earnest phoenix
#

got it working after an hour

#

How can i sort %all% to the end
My array of Object

[
{trigger:"!hi"},
{trigger:"%all%"},
{trigger:"!help"},
...
]
pale vessel
#

array.sort(x => x.trigger === "%all" ? 1 : -1);

#

1 would bring the element to the back and -1 would do the opposite

rapid wharf
#

i made a def in a cog file, but when using it it is givivg an error that Unresolved Reference
My code:

        with open("about.json", 'r') as f:
            users = json.load(f)
        return users

    @commands.command(aliases=['Aboutme', 'ABOUTME', 'AboutMe'])
    async def aboutme(self, ctx, *, information):

        users = await get_about_data()
        user = ctx.author```
#

error on second last line users = await get_about_data()

pale vessel
#

Are those aliases necessary

#

Aren't command names case-insensitive

rapid wharf
pale vessel
#

Why await the function?

#

Try removing it as the function isn't async

rapid wharf
#

let me try doing it async

earnest phoenix
#

i cant think of any commands sadKEK

#

wait how do i do the ping tho

#

like this

pale vessel
rapid wharf
pale vessel
#

If only norizon is lurking

#

Hmm

rapid wharf
#

removed await, still same

#

@pale vessel

pale vessel
#

Might wanna wait for a pythonista to help you bro

rapid wharf
#

okh

earnest phoenix
#

;

marble juniper
woeful pike
rapid wharf
rapid wharf
lament stump
#

link to a school meeting

#

@ripe prairie

#

nvm it's gone

copper cradle
#

oh wait I didn't see xetera's reply smh

#

I love how this would've worked in c++

woeful pike
#

ye c languages have an implicit this inside class methods but not every language does

copper cradle
#

yeah

#

https://github.com/google/zx this is actually a pretty clever use for string literals

GitHub

A tool for writing better scripts. Contribute to google/zx development by creating an account on GitHub.

earnest phoenix
#

is this good?

copper cradle
#

yeah but no

earnest phoenix
copper cradle
#

commands doesn't exist

earnest phoenix
#

the file name tho

copper cradle
#

wdym

earnest phoenix
#

i will link other commands to mainjs

copper cradle
#

I'm talking about the variable

earnest phoenix
#

oh

copper cradle
#

that has nothing to do with any file

#

try to run it

#

it's gonna throw a reference error

earnest phoenix
#

the bot?

#

I'm having a problem, my bot plays music and suddently it stops and music commands won't work anymore, anyone that might know the problem?

#

he's right

copper cradle
#

that wasn't the error I said

#

you got that error bc you tried to run node.

earnest phoenix
#

ah

copper cradle
#

node. isn't a thing on your pc, probs node <filename> or .

earnest phoenix
#

node .

#

to start it

#

yeah i typed it

#

have u downloaded the node.js?

#

there should be a space, node .

copper cradle
#

s p a c e

earnest phoenix
#

script error

#

show the white part

#

c/users?

copper cradle
#

that's not the part of the error you should be reading

earnest phoenix
#

excacly

copper cradle
#

you still gotta learn to read errors

earnest phoenix
#

you should read at the top, it tells u where the error is located

copper cradle
#

I literally told you

earnest phoenix
#

maybe show more?

#

command

#

not commands

copper cradle
earnest phoenix
#

should be like this

teal goblet
earnest phoenix
#

now does anybody there have experience with music bots? i'm having troubles with mine

#

like that?

copper cradle
#

this is what an uncompressed bot looks like

#

yeah

copper cradle
#

that should work now

earnest phoenix
#

just stops playing music and the music commands wont work anymore

#

kinda disappointed

teal goblet
#

What module you use?

earnest phoenix
#

ah

#

it gives error if i try doing command rn

earnest phoenix
#

ffmpeg ytdl search and the other yt

teal goblet
#

Sorry, i mean what npm

earnest phoenix
#

yeye

teal goblet
#

Ok

earnest phoenix
#

search and core

teal goblet
earnest phoenix
#

can't open the bot rn but i remember it says that "end is null"

#

withouth this line it wont disconnect on stop or skip command

teal goblet
#

What npm you use to define server_queue?

earnest phoenix
#

i've downloaded like ytdl-core ytdl-search and ytdl-core opusscript

#

i've made a const for server_queu

teal goblet
#

And what define the queue?

earnest phoenix
#

ytdl-core i think

#

have also a const for queue

#

not totally sure

#

problem is also that i can't connect to the bot console rn, i can try it on my pc tho

#

it runs smootly on my pc, i think it's due the server it's being hosted on

teal goblet
#

Maybe, the server must have a good connection to play music

earnest phoenix
#

like it freeze and won't play music anymore, if i try to stop to make it leave the error to "end being null"

robust harness
#

So I wanted to make a command so they can check if they have voted and i dont this but says topgg.hasVoted isnt a function what would i use otherwise
code for it below:


module.exports = {
    name: "test",
    description: "test command for top.gg vote checker",
    async execute(client, message){
        let voted = await topgg.hasVoted(message.author.id);
        if(!voted) {
            return message.channel.send(`You havent voted yet!`)
        } else {
            return message.channel.send(`Voted`)
        }
    }
}```
sudden geyser
#

I believe the hasVoted function is under the Api class in the top-level export.

#

And since it's a class, you need to initialize it before you can use it.

robust harness
#

ahh yea i forgot to put the topgg client part in

frigid mountain
#

I know how to make a say command but now I want to make my say command so that if I type "helll world" it types hello world

sudden geyser
robust harness
sudden geyser
#

aka having one instance of that variable and sharing it across areas like commands

sudden geyser
#

as opposed to making a bunch of separate instances of topgg.Api

sudden geyser
# earnest phoenix

I think they want to make it so when they run something like !say "Hello world" it responds with Hello world

robust harness
#

i think i could do something like put it in the config file and then checks there for the instance each time maybe

crimson vapor
sudden geyser
#

Which sounds like a need for regular expressions

#

Though accepting an arbitrary number of arguments after would be easier

#

and more elegant

near stratus
#

umm
.split('"')[1] should do

sudden geyser
#

That assumes the user doesn't use " anywhere in their message

frigid mountain
#

Omg

#

🤦‍♂️

earnest phoenix
#

idk y should u do it like this bu there ya go

frigid mountain
earnest phoenix
#

try explaining better

#

wait, you want like a corrector bot?

sudden geyser
#

He wants to create a say command.

#

And add support for quotations.

#

But the issue has already been solved (it seems)

earnest phoenix
#

nice i guess

olive roost
#

can anyone tell me about webbook in top.gg

near stratus
olive roost
#

@near stratus can you explain me about authorization instead of there

near stratus
#

Where are the 3 pings ?

olive roost
#

i provided worng

near stratus
#

Are you using NodeJS ?

olive roost
#

yes

#

i m

near stratus
#

and express

olive roost
#

ok

#

express is already there

near stratus
#

Then run the sample code from their docs

const Express = require('express')
const Topgg = require('@top-gg/sdk')

const app = new Express()

const webhook = new Topgg.Webhook('The_auth_Token')
app.post('/vote', webhook.listener(vote => {
  console.log(vote);
}))

app.listen(3000)

(Definitely not spoonfeeding)

#

Then click on the Test webhook from the bot page

#

wait a few seconds (maybe minutes) and you should have your demo vote on console

olive roost
#

@near stratus whats auth token

near stratus
#

In this case topggauth123

#

You can set it yourself

olive roost
#

@near stratus and same in like const webhook = new Topgg.Webhook('topggauth123')

near stratus
#

yes

olive roost
#

ok thanks a lot

near stratus
#

^°^

olive roost
#

@near stratus is this ok

near stratus
#

Umm

#

you'e supposed to upt ypur Webhook URL there

#

not From Discord

olive roost
#

ok

wispy glen
#

I think you can use google scripts no?

earnest phoenix
near stratus
#

Discord Webhook !== Topgg Webhook

olive roost
#

?

olive roost
near stratus
# olive roost ?

Topgg Webhook will send a request to your server / VPS / wherever you're hosting a bot

sudden geyser
near stratus
# olive roost this to add

So the webhook URL should be
https://69.69.69.69:4200 Here 69.69.69.69 is your IP and 4200 is your PORT

tacit kiln
#

Hi, Im a new bot developer that had a very general question about making my bot public:

Is there a limit to how many servers my bot can be in? I've heard rumors about this but can't find official documentation. How do you avoid this?

olive roost
#

ok

near stratus
olive roost
#

is this ok now

wispy glen
near stratus
olive roost
#

ok

near stratus
#

not 69.69.69.69

#

it was an example

olive roost
#

thanks for help

near stratus
#

amd your post is 3000

sudden geyser
tacit kiln
earnest phoenix
#

there is no limit wym

tacit kiln
#

@earnest phoenix

olive roost
#

how can i find my ip

sudden geyser
wispy glen
#

Bot limit in Discord
A bot can be present in a maximum of 2,500 guilds per WebSocket connection. In order to allow a bot to be present in more guilds, the bot must implement sharding and open several separate WebSocket connections to Discord.

tacit kiln
#

for someone that has gone through the process before: should i be trying to verify my bot now before i hit 100 servers?

olive roost
sudden geyser
#

You can verify your bot once it reaches 75 servers.

#

Which takes a few days I think.

earnest phoenix
#

they changed it?

sudden geyser
#

Did they?

earnest phoenix
#

idk

#

thought it was a month

tacit kiln
#

o

olive roost
#

its 76

tacit kiln
#

So you can verify your bot when u get to 76 servers, You have to verify before 100 or 250, then to pass 2500 u need to do another update for sharding?

#

are there any other restrictions a new bot owner should know about? I would like to share my bot beyond 3000 servers, ofc thats the dream if its well liked

sudden geyser
#

The second update is to make your bot conform to the requirements of sharding. It doesn't require a verification process.

#

I don't think there are any other restrictions you should be wary of.

olive roost
#

how do i get ip?

tacit kiln
#

thank you very much for the info @wispy glen @sudden geyser @earnest phoenix , im very much looking for guidance as a bot developer! if anyone would like to teach me more or just chat with a fellow bot owner that has big dreams of making an impact on discord, then please add me as a friend, i would love to chat more with people doing similar stuff as me:) have a good day

spare badger
olive roost
#

so how

sudden geyser
#

He wants to get his VPS's IP

olive roost
#

yes

latent heron
spare badger
#

@latent heron No legal documented legit way 😛 There is always a way

latent heron
#

That's correct then 😂

snow urchin
#

Using moment

spare badger
#

@snow urchin Look into the momentum diff function. It allows you to compare two datetimes and get the difference in time. You would then have to create your own logic to show it to the user the way you want it to.

earnest phoenix
#

wait

#

if i download ffmpeg

#

which one will i pick?

#

the source code or pgp key?

#

or both

spare badger
earnest phoenix
pale vessel
#

I don't think they support precision

spare badger
#

@earnest phoenix I guess it depends on what you are trying to do?

pale vessel
#

you probably need to use ms or something, something that allows you to format the string

spare badger
#

What are you trying to do roughly?

earnest phoenix
#

music bot

spare badger
#

Using node.js?

earnest phoenix
#

hmm

#

discord.js

spare badger
#

On a linux machine?

earnest phoenix
#

windows

spare badger
#

So when you go to the website of ffmpeg you can download the executable you need for Windows on the bottom left.

earnest phoenix
#

oh

spare badger
snow urchin
snow urchin
weary crypt
spare badger
#

@snow urchin I think that would require some custom logic. You would have to do something like:

var now  = "04/09/2013 15:00:00";
var then = "02/09/2013 14:20:30";

const timeDifference = moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss"));

if (timeDifference <= 60000) {
  // Display in seconds since it is less then one minute
} else if (timeDifference <= 60000 * 60) {
  // Display in minutes since it is less then one hour
} else if (timeDifference <= 60000 * 60 * 24) {
 // Display in hours since it is less then one day
} else {
  // Display in days since it is more then one day
}

Not sure if the above code is exactly right, but it would roughly look like this.

lusty quest
weary crypt
#

Yea they really are

#

If there is a good API for Lavalink it makes it much easier

sudden geyser
spare badger
#

Leap seconds?

rocky hearth
#

is this good to empty an js array? arr.splice(0, Infinity)

spare badger
#

Sure I guess lol. Would have to look at how momentum handles things.

pale vessel
#

just array = []?

rocky hearth
#

it will create another array, (I mean new reference)

pale vessel
#

what's wrong

#

you just want to empty it, right?

rocky hearth
#

I hv a habit, to declare const vars as much as I can

spare badger
#

So you want to empty an array you have defined as a constant?

#

I would say you should not make that a constant then since you are changing it.

rocky hearth
#

yup, another method I got was this, arr.length = 0

sudden geyser
spare badger
#

Yea I see the StackOverflow page you find these solutions at. I would just make it a var or a let and empty the thing by creating another instance.

#

I don't see why you would want to make it a constant if you are changing things inside the thing.

sudden geyser
#

Making the array const and using methods to mutate the array is not a bad habit

#

It's just not as useful as const could really be to mean immutability.

rocky hearth
#

hmmm, to achieve immutability, I freeze the array

sudden geyser
#

You can do that too

rocky hearth
#

I couldnt resist myself from making code, as memory and performance efficient as possible.
I sometimes, make the code very complex and difficult to understand to achieve that.
How do I help myself. I waste alot of time too, even weeks on a single function

earnest phoenix
#

do i need node.js for the music bot or no?

weary crypt
#

You can use other languages for it as well

sudden geyser
#

e.g. Rust

earnest phoenix
#

i already have node.js installed

sudden geyser
#

By nature, JavaScript's exotic, dynamic nature does not put it on par with performance efficiency, proof, and memory (though it's "memory safe" to some degree)

spare badger
#

@earnest phoenix If you want to interact with the Discord API through a library like discord.js like you said you wanted to use, then yes you do need NodeJS.

woeful pike
sudden geyser
#

show more

earnest phoenix
#

Yup

#

Show the whole error

woeful pike
#

guys help I'm getting some errors

earnest phoenix
woeful pike
#

pls help

pale vessel
#

😐

earnest phoenix
#

Show whole error

weary crypt
#

How fix ‘err’

earnest phoenix
#

bruh

spare badger
#

Guys what am I doing wrong at this line of code?

earnest phoenix
pale vessel
#

Stop acting like a clown

earnest phoenix
#

bruh

weary crypt
#

Show the whole error lol

earnest phoenix
#

its at terminal tho

#

Yup

earnest phoenix
#

show the whole error

spare badger
#

I have seen a terminal before

earnest phoenix
sudden geyser
#

There you go!

earnest phoenix
spare badger
#

What was the command you tried to run?

earnest phoenix
#

In your thing I Think Your python Version is outdated

#

Or something

#

And it Failed To Execute the Installation of whatever package

sudden geyser
#

The error doesn't tell enough at the moment

spare badger
#

What were you trying to do? Install NodeJS?

sudden geyser
#

It's just a disarray of 200s and 404s and failed to execute some script

earnest phoenix
#

I think he was trying to install a package from the registery

spare badger
#

@earnest phoenix Try running the install command for each package separately so you can see what package is failing.

earnest phoenix
#

ight

boreal iron
#

Does <member>.setNickname() change the username locally on the server only? Does the server remember that username after the client/bot left/joined again?

spare badger
#
npm install @discordjs/opus
npm install ffmpeg-static
npm install yt-search
npm install ytdl-core