#development

1 messages Β· Page 876 of 1

cinder patio
#

These `

earnest phoenix
#

lul

#

inside ``

#

:v

coarse topaz
#

Oh

#

Sure, let me try, thanks

oak cliff
#

so its saying that guild is undefined for you grayald?

earnest phoenix
#

is the channel undefined

oak cliff
#

well your error is saying cannot read channels of undefined, so whatever is before channels is undefined

earnest phoenix
#

@cinder patio not sure but you wanted something like this?

const RandomElementGenerator = (array) => {
    let tempArray = [...array]

    return () => {
        const randomNumber = Math.floor(Math.random() * tempArray.length)
        const elementToReturn = tempArray[randomNumber]
        tempArray.splice(randomNumber, 1)
        if (!tempArray.length) tempArray = [...array]

        return elementToReturn
    }
}

const exampleArray = [23, 351, 213, 521, 4123]
const randomElementGenerator = RandomElementGenerator(exampleArray)
console.log(randomElementGenerator())
console.log(randomElementGenerator())
console.log(randomElementGenerator())
console.log(randomElementGenerator())
console.log(randomElementGenerator())
console.log(randomElementGenerator())
coarse topaz
oak cliff
#

you'll need to get message from reaction

coarse topaz
#

changing the listener?

earnest phoenix
#

(reaction, message, user)

oak cliff
#

no no, so messageReactionAdd passes reaction and user - you just need to pull message from the reaction object

earnest phoenix
#

in bot.on

coarse topaz
#

oh i see

#

perfect

earnest phoenix
#

:v

#

so, my problem?

oak cliff
#

messageReactionAdd does not pass message

sacred mountain
#

I need help

#

I’m making a ping command

#

It says this tho

earnest phoenix
#

code @sacred mountain

#

copy and paste code

sacred mountain
#

Oh

#

I hav a photo

earnest phoenix
#

please best paste code

sacred mountain
#

Ima copy code one sec

earnest phoenix
#

ok

sacred mountain
#

case 'ping':
//message.channel.send('pong!');
//console.log(message.member + ' USED 'ping' PROMPT')
//break;
ping_msg = message.channel.send(πŸ“ Pinging...)

        message.channel.send(`πŸ“ Pong!\nLatency is ${Math.floor(ping_msg.createdAt - message.createdAt)}ms\nAPI Latency is ${Math.round(bot.ping)}ms`);
        break;
#

Ignore the first bit (it’s old code)

#

It starts at ping_msg =

earnest phoenix
#

ok

golden condor
#

Ok

#

What is the issue

earnest phoenix
#

message.channel.send(`:ping_pong: Pong!\nLatency is ${ping_msg.createdTimestamp - msg.createdTimestamp}ms\nAPI Latency is ${Math.round(client.ping)}ms.`);

#

try it

coarse topaz
#

I think the last thing I need is the system to make the bot know when people reacted. Then it will change the number from 0, and will add 1 for each time the users reacted. when it reaches the limit (7) in this case, it should send a message...
@oak cliff Really thank you for helping me :')

oak cliff
#

so you want something to incriment every time you get a vote and then when it hits a certain number, stop?

coarse topaz
#

exactly

golden condor
#

@coarse topaz that shouldn't be too hard

coarse topaz
#

and it will send a message when the limit is reached

earnest phoenix
#

Np

oak cliff
#

well you could either store it in a db or call message.reactions.cache.size every time

golden condor
#

You just check on the message reaction add event if the message id = the id of the message

#

and check the reaction size

coarse topaz
#

@coarse topaz that shouldn't be too hard
@golden condor I'm sincerely noob at programming, anyway, I've been reading a lot of pages to work it by my self... tho I didn't find something about these features I'm asking here... πŸ˜…

golden condor
#

are u on discord.js?

coarse topaz
#

yep

golden condor
#

I understand that I'll try help

#

Ok

#

should be something along the lines of this

earnest phoenix
#

let guild = bot.guilds.cache.get(`675254454139748352`) const channel999 = guild.channel.cache.get(`694189734146211901`) channel999.send({ embed: embed }) });

error: Unhandled Rejection TypeError: Cannot read property 'channel' of undefined

coarse topaz
#

well you could either store it in a db or call message.reactions.cache.size every time
@oak cliff i think the second one is better

oak cliff
#

yeah probably

earnest phoenix
#

and Hector, congrats on trial mod

coarse topaz
#

Sooooooo, how could I figure it out? x)

#

Thanks Grayal! ^^

#

I'm trying to give my best πŸ™‚

earnest phoenix
#

Yeah

coarse topaz
#

Ah, by the way, I think Discord.js changed the way to send embeds, so I need to work with normal messages... Is there another way to send embeds?

#

When I try to send an embed, it doesn't work '-' And I'm sure I'm doing everything fine...

golden condor
#

I am tryna figure this out wait a sec

coarse topaz
#

Ok, thanks Cx! ^^

golden condor
#

There is two ways to do embed

earnest phoenix
#

hector can you go general please?

coarse topaz
#

Sure! I'll

golden condor
#
const Embed = new Discord.MessageEmbed() //basically the same as RichEmbed
.setTitle("whatever") //etc.
message.channel.send(Embed)
//or
message.channel.send({embed: 
title: "whatever" //etc.
})```
#

@earnest phoenix ^^

#
client.on("messageReactionAdd", async(messageReaction, user) => {
const emoji = messageReaction.emoji //the reaction emoji
const message = messageReaction.message //the message reacted to
if(!emoji.id === "") //unicode emoji (normal emoji) or a custom emoji (id)
if(!message.id === "the message id") //checks if it is the message you want
if(message.reactions.cache.size === 7) message.channel.send("whatever")
})
oak cliff
#

message.reactions.cache.size

golden condor
#

@coarse topaz I have tried to explain everything in there as best I could so you can understand rather than just spoonfeeding, hope it helps!

#

oopsy

oak cliff
#

i always forget too lol

golden condor
#

Yeah

#

;)

coarse topaz
#

I'm back...

#

Oh I see! Give me some minutes, I'll try it all... Thanks for being friendly with me! :)
@golden condor

golden condor
#

No problem man

#

Happy to help :)

earnest phoenix
coarse topaz
#

@golden condor Is this how it should be?
My bot doesn't answer to that command '-'

golden condor
#

.addField

#

You made a typo :)

earnest phoenix
#

cxllm

coarse topaz
#

A

#

XD

#

right

#

sorry!

earnest phoenix
#

how do fix my problem cxllm

golden condor
#

@earnest phoenix yes

earnest phoenix
#

this error

golden condor
#

What language?

#

discord.js?

earnest phoenix
#

ejs

golden condor
#

I don't know ejs sorry

#

What is the error coming from tho

earnest phoenix
#

okey

golden condor
#

Maybe I can try help

amber fractal
#

@earnest phoenix is that a bot or an OAuth2 login

#

has nothing to do with discord.js if that's the case

coarse topaz
mossy vine
#

whats the error tho

coarse topaz
golden condor
#

You on v11?

coarse topaz
golden condor
#

That'll be it

mossy vine
#

yeah then update to v12 or change MessageEmbed to RichEmbed

coarse topaz
#

will try they both, thanks!

mossy vine
#

no dont try both

golden condor
#

Not both at the same time

mossy vine
#

RichEmbed is a v11 thing and MessageEmbed is v12

golden condor
#

but updating to v12 changes everything

mossy vine
#

not that much

coarse topaz
#

Obviously not they both at the same time, nubie haha

#

If one doesn't work, then let's try with the next one

spare goblet
#

You should fix some of that indentation

#

It's almost impossible to read with that terrible indentation

mossy vine
#

^

#

use a linter

golden condor
#

On glitch you can use the format buttpn

spare goblet
#

At least something like this tohruweary

  if(message.content === `testembed`){
    const Embed = new Discord.MessageEmbed()
      .setTitle(`Hey!`)
      .addField(`Hello`, `Hello`);
    message.channel.send(Embed)
}```
coarse topaz
#

why should i format that? :(

spare goblet
#

anything would be better than that indentation

#

Because it's unreadable

#

I used to do the same, where my indentation is terrible, but then it would be a nightmare to rewrite / read back my code

golden condor
#

I use the vsc auto indenting

spare goblet
#

It also helps you understand the concept of scoping better

coarse topaz
#

Hmmm

#

Do you mean those words with colors?

spare goblet
#

webstorm auto indents anything you paste into it

#

Uh, no..?

coarse topaz
#

Then what do you mean with identation? πŸ€”

golden condor
#

like

this

coarse topaz
#

I'm a bit noob at this, really sorry x)

golden condor
#

Like when you press the tab button

coarse topaz
#

oh, of course

golden condor
#

In
dent

coarse topaz
#

i got it

golden condor
#

Ya

#

For v12

#

You may need a higher version of node

#

It requires node v12+

coarse topaz
#

What happened is that i just copied from what u sent to me, but i tend to make it readable, don't worry about it πŸ™‚

#

I can change the versions manually, right?

spare goblet
#

Put a proper ver

coarse topaz
#

I tried putting "12.x" , but didn't work.

spare goblet
#

That's because that's not a proper version number

coarse topaz
#

a

spare goblet
#

12.16.2

#

Is the recent stable

coarse topaz
#

ah

broken jay
#

Is JavaScript good choice for Discord bot backend RESTful API?

coarse topaz
#

Really thanks for all your help... I'm trying it now

#

nah, already ran the command and didn't work again...
Is the Discord.js version a wrong one?

#

ah, nvm

#

Hmm.. No... Still not working

#

Β―_(ツ)_/Β―

spare goblet
#

Just do npm install discord.js

coarse topaz
#

Ohh!

spare goblet
#

Glitch also needs a start script

coarse topaz
#

What do you mean with that?

spare goblet
#
"scripts": {
    "start": "node index.js"
},```
#

or something like that

#

I don't remember

#

I haven't touched glitch for a long time

earnest phoenix
coarse topaz
#

Thanks iara! ^^

#

@earnest phoenix Could you please show us your packages file?

earnest phoenix
#

ok

#

hang on

spare goblet
#

@earnest phoenix run this in console
npm install discord.js

coarse topaz
#

b r u h

spare goblet
#

what?

coarse topaz
#

I wanted to see if he had or not discord.js downloaded haha, you just ask him to install it
#solving problems even easier

earnest phoenix
#

@spare goblet ok

wheat jolt
wheat jolt
#

holy shit

merry dragon
#

Mans added everything he could find online.

wheat jolt
spare goblet
#

bro you have so many packages wth

coarse topaz
#

Mans added everything he could find online.
^^^ lmao

golden condor
#

@coarse topaz did it work?

earnest phoenix
#

app@yurianbot:~ 16:36
$ npm install discord.js
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN discord.js@12.2.0 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.2.0 requires a peer of erlpack@discordapp/erlpack but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.2.0 requires a peer of libsodium-wrappers@^0.7.6 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.2.0 requires a peer of sodium@^3.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.2.0 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@12.2.0 requires a peer of zlib-sync@^0.1.6 but none is installed. You must install peer dependencies yourself.
npm WARN prism-media@1.2.1 requires a peer of ffmpeg-static@^2.4.0 || ^3.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN prism-media@1.2.1 requires a peer of @discordjs/opus@^0.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN prism-media@1.2.1 requires a peer of node-opus@^0.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN prism-media@1.2.1 requires a peer of opusscript@^0.0.6 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.3 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.3 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.

  • discord.js@12.2.0
    added 15 packages from 17 contributors and audited 15 packages in 1.862s
    found 0 vulnerabilities
golden condor
#

AAAAAAAAAAAA

coarse topaz
#

@golden condor Hey! Thanks for asking!... Actually, after updating discord.js package, the bot doesn't answer to any of the commands :c

earnest phoenix
#

@spare goblet

golden condor
#

@coarse topaz things change in discord.js v12

earnest phoenix
#

@golden condor cxlm sorry :D

golden condor
#

Unless you wanna update to the new version

coarse topaz
#

@earnest phoenix It's totally ok, no need to paste all that here

golden condor
#

with all the changes

#

You should go down to v11.6.4

spare goblet
#

@earnest phoenix it should be fine then

golden condor
#

And change it to RichEmbed

spare goblet
#

try running your bot again

golden condor
#

It's practically the same

earnest phoenix
#

it said discord.js is v12.1.1

wheat jolt
#

he wasn't talking to you?

coarse topaz
#

it said discord.js is v12.1.1
@earnest phoenix Yep, it's the last version

golden condor
#

@coarse topaz if you allow me into your glitch project (in dms) I can try help

coarse topaz
#

@coarse topaz if you allow me into your glitch project (in dms) I can try help
@golden condor If you really want, I would thank it very much :)
Let's move to DMs then πŸ™‚

golden condor
#

Ok sure

#

Just so the invite isn't public

earnest phoenix
topaz fjord
#

you need node v12 or higher

#

for d.js v12

#

update your node

earnest phoenix
#

ok

#

i have node 13.12.0

topaz fjord
#

is this glitch or smth?

earnest phoenix
#

glitch

topaz fjord
pale vessel
#

add engines in package.json

topaz fjord
#

glitch supports a max of v12 apparently

earnest phoenix
#

so i need to downgrade the node to v12

topaz fjord
#
"engines": {
    "node": "12.x"
}
#

add that to package.json

earnest phoenix
#

ok

#

and hilariously it said

#

"engines": { "node": "8.x" },

#

it still stuck on the node v8.x

#

xd

royal portal
#

Whats the function for a random member?

#

discord.js

#

v12

pale vessel
earnest phoenix
#

discord.js is v12.2.0 now

royal portal
#

Cannot read property of members of undefined

pale vessel
#

try reading the error

royal portal
#
if(command === "someone") {
    
  var user = message.guild.cache.members.random();
  const embed = new Discord.MessageEmbed()
  .setDescription(`${user.user}`)
  .setColor(0x00AE86)
  message.channel.send(embed)
pale vessel
#

cache is inside members

royal portal
#

so message.guild.members.cache.random() ?

pale vessel
royal portal
#

hm

#

wait

#

@pale vessel if its in an embed, does it ping the user

pale vessel
#

no

royal portal
#

ok good

#

works now thx

honest perch
#

can you specify the amount of shards that you want created?

earnest phoenix
#

Does anyone know a bot that can verify that you own an instagram account?

warm cloud
#

what means would it have of doing so?

#

bots can't access connections

earnest phoenix
#

@warm cloud No but a bot that says " Put (LOL) in your bio" and then it checks if you do it and then youre verified

warm cloud
#

oh-

#

mayhap

#

wouldn't be hard to write

#

assuming IG permiits API access to bios

earnest phoenix
#

ahh is this a place where i can talk about my errors

opaque eagle
#

How can I get out the remaining time in moment.js?

earnest phoenix
rare tangle
#

my bot keep exceeding 256 mb ram though its only in 340 servers, what'd be the reason?

earnest phoenix
#

Hey @earnest phoenix
I tried this myself

#
if(command === "bansize") {
    message.guild.fetchBans()
    .then(banned => {
      message.channel.send(banned.size)
    })
  }```
#

Its supposed to work

#

fetch the bans

#

then send banned.size

valid frigate
#

is there any ratelimit against a bot leaving >n guilds at a time

earnest phoenix
#

so its message.guild.fetchBans().size if i aint wrong

#

i alrdy tried that

#

see what

#

wait*

#

use the method i told you

#
if(command === "bansize") {
    message.guild.fetchBans()
    .then(banned => {
      message.channel.send(banned.size)
    })
  }```

@earnest phoenix

#

is there any ratelimit against a bot leaving >n guilds at a time
@valid frigate
ratelimits exist on all endpoints, if you're using a library which handles them for you, you have nothing to worry about

valid frigate
#

ok

#

i was planning to make a command which allowed my bot to leave any number of guilds but i was limiting it to 5 max per command to be on the safe side

pale vessel
#

@earnest phoenix your code is a mess

earnest phoenix
#

i fixed it

royal herald
#

XD

earnest phoenix
#

lmao

#

tryin to fix the bans

royal herald
#

your code is mess xD

pale vessel
#

it's still a mess

earnest phoenix
#

it works good

#

i like the mess

royal herald
#

falzepe change avatar pls

earnest phoenix
heavy marsh
#

hmm

#

User bot ^^^ @drowsy sentinel

royal herald
#

Going personally I would use only fields if you can do it.

earnest phoenix
#

hmm

drowsy sentinel
#

You calling someone a self-bot for posting an embed?

royal herald
#

just in right order

heavy marsh
#

Ok nvm

royal herald
#

to make colums of some fields

heavy marsh
#

sorry

#

It was an image

royal herald
#

XD

#

it was blurred a little so I knew that was not a user bot

earnest phoenix
#

in the meantime the AMOLED theme on discord android is entirely black lol

royal herald
#

cause it is amoled

#

great contrast

#

so they wanted to show the contrast

heavy marsh
#

I have a question on discord.js v11.4.8
Is it possible to make the bor await 10seconds

await member.addRole(`700446711692263544`);
await member.addRole(`700446747083931708`);
await member.guild.channels.get(staffwelcomechannel).send(`![joins](https://cdn.discordapp.com/emojis/680985507299459072.webp?size=128 "joins") **Welcome to the staff server <@${member.id}>!**`);```
royal herald
#

hm

#

I did it before in discord.js but I can't say how. I just don't remember

earnest phoenix
#

setTimeout

royal herald
#

oh setTimeout sounds familliar

earnest phoenix
#

unfortunately js is singlethreaded so you can't do parallel execution blocking, you have to use setTimeout

heavy marsh
#

I mean wait for 10 seconds then do this part

await member.addRole(`700446711692263544`);
await member.addRole(`700446747083931708`);
await member.guild.channels.get(staffwelcomechannel).send(`![joins](https://cdn.discordapp.com/emojis/680985507299459072.webp?size=128 "joins") **Welcome to the staff server <@${member.id}>!**`);
earnest phoenix
#

yes

#

setTimeout

royal herald
#

yes

#

encapsulate it and pass to settimeout as function

#

or

#

just make arrow function afaik

heavy marsh
#
setTimeout(() => {

}, 1000);

await member.addRole(`700446711692263544`);
await member.addRole(`700446747083931708`);
await member.guild.channels.get(staffwelcomechannel).send(`![joins](https://cdn.discordapp.com/emojis/680985507299459072.webp?size=128 "joins") **Welcome to the staff server <@${member.id}>!**`);
#

Like this?

earnest phoenix
#

lol

#

no

royal herald
#

move all the code into that arrow function

earnest phoenix
#

why do you think that the first parameter of setTimeout asks for a func

heavy marsh
#

But then want it do every thing after each 10 seconds

royal herald
#

hm

earnest phoenix
#

wat

royal herald
#

so encapsulate rest of the code too in that arrow func

#

πŸ€”

heavy marsh
#
wait 10s
await member.addRole(`700446711692263544`);
wait 10s
await member.addRole(`700446747083931708`);
wait 10s
await member.guild.channels.get(staffwelcomechannel).send(`![joins](https://cdn.discordapp.com/emojis/680985507299459072.webp?size=128 "joins") **Welcome to the staff server <@${member.id}>!**`);
royal herald
#

Director

earnest phoenix
#

what

heavy marsh
#

Will it do it like that?

earnest phoenix
#

no

royal herald
#

idk

earnest phoenix
#
await member.addRole(`700446711692263544`)
}, 10000);
setTimeout(() => {
await member.addRole(`700446747083931708`)
}, 10000)
setTimeout (() => {
await member.guild.channels.get(staffwelcomechannel).send(`:joins: **Welcome to the staff server <@${member.id}>!**`)
}, 10000);```
royal herald
#

I am not JS master, but I would move all rest of code into that arrow function

earnest phoenix
#

This should work

royal herald
#

hm

heavy marsh
#

OOh so that will do each taking 10 seconds

earnest phoenix
#

Yup

#

what

royal herald
#

hm

earnest phoenix
#

?

heavy marsh
#
setTimeout(() => {
await member.addRole(`700446711692263544`);
await member.addRole(`700446747083931708`);
await member.guild.channels.get(staffwelcomechannel).send(`![joins](https://cdn.discordapp.com/emojis/680985507299459072.webp?size=128 "joins") **Welcome to the staff server <@${member.id}>!**`);
}, 10000);
earnest phoenix
#

are you guys blind

royal herald
#

why 3 settimeouts

heavy marsh
#

wHAT WILL THIS DO?

earnest phoenix
#

Uhh

royal herald
#

1 settimeout

earnest phoenix
#

guess what it will do

heavy marsh
#

Wait for 10s then does that?

earnest phoenix
#

correct

#

Hmm

heavy marsh
#

OOh ok thats what I need

royal herald
#

yes

heavy marsh
#

thank you

royal herald
#

move entire code you want to have executed after that 10 s

serene cliff
#

is there anyway to have pm2 restart even when bot responds
Error: getaddrinfo ENOTFOUND
Having a hosting provider network issue but wish the bot to continously retry reconect until it succesds

heavy marsh
#

Perfect πŸ™‚

royal herald
#

pm2 restart?

heavy marsh
#

So like this

setTimeout(async() => {

await member.addRole(`700446711692263544`);
await member.addRole(`700446747083931708`);
await member.guild.channels.get(staffwelcomechannel).send(`![joins](https://cdn.discordapp.com/emojis/680985507299459072.webp?size=128 "joins") **Welcome to the staff server <@${member.id}>!**`);

}, 10000);

await console.log(`[ Staff Server Join ] ${member.user.tag} (${member.id}) joined the staff server!`);
royal herald
#

Do you mean restart at 2 pm?

#

I dont understand async() Director

serene cliff
#

i mean having pm2 automatically restart the script once it fails connecting to discord api

#

Error: getaddrinfo ENOTFOUND

earnest phoenix
#

yup director, that's correct

serene cliff
#

with that error

heavy marsh
#

So that the await will work

#

thank you

royal herald
#

@serene cliff if you need to have restart when either bot responds or not you just need to use cron to stop and rerun the bot

earnest phoenix
#

by the way awaiting console.log won't do anything, it doesn't return a Promise

royal herald
#

if you want to do restart once you have error

#

you need to make your discord bot execute a script which stops the bot and also rerunning it once stopped

earnest phoenix
#

@royal herald i think he does it but he is unable to reconnect the bot once it stops i think

royal herald
#

why?

earnest phoenix
#

Hmm read the error

serene cliff
#

hosting provider having continous issues and when that occur all of my bots are dead and requires a manual pm2 restart command.. which is tedious and looking for an automation of this mess

royal herald
#

what is pm2?

serene cliff
earnest phoenix
#

It's a module that keeps your bot alive and you can also use it to restart a bot through a command and stuff

#

[But need to know how it works though]

royal herald
#

I don't know this so I'd better not help πŸ€”

small prairie
#

process manager

serene cliff
#
0|dbm      |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
0|dbm      | (node:19837) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
0|dbm      | (node:19837) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
This is a issue because my servr couldnt connect discord api due to providers network issue but beside that. im trying to find a way to get the bot to reconnct to discord api
#

not sure what way

earnest phoenix
#

where are you hosting your bot

serene cliff
#

kansas city

#

its from a datacenter

earnest phoenix
#

nothing on the api status page, so it's definitely on your end yeah

anyways d.js should auto reconnect, if not just call login again

small prairie
#

This has been happening for a while

earnest phoenix
#

.

grizzled raven
#

seems to have something to do with client.emojis

earnest phoenix
#

Never seen that before (not the client.emojis) that thing in the image

clear wraith
#

Does anyone know how to create economy commands?
Example: Bal, work, rob, daily, weekly, etc?

royal herald
#

hm

#

make database where you store all of your users' data about how much they have

earnest phoenix
#

@clear wraith lib?

royal herald
#

and then use commands to operate on that database I think

earnest phoenix
#

also you might need a database or json file

#

But i prefer database

#

json is not a database

clear wraith
#

I have a database file

royal herald
#

cry who said that?

earnest phoenix
#

@earnest phoenix ik

#

everyone and everything

royal herald
#

json is not database but... hm mongodb uses json to store data

earnest phoenix
#

it's glorified json yes

#

but mongo, while still being trash, is an actual database wrapper

royal herald
#

so json can be used as database

earnest phoenix
#

raw json files are not

#

can

#

but aren't supposed to be

royal herald
#

What's the idea behind nosql databases?

trim nexus
#

performance I guess

earnest phoenix
#

not having to write sql

#

some sql databases outperform nosql ones

royal herald
#

so json databases are faster?

#

usually?

earnest phoenix
#

uh no

royal herald
#

he said "performance I guess" and I don't know what he mean by writing so

earnest phoenix
#

it's a guess

royal herald
#

so he thinks nosql databases are faster

earnest phoenix
#

while mongo is utilising json, it isn't only json

#

people here tend to be stupid and still go for writing into raw json files

#

and then complain when they experience data loss and poor performance

wet dove
#

i have a question, how can i make the bot leaves from a voice channel when no one is in the voice channel? (I'm using js)

clear wraith
#

I have a question about how i can remove an owner from my bot. I've tried on Top.gg, but it didn't remove the user

ember atlas
#

@clear wraith This really isnt a development question, more of a #general one

clear wraith
#

Ok

lyric mountain
#

i have a question, how can i make the bot leaves from a voice channel when no one is in the voice channel? (I'm using js)
@wet dove get the array of users connected to the voice channel

#

if its size equals to 0 then leave

#

put that inside a cronjob or infinite loop

royal herald
#

and do it when someone leaves

lyric mountain
#

onLeave event triggers on guild member leave

royal herald
#

hm

lyric mountain
#

you can't listen to members leaving a vc

royal herald
#

there is no onvoicechannelleave event?

lyric mountain
#

no

royal herald
#

:C

lyric mountain
#

afaik

quartz kindle
#

there is voiceStateUpdate

wet dove
#

oh ty

royal herald
#

hm

earnest phoenix
#

what's the v12 change for js message.guild.roles.find("name", "rolename");

quartz kindle
#

.cache.find

earnest phoenix
#

ok

#

why did it say this

fn.bind is not a function
quartz kindle
#

update your node.js version

earnest phoenix
#

im on 12.0.0

quartz kindle
#

are you sure? do node -v

earnest phoenix
#

yep

quartz kindle
#

show full error

earnest phoenix
quartz kindle
#

.find("name","value") was removed

#

use .find(function)

#

like this: .find(item => item.name === value)

earnest phoenix
#
let muterole = message.guild.roles.cache.find("name", "muted");``` 
im using it for a muterole function
quartz kindle
earnest phoenix
#

ah yes sorry for my stupidity

#

ty

calm shore
#

https://paste.menudocs.org/paste/zbu42
I want it so when i type
-page 2 with the space then my embed will send
but normally with a Modules file, u cant have a space in ur main command
so i added a args[0] but its not working

Tag me when you find an answer

earnest phoenix
#

@calm shore

#

Oh nvm lmao
Ill look at code

calm shore
#

the sender isn’t the problem

earnest phoenix
#

Ik ik

#

It seems fine idk

calm shore
#

it doesn’t work tho

quartz kindle
#

but normally with a Modules file, u cant have a space in ur main command
you can, there's nothing stopping you from doing this

calm shore
#

Ik

earnest phoenix
#

Also didnt understood

calm shore
#

how do i do it

earnest phoenix
#

Just put it in the command name?

quartz kindle
#

why are you checking for args and for message.content? they are both doing the same thing

#

console.log your args to see what they look like

calm shore
#

ok

#

Oh wait

#

thats the old

#

code

#

this is the new

quartz kindle
#

console.log your args

calm shore
#

console.log(args)

#

i did that

#

nothing happens when i run the command

earnest phoenix
#

Args[0]

quartz kindle
#

nothing shows in your console?

earnest phoenix
#

Or whatever u use

calm shore
#

Nope

#

wait

#

i have an idea

#

let me try something

#

Yea because originally i had all my help commands with -page 2 and stuff in my main js file, but due to adding in custom prefixes. Everything got wonky and it wouldnt check for prefix in my main file so i switched it all to command folders

#

Ok big new

#

i tried console.log(args[0])

#

and nothing popped up when i typed the command

warm marsh
#

In-order to get all the songs from a spotify playlist do I have to use their API?

#

Or is there an easier way?

lyric mountain
#

api

royal portal
#

How can I make it so if someone mentions a role then the bot replies

lyric mountain
#

it's the only way afaik

royal portal
#

in v12 discord.js

warm marsh
#

Alright, Thanks!

lyric mountain
#

and please note that spotify LOVES to change their api and not notify devs

royal portal
#

Anyone?

calm shore
#

Oh

#

yo here

#

it’s easy

#

once you specify the role that is being mentioned

#

do message.reply(β€œno”)

royal portal
#

yeah but im talking about

#

the specify part

calm shore
#

okay that’s easy too

#

so it’s all args. what u need to do is add this

#

let rRole = message.guild.roles.get(β€œROLE ID”)

#

then you do

#

That’s how u grab the role

#

then you need to add it to an args statement

#

so that would be this..

royal portal
#

how about without the id

calm shore
#

let rUser = message.guild.roles(message.mentions.roles.first() || message.guild.roles.get(args[0]));

royal portal
#

so it would work if its any role?

calm shore
#

yes

#

exactly

royal portal
#

what about if its named that role

#

then it works without id

#

let rRole = message.guild.roles.get(β€œrole here”) ?

earnest phoenix
#

let rUser = message.guild.roles(message.mentions.roles.first() || message.guild.roles.get(args[0]));

#

Like he said

#

Name and mention will work

#

@rolename or rolename

royal portal
#

what about @rolename

earnest phoenix
#

Yeah

#

@rolename or rolename

calm shore
#

-page 2

royal portal
#

oh

calm shore
#

let rUser = message.guild.roles(message.mentions.roles.first() || message.guild.roles.get(args[0]));

#

This command like i said will work

earnest phoenix
#

Told him

#

All good

calm shore
#

Just specify rUser in ur message

earnest phoenix
#

Try it

calm shore
#

Ty @earnest phoenix

royal portal
#

but then you could mention any role

#

and it would still work

calm shore
#

right

earnest phoenix
#

Yeah

royal portal
#

but just for a role named 'test' for example

earnest phoenix
#

It will get the first mentioned role / role name on args 0

#

So use @test or test

royal portal
#

but a specific role

#

not any

earnest phoenix
#

...

calm shore
#

Thats easy

#

Oh @earnest phoenix do u know how to add a space to a command modules file. I tried specifying args if (args[0] === '2') { Like that but its not working

earnest phoenix
#

Just add to command name

calm shore
#

huh?

#

wdym

sudden geyser
#

you want to have the command name with a space?

calm shore
#

Yes

#

Exactly

earnest phoenix
#

Add a space in command name?
"Command name"

sudden geyser
#

Wouldn't it be more convenient to use something like a dash? You'd have to make a workaround joining the entire string then checking if it starts with the command name.

calm shore
#

No a space is how its always been

#

My prefix is a dash

#

so i feel itll be ugly and weird if i add a dash instead of a space

#

-page-2

#

ew

earnest phoenix
#

Listen

#

Add a space
It will work

calm shore
#

add a space where

earnest phoenix
#

"Page 2"

calm shore
#

where i define args

earnest phoenix
#

Command name

calm shore
#

module.exports.help = {
name: "page 2"
}

earnest phoenix
#

Guess it will work yeah

#

I dont see why not

calm shore
#

i dont think it will work but ill try it

#

last time i tried it it never worked

earnest phoenix
#

Why not?
Its the command name
And "" lets you put whatever name

sudden geyser
#

why not make 2 be the subcommand or something

earnest phoenix
#

He tried with args
But he can use both ways
Name or sub

calm shore
#

so look

#

in chat u type -help

#

it sends u a dm

#

then in dms u type -page 2

#

and it goes to page 2

earnest phoenix
#

But the command will only work on the server

#

Wont it?

calm shore
#

but it was working fine with my main js file, but ever since i added custom prefixes i had to switch everything to modules

#

only the -help command will work because no space is specified

earnest phoenix
#

I use server.js with custom prefixes
Using quick.db

calm shore
#

what

#

Ok new solutions

earnest phoenix
#

I use a main file

calm shore
#

In my main.js file

#

how do i make custom prefixes work

#

here this is my code

earnest phoenix
#

Use quick.db and set a custom prefix for a guild

calm shore
#
/PREFIX FILES

bot.on("message", message => {
  const botconfig = require('./botconfig.json');
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
  if(!message.content.startsWith(prefix)) return;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = bot.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(bot, message, args);
})


//Files commands
fs.readdir("./commands/", (err, files) => {
  if(err) console.log(err);

  let jsfile = files.filter(f => f.split(".").pop() === "js")
  if(jsfile.length <= 0){
    console.log("Couldn't find commands.");
    return;
  }

  jsfile.forEach((f, i) =>{
    let props = require(`./commands/${f}`);
    console.log('\x1b[34m%s\x1b[0m', `${f} loaded!`)
    bot.commands.set(props.help.name, props);
  })
})```
#

so anyone can change the prefix to their own server

#

so its setup with a database

#

but this only works with Command Module Files

sudden geyser
#
  1. Avoid using JSON as a database.
  2. Check if you're in a guild. If the command was not run in a guild, default to your default prefix.
earnest phoenix
#

^

calm shore
#

Oh no this is working perfectly fine

earnest phoenix
#

First one is true
Json is bot a good db

calm shore
#

with module command files atleast

earnest phoenix
#

But json files are bad

#

Use quick.db or somthing

calm shore
#

They worked for me for a year

#

no problem

earnest phoenix
#

. .

#

hey people/ i got an issue

calm shore
#

We are in a chrisis rn Zin

earnest phoenix
#

ok sry

calm shore
#

uno momento

earnest phoenix
#

He can ask stuff

#

Go on

#

one sec

#

Zinx

sudden geyser
#

Also you can just require instead of JSON.parse(fs.readdirSync) Not sure about this actually

Quick.db imo is not a good alternative.

Wobbly, what worked for you? The JSON db or something else

earnest phoenix
#

ok nvm i got it

sudden geyser
#

alright

calm shore
#

Ok look. So the json file isnt the problem. The custom prefix where you can change ur prefix works perfectly fine with the Command Module folders, but with my main JS file at the start, Custom prefixes dont work and it uses my main and original prefix which is "-" while all the other commands that arent in my main js file use a different prefix. My problem here is i need to specify Custom Prefixes in my main js file, but i dont understand how to because the fact my big brain int working rn

#

that gives me anxiety when im trying to reread it, but its fine lol.

earnest phoenix
#

My brain

#

It hurts

calm shore
#

^^^^^^^^^^^

clear wraith
#

^^^^^^^^^^^^

calm shore
#

Lol would u like me to re word it or go into a testin vc while i turn on live to show u

#

Just go into vc and mute

#

and ill show u

earnest phoenix
#

Not the right time

clear wraith
#

Im waiting for your stream to load. :\

calm shore
#

oop

#

lol

#

Ok are u watching

clear wraith
earnest phoenix
#

ok i got an issue - basically im trying to add a text to my HTML webpage, but i gotta use <font> tag or a CSS. I'm trying to add text to the middle but i'm not sure how. It's been a while since I coded so please do understand I can't remember much. So issue: can someone add a text for me in the middle

clear wraith
#

Stream won't load. SLOW

calm shore
#

Ok short story

#

How tf do i get custom prefixes to work in my main.js file

#

they work perfectly fine with my command module files

earnest phoenix
#

u add prefixes in config.json

calm shore
#

but they arent working in my main.js file

#

0_0

#

wait wait wait

#

0_0

earnest phoenix
#

stop the repeat

#

im trying to get help

calm shore
#
//PREFIX FILES

bot.on("message", message => {
  const botconfig = require('./botconfig.json');
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
  if(!message.content.startsWith(prefix)) return;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = bot.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(bot, message, args);
})```
#

No ur a god

earnest phoenix
#

Just add them to the config and make it so if there is a prefix it will use it instead of the normal prefix

calm shore
#

u might be on to something

#

Ok how would that look

earnest phoenix
#

me?

#

Wobbly

#

not u

#

lmao

#

Oh

#

Lmao

calm shore
#
{
    "prefix":"-"
}```
earnest phoenix
#

yes

calm shore
#

This is my bot config

earnest phoenix
#

u can add more

#

Noo

calm shore
#

what would i add

earnest phoenix
#

"-","pe","!"

calm shore
#

LOL

earnest phoenix
#

For each guild id

#

Add a prefix

calm shore
#

BRUH wut

#

thatd take forever

#

theres over 200 guilds

#

LMFAO

earnest phoenix
#

The system will do it

#

Bro
Listen

#

ok i got an issue - basically im trying to add a text to my HTML webpage, but i gotta use <font> tag or a CSS. I'm trying to add text to the middle but i'm not sure how. It's been a while since I coded so please do understand I can't remember much. So issue: can someone add a text for me in the middle
🀯

sudden geyser
#

That's not a very good way of doing it. is prefixes[guildID].prefixes going to be a single string as the prefix, or an array of prefixes?

calm shore
#

What

earnest phoenix
#

When they do the !set prefix command the bot will take args and that would be the prefix
It will make it so each guild id have its own prefix

calm shore
#

Yes

#

thats what it does already

earnest phoenix
#

I didnt mean u do it

#

lmao

calm shore
#

It works fine with the command module files

#

but not my main js

earnest phoenix
#

So just make it ON MAIN JS TOO

calm shore
#

it works with my command module files because of this code i added to Filesystem

earnest phoenix
#

lool]

calm shore
#
//PREFIX FILES

bot.on("message", message => {
  const botconfig = require('./botconfig.json');
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
  if(!message.content.startsWith(prefix)) return;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = bot.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(bot, message, args);
})
#

I DONT KNOW HOW THO

#

LMFAO

#

I tried to do this

earnest phoenix
#

IM EXPLAINING

#

Reee

calm shore
#
bot.on('message', message => {

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
})```
earnest phoenix
#

hello baes

calm shore
#

But this doesnt work

earnest phoenix
#

message.guild.users.filter

sudden geyser
#

botCount is not a thing. Filter the guild member collection and check for if the member is a bot.

earnest phoenix
#

User bot

#

^

sudden geyser
#

guild.users is not a thing.

calm shore
#
//PREFIX FILES

bot.on("message", message => {
  const botconfig = require('./botconfig.json');
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
  if(!message.content.startsWith(prefix)) return;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = bot.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(bot, message, args);
})
``` How do i make this work for my main.js thoooooooooooooo
#

😭

earnest phoenix
#

Message.guild.members.filter(member => !member.user.bot).size

#

Kinda spoon feeding lmao

calm shore
#

lol

sudden geyser
#

The custom prefix where you can change ur prefix works perfectly fine with the Command Module folders, but with my main JS file at the start, Custom prefixes dont work and it uses my main and original prefix which is "-" while all the other commands that arent in my main js file use a different prefix. My problem here is i need to specify Custom Prefixes in my main js file, but i dont understand how to because the fact my big brain int working rn
Are you properly saving the file?

calm shore
#

What

#

oh yes

#

ctrl + s is a dear

#

Lol

sudden geyser
#

wut.

When you say "JS file at the start", do you mean when you restart your bot, or whenever you send a message? Are you using your DB's write function (fs module, even though you still shouldn't be using JSON a db)?

calm shore
#

No lol

#

js file at the start meaning my main js file i started with from the beginning

#

the first one i ever made

#

main.js

#

Faxxxxxxxxxxxxx

sudden geyser
#

This confuses me.

calm shore
#

Bruh not as much as me

#

😩 \

#

Ok here

#

So i made custom prefixes right?

#

Now when someone does

#

-setprefix !

#

It changes the prefix to ! for their specific server

#

right? Now if you do !ask which is a command, it will works perfectly fine

#

because its in a commands folder using modules filesystem

#

but the custom prefixes wont work for my main.js file because custom prefixes isnt defined in it and i dont know how to define it

#

for example i defined it in my modules command script like this


//PREFIX FILES

bot.on("message", message => {
  const botconfig = require('./botconfig.json');
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
  if(!message.content.startsWith(prefix)) return;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = bot.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(bot, message, args);
})


//Files commands
fs.readdir("./commands/", (err, files) => {
  if(err) console.log(err);

  let jsfile = files.filter(f => f.split(".").pop() === "js")
  if(jsfile.length <= 0){
    console.log("Couldn't find commands.");
    return;
  }

  jsfile.forEach((f, i) =>{
    let props = require(`./commands/${f}`);
    console.log('\x1b[34m%s\x1b[0m', `${f} loaded!`)
    bot.commands.set(props.help.name, props);
  })
})```
#

But i dont know how to make it work for the rest of the commands in my "Main.js" file

#

So for example. if the prefix is set to !

#

my lockdown command is in my main.js file so if you do, -lockdown on. it will work with "-" but not "!"

#

now i think this is the reason

#

const { prefix, token } = require('./botconfig.json');

#

But if i remove the prefix part of it, how will i make it work with custom prefixes

lyric mountain
#

Dude, just set a prefix column for your guild configuration table

calm shore
#

wut

lyric mountain
#

Instead of saving the prefix globally "botconfig.json", save it per-server

#

So every server start with the prefiz set to -, but can be changed individually

calm shore
#

Yes exactly

#

and thats what i did

lyric mountain
#

So what's the issue?

calm shore
#

it works fine with module command files but not my main.js

#

thats the issue

lyric mountain
#

Why?

calm shore
#

Ok look

lyric mountain
#

Where are you getting the prefix in the other files?

calm shore
#

Now when u have a commands folder you define it like this


//PREFIX FILES

bot.on("message", message => {
  const botconfig = require('./botconfig.json');
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
  if(!message.content.startsWith(prefix)) return;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = bot.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(bot, message, args);
})


//Files commands
fs.readdir("./commands/", (err, files) => {
  if(err) console.log(err);

  let jsfile = files.filter(f => f.split(".").pop() === "js")
  if(jsfile.length <= 0){
    console.log("Couldn't find commands.");
    return;
  }

  jsfile.forEach((f, i) =>{
    let props = require(`./commands/${f}`);
    console.log('\x1b[34m%s\x1b[0m', `${f} loaded!`)
    bot.commands.set(props.help.name, props);
  })
})```
#

this script is in my main.js file like everyone else has it

#

because thats how u get command folders to work

#

But i added this part to it

lyric mountain
#

Why aren't you getting the prefix dynamically?

calm shore
lyric mountain
#

Exact

#

Do that in main too

calm shore
#

how

#

bot.on wont work

#

i tried it

#

bot.on('message'

lyric mountain
#

message has a guild attribute

calm shore
#

well i know that

lyric mountain
#

Use it to get tge prefix just how you did

calm shore
#

my brain hurts

lyric mountain
#

The code above is the answer

calm shore
#

so would i do-

#

Yes ik

lyric mountain
#

Copy it into main.js

calm shore
#

Its in main.js

#

Ok look

lyric mountain
#

Lets go step by step

#

What db are you using?

calm shore
#

json

#

sadly

#

ill fix it later

lyric mountain
#

.....then I can't help you

#

It'll be overcomplicated

calm shore
#

bruhhhhhhhhhhhhhhh

#

okay tell me how to use .db

lyric mountain
#

If you used a sql database it'd be as simple as "SELECT prefix FROM guild WHERE id = :id"

calm shore
#

ok here

#

let me make it simple

#

  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;```
Do u know how to make this work for all of my commands in my main.js file
lyric mountain
#

Yes

calm shore
#

Ok

#

how

lyric mountain
#

Put that inside a function

#

And use the function to get the prefix anywhere

calm shore
#

but

#

wait wait

#

okay so would i do

lyric mountain
#

Do the following:

#

Create a Helper.js

#

Inside it put that code inside a function that returns a string

#

Then import Helper.js anywhere where you need to get the prefix

calm shore
#

so

#

in helper.js

#

would i add this

#

bot.on('message', message => {
  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
})
#

and then in my main.js

#

i would do

#

const prefix = require("./helper.js")

#

@lyric mountain did u die

lyric mountain
#

No

#

Also no for your other question

#

Just put it inside this:

function getPrefix(guildId) {
	//CODE

	return prefix;
} 
calm shore
#
function getPrefix(guildId) {
  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;

    return prefix;
} ```
#

my brain

#

hurts

#

okay wait

#

would i add that to helper.js

#

or main.js

#

where my code it

#

is

lyric mountain
#

the idea of using a helper file is to centralize commonly used functions

#

since you'll be calling that file pretty much everywhere

calm shore
#

so i cant do this in my main.js
const prefix = require("./helper.js");

astral yoke
#

I got an error at my command handler

#

who wants the error with code and help

lyric mountain
#

so i cant do this in my main.js
const prefix = require("./helper.js");
@calm shore no

calm shore
#

so would this be my helper.js file then

#
bot.on('message', message => {
  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;
})```
lyric mountain
#

const helper = require("./helper.js");
then
const prefix = helper.getPrefix(message.guild.id);

calm shore
#

so then this would be my helper.js if ur getting prefix

#
function getPrefix(guildId) {
  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[message.guild.id]) {
      prefixes[message.guild.id] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;

    return prefix;
} ```
lyric mountain
#

yep

#

but you gotta change prefixes[message.guild.id] to prefixes[guildId]

calm shore
#

so i would do

lyric mountain
#

no

#

you'd pass the guild id via argument

calm shore
#

oh

lyric mountain
#

in the function's call

calm shore
#

function getPrefix(guildId) {

#

its alr defined so it wont matter, correct?

lyric mountain
#

yes

#

that guildId will be defined when you call the method

astral yoke
#

Got error with command handler:

    at load (C:\Users\Cools\Downloads\azbot\handlers\command.js:14:36)
    at C:\Users\Cools\Downloads\azbot\handlers\command.js:28:27
    at Array.forEach (<anonymous>)
    at C:\Users\Cools\Downloads\azbot\handlers\command.js:28:14
    at FSReqCallback.oncomplete (fs.js:152:23)```

Code:

```const { readdirSync, lstatSync, readdir } = require("fs");
const logger = require("../utils/logger"); 
const Discord = require('discord.js')
const client = new Discord.Client();
const fs = require("fs")
const ms = require('ms');

module.exports = (bot) => {
  const load = dirs => {
    const commands = readdirSync(`./src/commands/${dirs}/`).filter(d => d.endsWith('.js')); 

    for (let file of commands) { //for each of these files
      let pull = require(`../src/commands/${dirs}/${file}`);
      bot.commands.set(pull.config.name, pull);
      if (pull.config.aliases) pull.config.aliases.forEach(a => bot.aliases.set(a, pull.config.name));
    };

  };
  readdir(`./src/commands/`, (err, directories) => {
    if (err) logger.error(err); 
    var dirArray = [];
    directories.forEach((f, i) => { 
      if (lstatSync(`./src/commands/${f}`)) {  
        dirArray.push(f);
      }
    });

    dirArray.forEach(x => load(x));
  });
};

calm shore
#

bruh great flood

astral yoke
#

Error is at bot.commands.set(pull.config.name, pull);.

#

nah not a flood.

calm shore
#

Its a flood

astral yoke
#

not on purpose my guy

#

just trying to get help with code

earnest phoenix
#

You did the same thing lmao

#

@calm shore

calm shore
#

Ik lol but no one was talking when i did it

earnest phoenix
#

Still

calm shore
#

he just completely wiped my convo

earnest phoenix
#

Whatever

calm shore
#

^

#

i mean yea ig i shouldnt talk

#

ok so

#

I made a helper.js

#

added this in it

#
  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[guildId]) {
      prefixes[guildId] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;

    return prefix;
}```
#

then added this to my main.js

#

const helper = require("./helper.js");

#

then i put this inside my command script

#

this is my error

#

(node:185720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 85) (node:185720) UnhandledPromiseRejectionWarning: TypeError: helper.getPrefix is not a function

#

bot.on('message', async message => {

#

const prefix = helper.getPrefix(message.guild.id);
^

TypeError: helper.getPrefix is not a function

sudden geyser
#

@astral yoke do you still need assistance? Are you sure you're exporting something with the property config?

astral yoke
#

No I don't, I was ignored and I found out it was due to one of the commands I added but I removed it and it worked. Thanks though.

sudden geyser
#

Np.

lyric mountain
#

(node:185720) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 85) (node:185720) UnhandledPromiseRejectionWarning: TypeError: helper.getPrefix is not a function
@calm shore have you defined the function correctly?

calm shore
#

function getPrefix(guildId) {
let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

if(!prefixes[guildId]) {
prefixes[guildId] = {
prefixes: botconfig.prefix
}
}

let prefix = prefixes[message.guild.id].prefixes;

return prefix;

}

#

i did that

#

that went in helper.js

#

const helper = require("./helper.js");
const prefix = helper.getPrefix(message.guild.id);

#

this went in main.js

lyric mountain
#

just a sec

sudden geyser
#

did you export it

calm shore
#

Well its not in a folder

sudden geyser
#

did you do module.exports or exports

calm shore
#

here

#

this is my whole helper.js file

#
const botconfig = require('./botconfig.json');
const Discord = require('discord.js');
const filesystem = require('filesystem');
const fs = require('fs');
const files = require('files');
const bot = new Discord.Client();

function getPrefix(guildId) {
  let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

  if(!prefixes[guildId]) {
      prefixes[guildId] = {
        prefixes: botconfig.prefix
      }
  }

  let prefix = prefixes[message.guild.id].prefixes;

    return prefix;
}
#

Thats all of it

sudden geyser
#

yeah so you didn't export it

#

so export it

calm shore
#

nope

#

okay but then i need to put it in my commands folder

lyric mountain
#

put export behind the word function

#

I guess

#

don't remember how to export a function in js

calm shore
#

export.function getPrefix(guildId) {
let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));

if(!prefixes[guildId]) {
prefixes[guildId] = {
prefixes: botconfig.prefix
}
}

let prefix = prefixes[message.guild.id].prefixes;

return prefix;

}

lyric mountain
#

no no

#

no dot

calm shore
#

export function getPrefix(guildId) {

lyric mountain
#

@sudden geyser is this howw you export a function?

#
module.exports = function (msg) { 
    console.log(msg);
};
#

do that

#

put module.exports = behind that function

calm shore
#

module.export = function getPrefix(guildId) {

lyric mountain
#

yes

#

try it

calm shore
#

ok im trying it now

#

one sec

sudden geyser
#

Kuu that's one way of doing it.

#

But that assigns the entire export.

#

If you plan on having multiple, you'll have to make properties for it.

#

like module.exports.property = function() {...}

lyric mountain
#

@calm shore

calm shore
#

module.exports.property = function getPrefix(guildId) {

sudden geyser
#

bruh

calm shore
#

.

lyric mountain
#

guess it'd be module.exports.prefix = function (guildId) {

calm shore
#

what about

#

getPrefix

lyric mountain
#

in node it's different from raw js

#

see "exporting functions"

calm shore
#

const prefix = helper.getPrefix(message.guild.id);
^

TypeError: helper.getPrefix is not a function

#

so

#

how would i make that const then

lyric mountain
#

const prefix = prefix(message.guild.id);

sudden geyser
#

Set the property as whatever you want it to be when exported, and use that same property to call it.

calm shore
sudden geyser
#

You're already exporting when making modular commands so this shouldn't be difficult

calm shore
#

ok let me test this out

#

U fixed it

#

❀️ no homo

#

ty

#

ly

distant notch
#

Hi

lyric mountain
#

@calm shore πŸ‘

#

now every common function you make just add to the helper file

vagrant root
#

i want to post my bot servers count in site how ?

earnest phoenix
heavy marsh
#

I am trying to do a command on discord.js v11.4.8
I am trying to give/remove a role/roles of staff members.
I want to run a command for example $xxx then it takes the roles from the main server adds or removes them to/from user in the staff server.

Its around 18 roles in total. What will the best way be?

heavy marsh
#

Even if there is 18 roles πŸ‘€

earnest phoenix
#

yes

#

it doesn't add them individually

#

the api allows you to pass an array of snowflakes to modify the member roles

heavy marsh
#

So I will have to check each role?

earnest phoenix
#

wat

heavy marsh
#

Ok nvm I will try it myself

#

I see how it goes

#

thank you

vagrant root
#
$.ajax({
    method: 'POST',
    url: `https://top.gg/api/bots/xx/stats`,
    data: {
        server_count: client.guilds.size
    },
    headers: {
        authorization: 'xxxx'
    }
});
#

now how can define server_count: client.guilds.size in the site ?

earnest phoenix
#

Wdym

#

You tell top.gg ur server count and the site will display it

#

you dont need to do anything else except one post request

prime cliff
#

Yo top.gg update my bot server count to 99999999 kthx

earnest phoenix
vagrant root
quartz kindle
#

you can set it to 9999999 yourself if you want

#

it will work

#

but most likely will get you banned from top.gg

coarse topaz
#

Well, good night to everybody, before all.
I wanted to ask you something, to see if you can help me with it :)

I run a command > Bot sends a message > Bot reacts to its own message with a specified emoji > And now, I need to make a system to make it know how many people is reacting, so when it reaches a specified reacts number, it will send a message...

I would thank it a lot if someone of you could help me. :P
(Please ping me when answering) πŸ‘

earnest phoenix
#

in which lib

coarse topaz
#

Discord.js

earnest phoenix
#

you'll have to check if the reaction was added to the message you want to keep track of

#

do that by comparing message ids

#

when executing the command you'll have to store the message id somewhere so you can compare it later in messageReactionAdd

#

store it in some form of a database if you want it to stay persistent, if not a variable is enough

unreal cliff
#

there is an easier way to do that

earnest phoenix
#

is there?

unreal cliff
#

ye

coarse topaz
#

I would be happy to hear all suggestions! ^^

#

Go ahead!

unreal cliff
#

message.createReactionCollecter

coarse topaz
#

And how am I supposed to use it? :p

unreal cliff
#

and then collecter.on('collect', ()=>{ some function here })

amber fractal
#

but then you can have a collector running forever

unreal cliff
#

no

coarse topaz
#

'-'

unreal cliff
#

you can specify a time limit

amber fractal
#

He doesn't want a time limit tho

earnest phoenix
#

isn't the collector just a subscription to messageReactionAdd under the hood

coarse topaz
#

exactly

amber fractal
#

I need to make a system to make it know how many people is reacting, so when it reaches a specified reacts number, it will send a message...

unreal cliff
#

then set the time to like a week