#development

1 messages ยท Page 936 of 1

pale vessel
#

sorry if i sound annoyed

zenith terrace
pale vessel
#

#clientapplication ๐Ÿ‘€

#

copy pasted from url bar

zenith terrace
#

Mhm

pale vessel
#

same

#

mine's #collection lol

zenith terrace
#

Nice

#

:)

neat ingot
#

man, changing from v11 -> v12 has taken me so long already, still not finished ๐Ÿ˜

#

literally like a month and a half now ๐Ÿ˜

pale vessel
#

how?

sudden geyser
#

regex is your best friend

pale vessel
#

and enemy sometimes tbf

hoary elm
#

So I never really ask for help anymore but right now I need some I have a command

const Discord = require("discord.js");

const bot = new Discord.Client();

const snek = require('snekfetch');

exports.run = async (client, message, args) => {

const speech = args.join(' ');

if (speech.length < 2) return message.channel.send(`${message.author.username} You must supply text for Yoda. Yes.`);

const { text } = await snek.get(`http://yoda-api.appspot.com/api/v1/yodish?text=${encodeURIComponent(speech.toLowerCase())}`);

message.channel.send(JSON.parse(text).yodish).catch(console.error);

}

It's supposed to take the text provided and return it as Yoda text but it's having issues parsing the JSON response and I get a error ```at JSON.parse (<anonymous>)7:43 AM

Jump Toat Object.exports.run (/app/commands/yoda.js:8:31)7:43 AM

at processTicksAndRejections (internal/process/task_queues.js:86:5)7:43 AM

[FATAL] Possibly Unhandled Rejection at: Promise Promise {7:43 AM

<rejected> SyntaxError: Unexpected token u in JSON at position 07:43 AM

pale vessel
#

s n e k

#

we just went through this

hoary elm
#

Error is related to the website response, I have checked to make sure the site still works.

I have also attempted to use node-fetch

#

^

pale vessel
#

try to use node-fetch and i'll help you

#

or give the node-fetch code

hoary elm
#

I have code for it in node-fetch 1 sec

#
New Yoda CMD

const Discord = require("discord.js");
const bot = new Discord.Client();
const snek = require('node-fetch');

exports.run = async (client, message, args) => {

const speech = args.join(' ');

if (speech.length < 2) return message.channel.send(`${message.author.username} You must supply text for Yoda. Yes.`);

const text = await snek(`http://yoda-api.appspot.com/api/v1/yodish?text=${encodeURIComponent(speech.toLowerCase())}`)

.then(res => res.json()) // expecting a json response
.then(json => {
message.channel.send(JSON.parse(body).yodish).catch(console.error);
});
}
#

Error with that ^^ is text is not defined

pale vessel
#

why did you put it inside a constant

hoary elm
#

๐Ÿคฆ๐Ÿปโ€โ™‚๏ธ you know I had a feeling it was the const

pale vessel
#

remove const text =

#

actually

#

remove await too

#

because you use .then

hoary elm
#

So just ```text = ()``?

sudden geyser
#

also where do you define body

hoary elm
#

also where do you define body
@sudden geyser I don't I had that as text originally just changed it a few minutes ago

sudden geyser
#

Also why are you creating a new client at the top level of your file

#

ah

hoary elm
#

Yeah lol I'll change it back to text, thanks for your help guys ๐Ÿ˜‰

pale vessel
#

you don't need text = ()

#

simply ```js
snek(http://yoda-api.appspot.com/api/v1/yodish?text=${encodeURIComponent(speech.toLowerCase())})

.then(res => ...)```

hoary elm
#

Ahh okay makes sense

#

Thank you ๐Ÿ˜ and sorry still a bit new to node-fetch

pale vessel
#

you should change snek to fetch to avoid confusion

#

and code quality ig

hoary elm
#

Yeah I will do that lol it confuses me even

serene night
#

Hey guys I'm still having this error: ```
UnhandledPromiseRejectionWarning: Error: WHERE parameter "user_id" has invalid "undefined" value

#

and yet again this is my code:```js
const target = msg.mentions.users.first() || msg.author
const user = await Users.findOne({ where: { user_id: target.id } })
// Messed Up Code ^^^^^^^^^^^^^^^^^^^^^^
const items = await user.getItems()

#

i'm not sure what went wrong as when I console.log(target.id) it gave me my discord user id

warm marsh
#

Does the db have that user as an entry?

serene night
#

yes

#

I have another command called balance that gets the balance of the current user

#

and that command works like a charm

cold ivy
#

Can someone give me a solution for my bot running on discord.py turning off whenever my PC sleeps?

#

PM me please

warm marsh
#

Host it

serene night
#

@cold ivy pm2

cold ivy
#

on

#

what

warm marsh
#

VPS?

#

I've never worked with that database before so I've got no clue.

serene night
#

hmm

quartz kindle
#

@cold ivy your bot only works while your bot program is running, if the program stops running, so does the bot

serene night
#

well, thats why i said pm2

quartz kindle
#

pm2 wont help

serene night
#

pm2 has python2 and python3 support

#

and it works when my mac goes to sleep

quartz kindle
#

he said hes self-hosting and his pc sleeps

limber flume
#

@quartz kindle my bot has reached 75 servers and i have done verifiacation how long untill i get this dev

quartz kindle
#

mine took 3 weeks

limber flume
#

brUH

pale vessel
#

that's pretty fast

limber flume
#

why are u look so angry lul

cold ivy
#

do you have any free hosting solutions for discord.py

limber flume
#

heroku

#

is what i use its pretty good ๐Ÿ™‚

serene night
#

heroku is good but it can have frequent downtime when using a free account @cold ivy

limber flume
#

i have a free account and i never get downtime

#

its been 2 months and its easy , when i want to update my code i go to github and commit changes and 3 mins later its updated

serene night
#

hmm, i used heroku to host an owasp juice shop ctf and there was alot of downtime

cold ivy
#

as in down you mean it does not listen for commands?

limber flume
#

no heroku is perfect for me my bots always working

cold ivy
#

for you

limber flume
earnest phoenix
#

Heroku works fine tbh

serene night
#

i guess i'll try heroku

cold ivy
#

when it is down does it still listen for commands

serene night
#

no

earnest phoenix
#

No

#

Means your bot is also down

serene night
#

downtime means that the bot goes offline for a while

cold ivy
#

that wont work for me

pale vessel
#

your bot restarts every 24 hours

#

even on verified accounts

earnest phoenix
#

Unless you get the credit from github education pack

pale vessel
#

still no

earnest phoenix
#

Which only lasts for 2 years

pale vessel
#

it's dyno cycle

#

it has nothing to do with credits

earnest phoenix
#

Doesnt the hobby dyno

pale vessel
#

hobby might work differently

earnest phoenix
#

I'm pretty sure that's what it does

pale vessel
#

2 years is a long time though

earnest phoenix
#

Ye

pale vessel
#

i'm sure by that time you already have money to buy a vps

median siren
#

pm2 or tmux

serene night
#

has anyone worked with sequelize?

cinder patio
#

I have

serene night
#

cool

#

I need help with this error

#
UnhandledPromiseRejectionWarning: Error: WHERE parameter "user_id" has invalid "undefined" value
earnest phoenix
#

user_id is undefined

#

which it shouldnt be

serene night
#

and this is the code that I suspect is wrong is this:```js
const target = msg.mentions.users.first() || msg.author
const user = await Users.findOne({ where: { user_id: target.id } })
const items = await user.getItems()

earnest phoenix
#

you need to show us how you defined user_id

#

oh wait

#

yeah im stupid

serene night
#
module.exports = (sequelize, DataTypes) => {
  return sequelize.define('users', {
    user_id: {
      type: DataTypes.STRING,
      primaryKey: true,
    },
    balance: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      allowNull: false,
    },
  }, {
    timestamps: false,
  })
}
#

this is the Users model btw

cinder patio
#

can you console.log target

serene night
#

i can

earnest phoenix
#

that would be helpful with debugging

serene night
#

it gives me the Discord User object

earnest phoenix
#

then it should work

serene night
#

thats the problem

earnest phoenix
#

what exactly is Users

serene night
#

it's a sequelize model

earnest phoenix
#

Alright so its a database

serene night
#

yeah

earnest phoenix
#

hm

#

the onliest explanation i see is that sequelize fucked up somewhere

serene night
#

i have a file called avadb.sqlite which is the sqlite db for my bot

#

idk how sequelize fucked up

earnest phoenix
#

you can try annother db that bases on sqlite too

#

quick.db is pretty handy

serene night
#

hmm

#

ok i guess i can try migrating to quick.db

cinder patio
#

Doubt it's a problem from sequelize

earnest phoenix
#

@serene night you can try logging target.id too

#

if it works sequelize is broken

serene night
#

i still get an error

#

and i think that sequelize is actually broken

cinder patio
#

Are you sure the error is coming from that line? I think you are trying to set it to undefined

serene night
#

i'm sure that the error is coming from that line

#

It's showing a stack trace where the error origin is /Users/daydream/Developer/ava/commands/inventory.js

#

on line 13

#

column 57

#

well, i guess i'm gonna try quick.db

cinder patio
#

you are making a mistake

tight plinth
#

not really

#

quick.db is good

cinder patio
#

And probably has 1/10th of the features sequelize has

earnest phoenix
#

quick.db

cinder patio
#

features you are almost guaranteed to use

torn nebula
#

user_id has undefined value

#

your're finding value but not added any value to user_id

Set id value user_id then use findOne

unborn steeple
#

quick.db is useful but you can run into alot of errors if you dont know how to use it.

torn nebula
#

will starts with install error

unborn steeple
#

lol

peak venture
#

How would i sum the values inside

[ {
  value: 123
}{ 
value: 234
}]```
sudden geyser
#

iterate over the array and add up each .value

#

You can use <Array>.reduce for example.

peak venture
#

already doing a forloop

#

just wondering wether i did my reduce correctly?

#
TotalRating = ShipStore.reduce(
      (acc, currentRating) => {
        return acc + currentRating.total
      }
    );```
#

so in ShipStore.rating is the value i need

sudden geyser
#

did you try it? An example for the array you gave above: js arr.reduce((prev, val) => prev + val.value, 0); // The second argument is what the value at the start should be.

peak venture
#

ah so currentRating.total should be ShipStore.rating instead

lethal vine
#

hey question

#

how in python i check if a channel is nsfw or not

sudden geyser
#

currentRating is the current element in the array you're running. So whatever you want to add up should be off that.

#

cosmitir are you using discord.py because I think it's .nsfw on a channel

lethal vine
#

thx

peak venture
#

๐Ÿค”

#

the reducer just adds the numbers after one another 0145696720381386118823171148155014339901541

#

instead of like .f.e the last 2 are 990 and 1541

#
let TotalRating = ShipStore.reduce(
      (acc, val) => {
        return acc + val.yrating
      }, 0
    );
  console.log(TotalRating)```
earnest phoenix
#

I need help with addrole command

pale vessel
#

ask

#

just ask

earnest phoenix
#

Ok

#

I'm trying to do a addrole command but i have troubles to add the role to the member

silent berry
#

Hello. can someone tell me if there are any errors in this code

helium.on("message", async(msg) => {
    let chatmoderators = ['539195184357965833', '550170362248429568', '437019658374348801', '641795527444529152']
   if (msg.author.bot)return;
   if(msg.channel.name !== 'helium-global-chat')return;
   msg.delete()
   

   let e = new Discord.RichEmbed()
            .setTitle("Helium Global Chat")
            .setAuthor(msg.guild.name, msg.guild.iconURL)
            .addField("Message content", msg.content)
            .setColor("RANDOM")
            .setThumbnail(msg.author.avatarURL)
            .setTimestamp()
            .setFooter(`Helium Global Chat System || SECURITY | Guild id: ${msg.guild.id} | msg author id: ${msg.author.id} | code by Airbus A350-1000#0001. thanks to him, this bot will have a functioning global chat.`);

            if(chatmoderators.includes(msg.author.id)){
                e.addField("Sent By", `๐Ÿ› ๏ธ Chat Moderator | **__${msg.author.tag}__**`)
            }else{
                e.addField("Sent By", `**__${msg.author.tag}__**`)
            }
        await Promise.all(helium.channels.filter(c => c.name === 'helium-global-chat').map(c => c.send(e))) 

        await Promise.all(helium.channels.filter(c => c.name === 'helium-global-chat').map(c => c.setTopic(`Last message is sent by <@${msg.author.id}>`))) 
  
        


        gcauthor = msg.author.tag
        gcauthorid = msg.author.id
        gccontent = msg.content
        
        


})
#

discord.js v11.5.1

earnest phoenix
#

i define the target as message.users.mentions.first() and then if i want to use target.roles.add(specific role) it doesn't work, i get that error
Cannot read property 'add' of undefined

pale vessel
#

roles doesn't exist

#

or target

earnest phoenix
#

it is

lethal vine
#

in php i can use !()

#

in python meh idk

#

while i wait gotta search google

modest maple
#

php ๐Ÿคข

earnest phoenix
#
 let rMember = message.mentions.users.first();
 var rrole = message.mentions.roles.first();

rMember.role.add(rrole.id);

@pale vessel

pale vessel
#

chill

lethal vine
pale vessel
#

why do some people hate php

modest maple
#

channel.nsfw

lethal vine
#

ik that

#

i did that

#

but

#

i need it to return the reverse value

modest maple
#

not

lethal vine
#

like is nsfw is returning true

#

ohhhhhhhhhhhh

#

it makes sense

#

thx love

#

no homo

pale vessel
#

chill what's wrong with php

#

i need to know

lethal vine
#

idk

earnest phoenix
#

@pale vessel help ?

pale vessel
#

hold on

#

i kind of in need of an answer myself

#

@modest maple

modest maple
#

outdated, Outa love, outa luck

pale vessel
#

all right

#

i now got my answer

modest maple
#

better system exist which just out do php

pale vessel
#

i like php tho ngl

severe quarry
#

.

quartz kindle
#
  1. PHP encourages an insecure programming style by design
  2. The language is a minefield of hidden security problems.
  3. The documentation is full of harmful advice.
  4. PHP created by coders who never understood - value of time, business processes, ROI, etc. Most common use for code is in business world; PHP does not understand how IT works efficiently in a business world; it is for geeks only.
  5. It took years for PHP to support Unicode, which has been a requirement for business solutions for years. Does it do that well now?
  6. Inconsistent code, libraries, frameworks, reminds me of antique shops (mix of crap, mediocre stuff, unrelated items thrown together, with the odd useful item).
honest perch
#

dont dot post @severe quarry

quartz kindle
#

just examples i found from a simple google search

severe quarry
#

Gbx dllm @honest perch

honest perch
#

huh?

pale vessel
#

no wonder wp is insecure af

#

wp itself is a bunch of patched old PHP code

honest perch
#

bots auto do /wp-login on domains

pale vessel
#

and md5

quartz kindle
#

the reason i quit wordpress was precisely that

#

if you dont update it constantly, your website will be hacked

#

one of mine was

#

lmao

pale vessel
#

i'm a moderator on a web hosting service and many people either get suspended due to hacked wp installation or high load

#

what a pain

quartz kindle
#

rip

#

i searched "why is php hated"

#

and one of the top answers basically says "it used to be bad, but now javascript is way worse"

#

lmao

pale vessel
#

nice

quartz kindle
#

At one time, PHP, JavaScript, and C++ were considered the worst programming languages in the world. However, in December of 2015, PHP 7 was released. This version made breaking changes in order to substantially improve the language.

Consequently, PHP is no longer as awful as it used to be. By comparison, JavaScript has NOT made breaking changes, and it likely NEVER WILL.

Instead, ECMA TC39 have chosen to put a Band-Aid on JavaScript and pile on new feature after new feature in the hope that they can make you forget how execrable the language truly is. The result? Look at ECMAScript 2017: its language spec is a whopping 885 pages long!

JavaScript is now one of the most bloated programming languages in the world.

pale vessel
#

everything is bad huh

honest perch
pale vessel
#

and rerouting it won't make it any more secure

#

wp should be dead

modest maple
#

PHP Database manager for example

#

even if you escape inputs with it

pale vessel
#

what's that

#

pma?

modest maple
#

even if you escape inputs to prevent injection attacks

#

it will still execute them on the way out

quartz kindle
#

afaik PDO has prepared statements

modest maple
#

One of the biggest fuck ups i ever remember

pale vessel
#

it does

quartz kindle
#

PDO should be the standard database library when using php

modest maple
#

was the string escaping that still got injection attacked just when it fetched the data instead๐Ÿคฆโ€โ™‚๏ธ

quartz kindle
#

rip

ruby talon
quartz kindle
#

wat

ruby talon
#

yes

#

insane right

quartz kindle
#

why did you hve to enter that manually?

slender thistle
#

... what is that

pale vessel
#

what's that for

ruby talon
#

Bcs we received it manually

modest maple
#

but

ruby talon
#

like

quartz kindle
#

manually how?

ruby talon
#

the values

pale vessel
#

that doesn't look manual

modest maple
#

wtf was stopping u from just making a script to load it

#

lmao

quartz kindle
#

^

pale vessel
#

effort 100

modest maple
#

that just looks like binary

ruby talon
#

I created a little scripty to remove the tabs and add the ,'s

#

But still

modest maple
#

bruhhh

#

bruh

ruby talon
#

a shit load of work

quartz kindle
#

how was the original data formatted?

ruby talon
#

2sec

#

lemme send

#

Could've probb indeed done it easier with a script

modest maple
#

bruh

quartz kindle
#

oh jesus

ruby talon
#

but oh well, its done now

modest maple
#

they sent u a fucking dataframe

ruby talon
#

You know what the worst part is?

#

Its fucking simulation data

#

Like why does it have to BE THE SAME

modest maple
#

legit

#

would of just removed any alpha characters

ruby talon
#

Just lemme gen 1's and 0r;s

modest maple
#

replaces tab with ""

#

List that

#

chunk

#

dict

ruby talon
#

ig

modest maple
#

maybe like 20 lines of code in py?

ruby talon
#

well, 2 late now

modest maple
#

and like 5 mins lol

ruby talon
#

I have smol brain ya kno

nocturne grove
#

Hey. I've got a difficult question. What to do when my database gives an error while it wants to insert/update something that wasn't caused by a user executing a command? I don't hope to come across those errors, but I guess they can happen

ruby talon
#

Might wanna give the error ๐Ÿ™‚

marble canyon
#

s

silent berry
#

Hello. can someone tell me if there are any errors in this code

helium.on("message", async(msg) => {
    let chatmoderators = ['539195184357965833', '550170362248429568', '437019658374348801', '641795527444529152']
   if (msg.author.bot)return;
   if(msg.channel.name !== 'helium-global-chat')return;
   msg.delete()
   

   let e = new Discord.RichEmbed()
            .setTitle("Helium Global Chat")
            .setAuthor(msg.guild.name, msg.guild.iconURL)
            .addField("Message content", msg.content)
            .setColor("RANDOM")
            .setThumbnail(msg.author.avatarURL)
            .setTimestamp()
            .setFooter(`Helium Global Chat System || SECURITY | Guild id: ${msg.guild.id} | msg author id: ${msg.author.id} | code by Airbus A350-1000#0001. thanks to him, this bot will have a functioning global chat.`);

            if(chatmoderators.includes(msg.author.id)){
                e.addField("Sent By", `๐Ÿ› ๏ธ Chat Moderator | **__${msg.author.tag}__**`)
            }else{
                e.addField("Sent By", `**__${msg.author.tag}__**`)
            }
        await Promise.all(helium.channels.filter(c => c.name === 'helium-global-chat').map(c => c.send(e))) 

        await Promise.all(helium.channels.filter(c => c.name === 'helium-global-chat').map(c => c.setTopic(`Last message is sent by <@${msg.author.id}>`))) 
  
        


        gcauthor = msg.author.tag
        gcauthorid = msg.author.id
        gccontent = msg.content
        
        


})
ruby talon
#

Run and see

pale vessel
#

ah yes, we're bots that read your code and tell you what the problem is

silent berry
#

i have and one thing

earnest phoenix
#

whats the error?

silent berry
#
(node:44) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
at /home/container/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15
at /home/container/node_modules/snekfetch/src/index.js:215:21
at processTicksAndRejections (internal/process/task_queues.js:97:5)```
#

idk why i get it tho

quartz kindle
#

@ruby talon you could have done something like this

ruby talon
#

Ye should've

#

rips

nocturne grove
#

Might wanna give the error ๐Ÿ™‚
@ruby talon give the error? Wdym?

ruby talon
#

Hey. I've got a difficult question. What to do when my database gives an error while it wants to insert/update something that wasn't caused by a user executing a command? I don't hope to come across those errors, but I guess they can happen
@nocturne grove doesn't an error occur?
Or do you mean what if? If so, just don't let your users make them, add checks. You should always be in control of the execution or sql injection will probb occur.

nocturne grove
#

Of course I check their whole input, I replace all things needed etc. But I meant errors like connection stuff

ruby talon
#

Shouldn't raise an error on the DB side

silent berry
#

@earnest phoenix did you see the error?

quartz kindle
#

@silent berry that error means the message was not found, the only way i see it happening in that code is if you delete it somewhere else, which causes your msg.delete() to not find it

silent berry
#

ok

#

what would cause it to repeat the message to repeat its self where if i type one thing in the channel. it spams it.

ruby talon
#

@nocturne grove if any connection exceptions occur this will be on the side that send the request as the DB can't respond or receive anything

nocturne grove
#

Shouldn't raise an error on the DB side
@ruby talon ?

I can just get an error that prevents my bot from inserting data, right?

silent berry
#

there is bot protc on

quartz kindle
#

do you have other .on("message") blocks?

silent berry
#

yes

ruby talon
#

@nocturne grove Yes, if you are using a custom library you should add the checks yourself.
Else all exceptions should be build in and easy to handle for the script.

quartz kindle
#

@nocturne grove database libraries check these kinds of errors for you and give you back an error for you to handle

#

which database library are you using?

silent berry
#

djs v11.5.1

nocturne grove
#

yes I understand, but what to do if an error occured when the stuff needs to happen? Wait I'll explain

earnest phoenix
#
let rMember = message.mentions.users.first();
  var rrole = message.mentions.roles.first();
  rMember.roles.add(rrole.id)

err

Cannot read property 'add' of undefined
quartz kindle
#

you collect the error and log it somewhere, then show something to the user

#

rMember is not a member

ruby talon
#

If the DB server should be up might wanna retry

quartz kindle
#

mentions.users gives you a User, not a Member

ruby talon
#

:))

earnest phoenix
#

@quartz kindle and what should i do ?

quartz kindle
#

mentions.members

earnest phoenix
#

ok

#

ty

nocturne grove
#

On startup of my bot, it's going to send a log, check some if his permissions and start up his counters (see if anything changed)
When an error occured at the start up counters part, some strange things can happen in the whole uptime of the bot.
(Hmm I now realise I can work around that maybe)

#

I know this explanation is really vague

modest maple
#

yo @quartz kindle You are mc JS dude yes?

quartz kindle
#

mc?

ruby talon
#

Why track the uptime through a DB tho

modest maple
#

setTimeout(scaleUp, 500)

#

how can i pass args through setTimeout?

quartz kindle
#

() => scaleUp(args)

modest maple
#

?

quartz kindle
#

you want to give args to the scaleUp function, correct?

#

do you want to hardcode them? or do you want the timeout to call a method in a class? or something else?

nocturne grove
#

Why track the uptime through a DB tho
@ruby talon you probably read that because of my vague explanation xd

I meant stuff can go wrong for the entire time the bot is online, until it goes offline

modest maple
#

they're varibles

#

i worked it out

#

ty

cinder patio
#

I believe the third param for setTimeout/Intervals are the args

ruby talon
#

Ohh

#

@nocturne grove are you using cogs? (Just for info if my answer will be relevant)

#

'R what lang are you using?

nocturne grove
#

never heard of cogs in this context, so I guess no

ruby talon
#

@nocturne grove are you using javascript?

earnest phoenix
#
let banEmbed = new Discord.MessageEmbed()
    .setDescription("**Ban**")
    .setColor("#660213")
    .addField("Banned User", `${bUser}`)
    .addField("Banned User ID", `${bUser.id}`)
    .addField("Mod", `<@${message.author.id}>`)
    .addField("Mod ID", `${message.author.id}`)
    .addField("Banned on", message.channel)
    .addField("Date", message.createdAt)
    .addField("Reason", `${bReason}`);

error:

MessageEmbed field values may not be empty.

Why i get this if there isn't an empty field?

ruby talon
#

On your bot.

nocturne grove
#

@ruby talon yes, with mysql as database

ruby talon
#

Ait

earnest phoenix
#

@earnest phoenix inspect your variables, one of them returns nothing probably

ruby talon
#

I would assume you have to load the commands in when starting and that your code has a DB object which then executes all commands on the db?

nocturne grove
#

@earnest phoenix message.channel is an object, use it like ${message.channel} to get the mention. Or message.channel.toString() I believe

#

yes I have

earnest phoenix
#

@nocturne grove i tried in both ways bot i still got the error

ruby talon
#

If so add a test check at the start (see it as a ping), if you get an expected result switch a check var. If it failes retry but block the commands that depend on it

earnest phoenix
#

i told you to inspect your variables

#

you'll achieve nothing by guessing what's the issue

ruby talon
#

This way your script shouldn't be able to "crash"

quartz kindle
#

@earnest phoenix console.log(banEmbed.toJSON())

#

and you will see in your console which field is empty

ruby talon
#

Or atleast thats the way I would handle it in your situation.

nocturne grove
#

@ruby talon on startup, it's now already saying database connected after the, I believe, first query. So you suggest when that's not logging, I know the connection is not stable.
Hmm sounds logical, thanks

ruby talon
#

^^

nocturne grove
#

and tbh, I don't think I should go too far with it. Because now I'm thinking "what if something else's happening in one of the following queries"... ๐Ÿ˜…

earnest phoenix
#

i hope you're not using a single connection for all of your queries

quartz kindle
#

check your mysql library's docs, it should mention how to catch any error that happens

#

if your connection is unstable because you have a remote database, look into mysql pooling libraries

ruby talon
#

@nocturne grove idk how it works on JS but in python I would let my command class inherit my error handler class and catch the errors

nocturne grove
#

i hope you're not using a single connection for all of your queries
@earnest phoenix Last week I put all my queries in one file, so it will always make a new connection and close it. Thanks you was one of them who said that ๐Ÿ˜‰

Thanks for that

ruby talon
#

@quartz kindle do you prefer PostgreSQL or MySQL?

nocturne grove
#

ok will check that Tim thanks

#

hmm that sounds complex Arthur haha

ruby talon
#

Really isn't x)

nocturne grove
#

hmm

#

Tim knows how complex my code is ๐Ÿ˜‚

ruby talon
#

Well, the best of luck tho

nocturne grove
#

thanks for the help

ruby talon
#

Any time

quartz kindle
#

I use SQLite for my bots

nocturne grove
#

will look into the docs I guess, and else I will just rely on the connection ๐Ÿ™‚

quartz kindle
#

havent used Postgre yet, and use MySQL for my website

modest maple
#

Use postgres over MySQL

ruby talon
#

Ait, I used 2 use SQLite too, but for my next project is pretty big so I think a postgreSQL server fits more

#

& glad 2 work with new things

digital ibex
#

hi, how can i check if 75% of the messages a member sends are in caps?

#

like "EEEEEE" is all caps and ^^ would return true

#

using js

turbid bough
#

regex

#

A-Z

ruby talon
#

Damn

#

thats smart @turbid bough

digital ibex
#

so i can do something like

ruby talon
#

I really gotta learn how 2 work with regex, bcs kinds looks like enchanting table language

modern token
#

helllo

modest maple
#

hmm

if (typeof (block) !== "undefined") {
    lastBlock.classList.add("hidden")
}```
modern token
#

How do I go higher then the set kbps

modest maple
#

you cant

modern token
#

Whats with the chat names then

#

384

modest maple
#

its set to that

digital ibex
#

ok, idk how i'd do it

modest maple
#

its a 3 level boosted server

modern token
#

OH

digital ibex
#

imma go to regex101

modest maple
#

we get upto 384kbps audiop

modern token
#

So I need to boost

ruby talon
#

Channel settings and change the slider

modern token
#

Got yah

modest maple
#

Note to self: dont forget to use the right var other wise u will never get it going lol

ruby talon
#

Do I smell some html dev

#

Smells delicious

turbid bough
#

html code drooling

modest maple
#

I fucking hate front end

#

yet still do it ๐Ÿ˜ซ

ruby talon
#

I like frontend untill a UI designer comes and says that its hella shit

#

Backend is more my thing tho

earnest phoenix
#
message.guild.fetchBans().then(bans => {
    if (bans.some(u => User.includes(u.username))) {
      let user = bans.find(user => user.username === User);

      message.guild.members.unban(user.id, Reason);
    } else if (bans.some(u => User.includes(u.id))) {
      message.guild.members.unban(User.id);
    } else {
      message.channel.send(nue)

error

Cannot read property 'includes' of undefined

ruby talon
#

Frontend is easy 2 do but hard to make good

#

User object doesn't excist @earnest phoenix

#

Read ur error

#

Literally says it fam

earnest phoenix
#

i defined it already

#

i mention

#

i did everything

ruby talon
#

Probb gotta remove the cap on the U

#

I think User is the User oject and not the member object you want

modest maple
earnest phoenix
#

let User = message.mentions.members.first()

modest maple
#

still a little janky

ruby talon
#

Dang

modest maple
#

but it switches slides niceeeeee

ruby talon
#

anime watch stats

#

hit me up when its ready, I need 2 see my addiction

modest maple
#

ignore the domain

#

just had it laying around

ruby talon
#

Nice fam

#

Disable this border thingie tho

#

๐Ÿ˜ฆ

turbid bough
earnest phoenix
#

can someone help me please?

ruby talon
#

@earnest phoenix we can, if you give us some information

#

Eg, error, code, expected result ect

quartz kindle
#

from the code you showed, all we can see is that User is undefined

modest maple
#

@turbid bough fuck you found my 404 i forgot about

earnest phoenix
#

Wait. i'll give you the full code

quartz kindle
#

thats a 404 page? lmao

modest maple
#

well

#

you see

ruby talon
#

HAhahah

modest maple
#

i started making it

#

then basically went "fuck my life im going back to py"

quartz kindle
#

weeb

modest maple
#

then got yelled at by teacher for not doing some work --

ruby talon
#

Yell back

modest maple
#

even tho they just didnt read their emails

sudden geyser
#

Anime is power.

modest maple
#

Im only like 15% done anyway lol

#

but its going alright

earnest phoenix
#

ignore

#

that richembed

quartz kindle
#

you need to return in those ifs

#

else they will send a message saying that you dont have permissions, or that the user was not found, but the code will continue anyway

earnest phoenix
#

oh, ok

magic jackal
#

Yo, is there a way to profile my code?

#

Like suggestions on where to change things or what to do with high intensity sections?

quartz kindle
#

you mean execution speed?

lethal vine
#

so i used this

quartz kindle
#

in js you can time your functions with performance.now() to get an execution time reading

lethal vine
#

and it output me invalid number given

turbid bough
#

@modest maple is it just a website, or a website for a bot?

quartz kindle
#

otherwise you can also use one of the many profiling and heatmap libraries

lethal vine
magic jackal
#

@quartz kindle Perhaps, I'm just trying to see what I should change beacuse I want to restructure things again

#

kinda getting spaghetti

modest maple
#

@lethal vine are you trying to check if a string is a number?

#

if so

#

string.isdigit()

quartz kindle
#

if you want, you can show your hot code

lethal vine
#

im trying to check if argument is a number

#

yes

#

thx

magic jackal
#

I'm trying to make an efficient reload command too

earnest phoenix
#

Tim, i still got the error

modest maple
#

@modest maple is it just a website, or a website for a bot?
@turbid bough Just a site tho i intend to make the API public and access some stuff from my bot

magic jackal
#

@quartz kindle

#

it aint pretty but its working fine more or less

turbid bough
#

add me to the open beta then

quartz kindle
#

i mean, nothing i can say about that part, performance is pretty irrelevant at that point

#

i would do things a bit different but thats just personal preference

digital ibex
#

how can i check if a user has used a command in under 10 seconds?

#

like

#

i use 5 commands in under 5 seconds, how can i check it?

#

using javascript

turbid bough
#

read the docs

quartz kindle
#

you can use timers and intervals

digital ibex
#

nothing will be in the docs about that

turbid bough
#

js?

digital ibex
#

what can i check for though?

#

yes

quartz kindle
#

for example

jovial nexus
#

TypeError: args.replace is not a function

quartz kindle
#

create an object and an interval of 5 seconds

quartz kindle
#

every time a user uses a command, put the user in the object, and add a command counter

#

make the interval reset the counter every 5 secs

#

another way is to add a counter somewhere when a user uses a command, and set a timeout to remove said counter

#

the counters will keep themselves updated, and you can arbitrarily check their size at any given point

digital ibex
#

oki, thank u

#

what i'm doing has got nothing to do with doing anything with cooldowns

#

or d.js

#

only the js part of it

modest maple
#

how would i be able to temporarily suspend a function for x amount of ms (400)

quartz kindle
#

in js?

modest maple
#

yh

turbid bough
#

@digital ibex uuuh, wdym

modest maple
#

if i add a timeOut on the hide function

#

it will continue

quartz kindle
#

await new Promise(r => setTimeout(() => r(), 400))

modest maple
#

ooh

digital ibex
#

i'm trying to check if a user has used x amount of commands within n seconds

quartz kindle
#

@jovial nexus args.replace is not a function

#

check your args, they are either wrong or invalid

#

cant help without seeing your code

jovial nexus
#
    run: async(client, message, args) => {
        const url = args.replace(/<(.+)>/g, '$1')
turbid bough
#

um, args is an array isnt it?

modest maple
#

@quartz kindle How is that gonna work with button events tho?

jovial nexus
#

yu

turbid bough
#

i dont think arrays have replace function

jovial nexus
#

wait

#

it isnt

turbid bough
#

it isnt?

jovial nexus
#

nope

real helm
#

-bot

turbid bough
#

u sure?

#

cause "args" are usually named as an array

#

hence, the s

digital ibex
#

u can join the args and then replace it

quartz kindle
#

@jovial nexus how do you call the run function?

#

you're passing invalid args to it

#

@modest maple button events?

jovial nexus
#

do you mean this? ```js
commands.run(client, message, args);

quartz kindle
#

yes

#

how did you define args?

modest maple
#

The hide function is being invoked by a onClick() event

quartz kindle
#

are you using jquery?

modest maple
#

nop

quartz kindle
#

are you doing something like transitioning the opacity before setting the element to display:none?

modest maple
#

yh

jovial nexus
#
      const args = message.content.slice(prefix.lenght).trim().split(/ +/g);
modest maple
#

300ms from 100% -> 0%

#

then hide

#

but obs atm its hiding long before it gets to 0%

quartz kindle
#

you should be able to setTimeout(() => element.style.display = "none", 300)

#

or something

turbid bough
#

yeah split turns string into array

quartz kindle
#

@jovial nexus so args is an array

#

arrays dont have a .replace function

#

only strings do

jovial nexus
#

then i need to replace args?

turbid bough
#

no?

#

args[0]

#

if you are inserting an url in a command

quartz kindle
#

args is an array of words, for example if the person types command bla1 bla2 bla3 then args is [bla1,bla2,bla3]

#

if you want to execute the .replace function on the first argument, ie the first word the user writes after the command

#

do it to args[0]

jovial nexus
#
 run: async(client, message, args) => {
        const url = args[0].replace(/<(.+)>/g, '$1')
```?
quartz kindle
#

if you want to execute the replace function on all args, all words the user types, no matter the order

turbid bough
#

yes probably

quartz kindle
#

then use args.map(word => word.replace())

#

yes, you probably want the args[0] method

jovial nexus
#

TypeError: Cannot read property 'replace' of undefined

turbid bough
#

there are no args in your command then

jovial nexus
#

aaa

quartz kindle
#

did you type an url in your command?

jovial nexus
#

ok thx now works

modest maple
#

tim i worked out an easier way

#

i just passed the var to the func

#

and then assigned the old var after

#

fuck im dumb some times

earnest phoenix
#
 let User = message.mentions.members.first();

if(message.author.id === User.id) {
    const nupoti = new Discord.MessageEmbed()
    .setDescription(":no_entry_sign: **You can't ban yourself!**")
    .setColor("#ff9900");
    
    message.channel.send(nupoti);
    
    return;
  }

Cannot read property 'id' of undefined

quartz kindle
#

did you mention someone?

earnest phoenix
#

yes

turbid bough
#

is message.author undefined?

earnest phoenix
#

no

turbid bough
#

is User undefined?

earnest phoenix
#

i defined it, don't you see?

turbid bough
#

the error says it otherwise though

earnest phoenix
#

nvm. i solved it but i have another problem now

turbid bough
#

good

earnest phoenix
#
let User = message.mentions.members.first();
  let Reason = args.slice(1).join(` `);
  
  if (!User) {
    const mentioneaza = new Discord.MessageEmbed()
    .setDescription(":no_entry_sign: **You need to mention a person to unban!**")
    .addField("Correct Usage", "lt!unban [userMention/userID]")
    .setColor('#ff9900');
    
    message.channel.send(mentioneaza);
    
    return;
  }
  if (!Reason) Reason = `Unbanned by ${message.author.tag}`;

  message.guild.fetchBans().then(bans => {
    if (!bans.some(u => User.includes(u.username))) {
      let user = bans.find(user => user.username === User);

      message.guild.members.unban(user.id, Reason);
    } else if (!bans.some(u => User.includes(u.id))) {
      message.guild.members.unban(User.id);
      let banEmbed = new Discord.MessageEmbed()
    .setDescription("**Unban**")
    .setColor("#ff9900")
    .addField("Unbanned User", `${User}`)
    .addField("Unbanned User ID", `${User.id}`)
    .addField("Mod", `<@${message.author.id}>`)
    .addField("Mod ID", `${message.author.id}`)
    .addField("Unbanned on", `${message.channel}`)
    .addField("Date", `${message.createdAt}`)
    .addField("Reason", `${Reason}`);
      
    } else {
      
      const nue =  new Discord.MessageEmbed()
      .setDescription(":no_entry_sign: **That person isn't banned**")
      .setColor('#ff9900');
      
      message.channel.send(nue)
      
      return;
    }

when i use my unban command i still got the message that i don't mention anyone

turbid bough
#

cause when you unban someone, they arnt a member

#

they are a user

earnest phoenix
#

oohh

#

sure

turbid bough
#

so you need to look trough .users instead of .members

earnest phoenix
#

yes

#

i still get that i haven't mention anyone

turbid bough
#

what does your message look when you are sending that command?

earnest phoenix
turbid bough
#

can you try console.log it out, and or try to explicit say that you are comparing with undefined

#

if(User === undefined) ?

earnest phoenix
#

sure

#

if i do console.log i got only undefined in the console

#

not User.includes

#

@earnest phoenix then what?

#

@turbid bough any idea?

turbid bough
#

im not sure, but can you check if oyu print the whole list of users mentioned?

earnest phoenix
#

Excuse me? cand you explain me one more time ?

earnest phoenix
#
Couldn't resolve the user ID to unban.
const banList = await message.guild.fetchBans();

  const bannedUser = banList.find(user => user.id === User.id);

  if (bannedUser) message.guild.members.unban(bannedUser, Reason);
  else await message.channel.send(nue);
faint token
#

How to check if the bot has the correct permission to make a invite link
I try client.guild.me.hasPermission("CREATE_INSTANT_INVITE")
but it failed

sudden geyser
#

client.guild is not a property.

smoky spire
#

@earnest phoenix fetchBans doesn't return a collection of users

faint token
#

oh ok

earnest phoenix
#

@smoky spire then how could i check if a member is banned?

smoky spire
#

It passes a collection of objects that have a user property

pine bear
#

can you add slowmode to a command handler, I just want a yes or no answer.

smoky spire
#

yes

pine bear
#

ok thx

faint token
#

guild.me.hasPermission("CREATE_INSTANT_INVITE")

guild not defined?

Do i need to define the guild id?

crisp geyser
#

You need to define guild object, example: message.guild or client.guilds.cache.get(id)

#

By the way, does someone know how long does it take to have an answer from auction requests?

modest maple
#

monthss

crisp geyser
#

Oh that is sad, why so long?

faint token
#
let guild = message.guild;
console.log(guild.me.hasPermission("CREATE_INSTANT_INVITE"));

This report true even through the bot does not have permission?

nocturne grove
#

@faint token its safer to check for channel overrides, as an invite can only be made to a channel

#

Oh I just said the reason for that xd

faint token
#

ok

timid blade
#

I am reworking permission management for my bot, and i am getting an error (will attach in a sec) on this code. The console.log work fine and show the correct permissions but it crashes on the third line

#

im stumped

fiery stream
#
Ignoring exception in on_command_error
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\discord\client.py", line 312, in _run_event        
    await coro(*args, **kwargs)
  File "C:\Users\Jassm\Desktop\Alpha\modules\core\error.py", line 18, in on_command_error
    ctx._ = functools.partial(ctx._, cog="ErrorHandler")
AttributeError: 'Context' object has no attribute '_'```
#

help

sudden geyser
#

(Movement) Are you really sure it's coming from that line (shard.js 92:53)? You're also checking if a a guild member has administrator in the channel (still works)

fiery stream
#

        ctx._ = functools.partial(ctx._, cog="ErrorHandler")
        error = getattr(error, 'original', error)
        etype = type(error)
``` thats my code
timid blade
#

ye it is coming from shard.js 92:53, just figured out that the number im passing was a string and it doesnt like passing '8' instead of 8.

sudden geyser
#

ah

timid blade
#

should have something about that in the docs for discord.js

#

they just say u can pass a string number or flag

#

not that u can pass a number (bitfield) or string (flag)

sudden geyser
#

I mean it kind of does:

  • A string (see Permissions.FLAGS)
  • A permission number
  • An instance of Permissions
  • An Array of PermissionResolvable
timid blade
#

eh in hindsight that is a bit more clear, but most of discord.js it accepts strings instead of numbers because of snowflakes, so nobody would expect it to be different there so would be nice for a bit more clarity

dusty onyx
#

yo, what would be an appropriate pythonic way for stopping midway through a command, but not stopping the script or anything else?

slender thistle
#

return probably?

true ravine
dusty onyx
#

that didnโ€™t work for me

#

`await asyncio.sleep(5)
await message.channel.send("GO to continue NO to cancel")

def check(m):
    if m.content == 'GO':
        return m.content == 'GO' and m.channel == message.channel
    elif m.content == 'NO':
        global game_on_
        game_on_ = False
        react_set.clear()
        ultimates.clear()
        return`
#

this is what i have

#

after NO id like it to exit from the command

earnest phoenix
#

why this dont work?

client.users.get('507367752391196682').fetchMessage('688052360915845173')
  .then(message => console.log(message.content))
  .catch(console.error);```
#
TypeError: client.users.get(...).fetchMessage is not a function

faint token
#

you are fetching a message, it would not use a users

magic jackal
#

is there any way to shorten this function for the args I pass into the function

client.resource.cmdUsedLogger(client, command, commandArgs, msg)

#

Can't I just use an underscore?

earnest phoenix
#

@earnest phoenix client.users.get !?

#

@earnest phoenix yes(?

#

this dont work with users?

#

no

green vale
#

@earnest phoenix What version of DJS do you have?

#

v11 uses client.users.get while v12 uses client.users.cache.get

earnest phoenix
#

v11

#

@green vale ^^

green vale
#

Yeah client.users.get should work

wise quartz
#

How can i make a dashboard for my bot?

#

Basically interact with its database from a website.

#

Like disable and enable commands

clear island
#

Is there a way to know if the message is from the server where the message was sent?

earnest phoenix
#

@wise quartz you need to familiarize yourself with web development, look into these topics: frontend, backend, authentication, oauth2

#

how do i define what a command is in the default help command?

#

the whole "creating a dashboard" thing is too complicated to explain and too big of a concept so you'll have to research the topics yourself

wise quartz
#

Frontend, backend, authentication and oauth2?

earnest phoenix
#

yup

wise quartz
#

Is there yt tutorials for those?

sudden geyser
#

your error is your scope

earnest phoenix
#

don't seek for youtube tutorials

#

do actual proper research

unique nimbus
#

YouTube Tutorials just gives you the code

#

but doesn't tell you what they do

wise quartz
#

So where exactly should i be searching and search for what exactly?

earnest phoenix
#

i used a youtube tutorial it told me what the code does

#

google and the topics i said

wise quartz
#

Alr.

#

Gonna look into it

sudden geyser
#
green vale
#

I'm working on a commands "marketplace" of sorts with my Discord bot. I'm using JSON for information. Some JSON properly returns, but some values return as undefined. What should I do?

modest maple
#

use a db

green vale
#

I did consider a db, but I want to do it in a format that's similar to package.json

sudden geyser
#

Try it out and see.

earnest phoenix
#

I did consider a db, but I want to do it in a format that's similar to package.json
why though?

green vale
#

So like the way that my "marketplace" would work is that people could submit custom "packages" (command packs), and they can put info about the commands and the name and description in a JSON file that's similar to package.json

earnest phoenix
#

that's

#

a really bad idea

green vale
#

in the sense of safety?

earnest phoenix
#

yeah

green vale
#

Oh no I check that

earnest phoenix
#

oh

green vale
#

I'm going to manually check each package because it's dangerous if I don't obviously

earnest phoenix
#

i mean, unless you're reading the json file incorrectly, there's no reason that properties return undefined if they're there

sudden geyser
#

it's not for me I'm a python developer it's for a friend so i don't know js too much and i don't have access to the bot.
So ask them to try it out? The statement works but it's better if one is able to debug themselves.

green vale
#

Yea there shuldn't be anything wrong with the code

earnest phoenix
#

if nothing works at all, you can try switching to ini or yaml

green vale
#

I was thinking of that

#

Wait how can I read yaml/ini in JS?

#

(w/o npm packages)

earnest phoenix
#

you'll have to build your own reader

green vale
#

Oh

#

I could use js-yaml or something like that

earnest phoenix
#

json is a javascript native
JavaScript Notation Object
so for everything else you'll have to either build your own reader or use a npm package

#

i don't know which one is the most performant since i don't mess around with node too much

green vale
#

hm alright

sudden geyser
#

I assume they're using Discord.js. Are they on v11 or v12.

green vale
#

Or they're sharding?

#

I mean that's another possibility

earnest phoenix
#

in v12 the guilds property changed types

sudden geyser
#

ah then read what cry said.

earnest phoenix
#

see above

sudden geyser
green vale
#

Using yaml fixed my problem. Thanks so much!!

fiery stream
#

anybody know what did this got changed into

#
    "name",```
#

it gived me error on find

#

gives

earnest phoenix
#

are you on v12

fiery stream
#

yes

earnest phoenix
#

the channels property changed types

fiery stream
#

ohk

fiery stream
#
    "name",
    client.settings.get(message.guild.id).modLogChannel
  );``` u mean that?
earnest phoenix
#

uh no

#

look at the docs to see an example of how find is used now

#

click on the Collection thingy on the second link i provided

wanton sail
#

Help, why my bot isnt applied? I waited 2 weeks, the bot is off rn because I am working to pokemon commands, but it was on 2 weeks

#

(Ping)

earnest phoenix
#

be patient

wanton sail
#

Ok

astral yoke
#

okay so howcome

#

in this

#
  let welcome = bot.db.get(`welcome_${member.guild.id}`)
  if(welcome === null) {
    return;
  };
      const embed = new RichEmbed()
 .setAuthor(`Someone joined! it was **${member}#${member.discriminator}**`, member.displayAvatarURL)
        .setThumbnail(member.displayAvatarURL)
        .setColor('RED')
        .setTimestamp()
        .setTitle("**DELETED MESSAGE**")
      .setDescription(`Someone Joined!
        **User**: ${member.username}#${member.discriminator}
        **Have fun!**`);
  bot.channels.get(welcome).send(embed);
});```
#

it shows undefined

#

but then if you do it as a text

#

in the bot.channels.get(welcome).send(`new member arriving it was ${member}`)

#

it actually pings him

#

but then in the embed

#

it shows <@id>

earnest phoenix
#

nothing you can do

astral yoke
#

and its mostly undefined

earnest phoenix
#

oh

#

oh god

astral yoke
#

yeah..

earnest phoenix
#

authors cannot have mentions

#

or any kind of formatting

#

only field values and descriptions

astral yoke
#

so how would I change it with mentions?

earnest phoenix
#

what

astral yoke
#

how would I get it to work on the embed

earnest phoenix
#

use the description or a field value

#

also for the undefined

#

the properties you're looking for are on a user

#

not on a member

astral yoke
#

ty

green vale
#

I want to do something like:

    config.package = yaml.safeLoad(fs.readFileSync(config.friendlyblobs.args[0].ok))

with args[0] being the argument of the command.

How can I do something like this?

neat gazelle
#

config.package = yaml.safeLoad(fs.readFileSync(config.friendlyblobs[args[0]].ok))

green vale
#

So [] is the escape?

neat gazelle
#

yes

#

args is your variable

#

when using "." and your variable, the variable has to be inside of []

green vale
#

oh alright

#

O, but now it's saying this

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined

#

It's undefined instead of a string

neat gazelle
#

console log ```js
config.friendlyblobs[args[0]].ok

green vale
#

Let me try again with another variable--

#

another value

#

Yep same thing, let me check console log

neat gazelle
#

what is the value?

green vale
#

When I try to console.log(config.friendlyblobs[args[0]].sku), it returns "Cannot read property 'sku' of undefined"

#

I know that args[0] should return a string

neat gazelle
#

ok whats the config variable?

green vale
#

config is a json file

neat gazelle
#

basially fs.readFileSync is looking for a string value and config.friendlyblobs[args[0]].ok is not a sting value or config.friendlyblobs[args[0]].sku

#

.sku doesnt exist apperantly

green vale
#

I did something wrong

visual sandal
#

I made this function but it keeps returning undefined

            function afk(input) {
                fs.readFile('./resource.json', 'utf-8', async function (err, data) {
                    let body = JSON.parse(data);
                    let afk = body.afk;
                    for (let i = 0; i < afk.length; i++) {
                        if (afk[i].id === input.toString()) {
                            return true;
                        }
                    }
                    return false;
                })
            }
green vale
#

Let me try again

#

okay correction* when I run console.log(config.friendlyblobs[args[0]]) it returns undefined

neat gazelle
#

what exactly are you trying to do? @green vale

green vale
#

Okay let me explain it

#

So I'm creating a "marketplace" of some sorts for commands for my Discord bot

#

So like the way that my "marketplace" would work is that people could submit custom "packages" (command packs), and they can put info about the commands and the name and description in a JSON file that's similar to package.json

#

For the safety concerns--I review them manually (if that's what you're wondering)

neat gazelle
#

@visual sandal its coming undefined becuase js if (afk[i].id === input.toString()) { return true; }
is coming up false i think

quartz kindle
#

@neat gazelle answering your question from #topgg-api since this is the right place for it. When getting a user from the cache, the user is not guaranteed to be available. in order to get the user you will need to fetch from the api by using its id

#

guilds have an .owner and a .ownerID property for that. if .owner is not available, fetch it using the id provided by .ownerID

#

(in discord.js)

earnest phoenix
#

it's like that everywhere since the api returns the owner id in the guild object

neat gazelle
#

oh i need to try this. thank you

quartz kindle
#

since all you wanted was the owner's ID, you can simply use guild.ownerID directly, without needing to fetch anything

green vale
#

@neat gazelle Thanks for the help btw it finally worked

visual sandal
#

If the statement is false for the if statement then it should return false from the return outside the loop, right?

neat gazelle
#

no. if the if statment is false then it doesnt run the the method inside it. therefore nothing is being returned so its undefined

visual sandal
#

I did this, but it's still undefined

            function afk(input) {
                fs.readFile('./resource.json', 'utf-8', async function (err, data) {
                    let body = JSON.parse(data);
                    let afk = body.afk;
                    let result = false;
                    for (let i = 0; i < afk.length; i++) {
                        if (afk[i].id === input.toString()) {
                            result = true;
                        } else {
                            result = false;
                        }
                    }
                    return result;
                })
            }
neat gazelle
#
             function afk(input) {
                console.log(input);
                fs.readFile('./resource.json', 'utf-8', async function (err, data) {
                    let body = JSON.parse(data);
                    let afk = body.afk;
                    let result = false;
                    console.log(data);
                    console.log(afk);
                    for (let i = 0; i < afk.length; i++) {
                        if (afk[i].id === input.toString()) {
                            result = true;
                        } else {
                            result = false;
                        }
                    }
                    return result;
                })
            }```
#

do that to trouble shoot and see where its coming undefined

visual sandal
#

I tried that, but lemme try again

neat gazelle
#

try this as well, under your for loop do console.log(afk[i].id)

#

and in your else statement do return false instead

copper cradle
#

@visual sandal add a return to before fs

#

you should return the return value of the callback, which is the return value you specified

visual sandal
#

still undefined

neat gazelle
#

what all did you try?

visual sandal
#

I tried the code you sent and the modification zSnails said

neat gazelle
#

mmmm weird

#

what are the console logs?

visual sandal
#

that's the entire log

copper cradle
#

show your new code

visual sandal
#
            function afk(input) {
                console.log(input);
                return fs.readFile('./resource.json', 'utf-8', async function (err, data) {
                    let body = JSON.parse(data);
                    let afk = body.afk;
                    let result = false;
                    console.log(data);
                    console.log(afk);
                    for (let i = 0; i < afk.length; i++) {
                        console.log(afk[i])
                        if (afk[i].id === input.toString()) {
                            result = true;
                        } else {
                            result = false;
                        }
                    }
                    return result;
                })
            }
copper cradle
#

then declare an empty var at the top of the function, redeclare that var inside the callback

#

and then return that var

neat gazelle
#

wait so data is undefined

visual sandal
#

yes

neat gazelle
#

did you try changing your else statement to what i said earlier?

#

wait do thi

sudden geyser
#

@visual sandal you need to use a callback if you want a value from a callback.

neat gazelle
#

nvm lol

sudden geyser
#

either that or async/await

copper cradle
#

oh wait

#

I thought you were having another issuw

#

you could've said that

visual sandal
#

how..

earnest phoenix
#

how i put the bot in invisible/offline?

#

in type?

#

or status?

digital ibex
#

however u make it show online

#

change that to "invisible" instead of "online"

dapper compass
#

Hi, please how do I use the 'get' command ? (What do I need to import ?)
I can't find it in the doc cause searching the keyword "get" isn't really effective..

category = get(guild.category_channels, name='test')
real totem
#

hello discord bot nothing is active what can i do?

dapper compass
#

(Oh, with Discord Py)

rocky solstice
#

hello discord bot nothing is active what can i do?
@real totem What library are you using?

#

Discord.js?

real totem
#

discord.js

rocky solstice
#

js.

#

Alright.

real totem
#

Ok i solved it thanks anyway

rocky solstice
#

You're welcome, I guess.

green vale
#

So I'm developing a bot [DJS v12], and I'm going to use quick.db (It sucks, I know, but it's the easiest thing to use).

How would I use quick.db per-guild?

rocky solstice
#

Hm.

#

You can do ```js
db.add(${message.guild.id}_(thing you want define), (thing x2));

green vale
#

alright

rocky solstice
#

Then.

#
const fetched = db.fetch(`${message.guild.id}_(thing you want define)`);
green vale
#

Alright

rocky solstice
#

I guess you're using quick.db for economy commands.

green vale
#

Nope.

rocky solstice
#

Oh.

green vale
#

I'm creating some sort of "commands marketplace", I use Enmap for my main bot but I messed up my testing db for it

rocky solstice
#

I use Node 10 and Discord.js v11.

green vale
#

I use v12 and Node 12

white anvil
#

dont use enmap

#

stop

rocky solstice
#

^^^^

green vale
#

i've been using it for like 2 years its ok

white anvil
#

its really not

green vale
#

how

white anvil
#

it stores all ur stuff in one file

#

its prone to corruption

rocky solstice
#

Yeah.

#

What about Map?

white anvil
#

if somthing happens to file, all data gone

rocky solstice
#

Yes, just Map.

white anvil
#

doesnt scale at all

green vale
#
  1. I have backups on GitHub
  2. I have local backups
  3. It's not really too critical data anyway
rocky solstice
#

Then, what do you recommend.

green vale
#

All I have in my Enmap is just prefix so

white anvil
#

far slower than usual db

green vale
#

mongo is best for critical stuff

rocky solstice
#

Yup, ๐Ÿฅญdb.

green vale
#

Enmap works fast enough for me, and if it corrupts then that's okay since it's not critical

white anvil
#

i use postgres

#

i use postgres

green vale
#

Postgres

#

Hm

rocky solstice
#

Postgres, huh.

#

Never heard of it before.

white anvil
#

how

green vale
#

are you serious

white anvil
#

its one of most popular sql databases

rocky solstice
#

I'm pretty serious.

green vale
#

O_o

rocky solstice
#

Maybe because I'm new to coding.

green vale
#

What if I host my images on Postgres?

white anvil
#

but yea just dont use enmap at all

#

even if its non critical

#

it doesnt take long to spin up an actual database

#

its thre worst of the worst

#

i could list issues with it for ages

green vale
#

I do plan to migrate to Mongo at some point

rocky solstice
#

That's alright.

white anvil
#

btw

green vale
#

hm

rocky solstice
#

Quick.db actually sucks.

#

It's like Enmap.

green vale
#

It's based on the same thing

rocky solstice
#

if somthing happens to file, all data gone

white anvil
#

quick db is better than enmap

#

but still shit

green vale
#

I'm probably going to have to rewrite all of my commands

#

When I do move to Mongo/Postgres

white anvil
#

why

#

didnt you say you were only storing prefix

green vale
#

Yes

#

But I have configuration commands

#

Eh I'll figure it out when I do move

white anvil
#

i would have thought u would set it in one command and get it in your handler

green vale
#

There are* other settings but all of them are insignificant besides prefix

rocky solstice
#

Do you all mainly speak English?

green vale
#

Yes

rocky solstice
#

Lucky.

green vale
#

English and Japanese but natively English

#

Okay I'm gonna do quick.db lol

white anvil
#

๐Ÿคข

rocky solstice
#

๐Ÿคฎ

green vale
#

oh

white anvil
#

quick db is exact same but the only slight advantage is that its based on sqlite

green vale
#

It's temporary while I decide what db I should use

white anvil
#

if you cba learning sql then use mongo

green vale
#

Yeah I was already considering using Mongo

rocky solstice
#

Too many databases.

#

And what about Firebase?

green vale
#

Firebase has DBs?

rocky solstice
#

Yeah.

green vale
#

O_o

fast trench
#

It's temporary while I decide what db I should use
@green vale use MySQL. Super simple and easy to use

green vale
#

Hm another option

topaz fjord
#

mongodb

grizzled raven
#

i need to switch to mongo but aaaaaaaaaaa

steel drum
#

ive really liked mariadb

#

its meant to be a drop in replacement to mysql

#

and if you're developing a bot with node.js, it natively supports promises

green vale
#

that's cool

tidal sparrow
#

don't use firebase db

fast trench
#

MySQL is honestly the best and easiest db to use

dusky marsh
#

thats arguable

steel drum
#

theres no "best" database

golden agate
#

..
...

#

J3uwueeuyeye

#

Wheyyww

vivid crescent
#

wyd

spice smelt
#

well iโ€™m using quickdb and itโ€™s true it isnโ€™t really good. But can this be replaced by simple JSON files?

dusky marsh
#

anything is better than using JSON for your database solution

spice smelt
#

and btw why not use firebase? i havenโ€™t thought about it but it doenโ€™t seem that bad, right?

#

@dusky marsh why? not safe?

gilded ether
#

JSON is prune or prone to corruption

dusky marsh
#

^

gilded ether
#

i canโ€™t remember the word

#

but ANYTHING is safer

spice smelt
#

xD

#

actually its just a file so it makes sense xD

#

but what about firebase?

gilded ether
#

never heard of that

cedar nova