#development

1 messages ยท Page 1233 of 1

white drum
#

It still works but
@NightCrafter1#0882

unique patio
#

true matching

weak rain
#

oh lol

unique patio
#

You'd use it in cases like undefined. value === undefined

weak rain
#

oops

unique patio
#

instead of value == undefined (incorrect)

weak rain
#

i forget to change id

unique patio
#

but may pass

weak rain
#

i m sorry

white drum
#

You do !=
For not equal to

unique patio
#

Yes but !==

#

is for matching other types

white drum
#

That's wrong

#

I think

unique patio
#

Nope

#

It's right ๐Ÿ™‚

#

Too deep in this to go home now

#

ECMAScript 6 stuff

#

nearly 10+ years old standards

white drum
#

It doesn't work for me in certain cases

#

But

unique patio
#

It's used spedcifically

#

for certain cases.

white drum
#

I'm not feeling like explaining

#

Makes sence

unique patio
#

To sum

#

=== is strict comparison

#

== is light comparison

white drum
#

Ahh

unique patio
#

int to int matching ==

#

If you do an int to int/string match

#

===

white drum
#

K

unique patio
#

or if the value could be int, but may return undefined

#

!== undefined

#

Strict comparisons

#

For most part if you triple up; you're good to go

#

on all ends. But it looks really un-professional. ๐Ÿ˜›

white drum
#

Chat died

unique patio
#

--
To finish that, they wanted to compare what could be known as int type to a string representing an INT type; and the use of strict compare does a cast check between the types; for a proper-deeper match. Now this is as basic and straight to it as it gets.

earnest phoenix
#

no chat didn't die

unique patio
#

Real coding talk was had.

earnest phoenix
#

i'm still here

unique patio
#

All those who had questions mouth's dropped.

white drum
#

You kinda did babble on tho...

unique patio
#

You did pass bad information?

#

๐Ÿ˜‰

white drum
#

..

earnest phoenix
#

@pale vessel can you draw a gradient in canvas with transparency?

white drum
#

Anyone know how I can make a weather command

#

Like any thing I can use

#

Orr

unique patio
#

The weather APIs are becoming paid for

white drum
#

Bruh

unique patio
#

I hear of python or lower-end languages doing good scrubs

#

to pull the data without using active API but it's messy them scrubbers

#

See it most with python projects.

white drum
#

I use discord js

unique patio
#

Oh yeah no scrubbing with JS

#

it's very minimal there, you get as far as cross-site injection and that's it, no real power to surf the web and pull site-pages.

#

So yeah use an API from a weather network

#

(maybe costs) or use a better language to scrub it out.

white drum
#

Mhm

earnest phoenix
#

can you draw a gradient in canvas with transparency?
sounds really weird but i need it for a gay command
you can't make an image transparent in canvas so i had to make the rainbow gradient transparent
any idea how?

sudden geyser
#

What do you mean by "good scrubs"? What does the language really have to do with using an API?

unique patio
#

No idea, my graphics end is poopsky

#

Javascript doesn't have the power to execute a browser launch and cipher its components

#

like C#/python or even java

#

Those can hook for days and tell a browser to do whatever, grab data then process it.

#

Javascript will never have that power without added modules like NodeJS/etc.

#

Which won't power that.

earnest phoenix
#

Javascript doesn't have the power to execute a browser launch and cipher its components
@unique patio there is one npm package that can execute any installed web browser in the system inside the termnial iirc mmLol

sudden geyser
#

So, acting like a browser?

unique patio
#

There is actaully!

#

But it's not as good

#

But yeah if you can do that, by all means use that! But experience taught me a lower-end language to get that stuff done for scrubbing sites.

#

But if it's built in now via NPM hell yeah you winnin'

#

Javascript generally on its own cannot access different executed PIDs in the CPU and read them out.

#

but apparently with some additional modules you may get some support there but not full?

eternal osprey
unique patio
#

like this????
or embed

eternal osprey
#

i already have made a bot that shows the coordinates

unique patio
#

Looks more like an embed.

eternal osprey
#

yeah but look at those blue links

#

how do i add them to my embed?

unique patio
#

addfield/addfields

eternal osprey
#

but i have got a weather search bot

unique patio
#

There's a whole write-up on it, I don't use them much.

eternal osprey
#

so if you use $po rain it returs countries with raining weather

#

but that means that the countries change all the time

#

so i cannot just use addfield

unique patio
#

Hmmm just use >>>

thick gull
#

markdown links

unique patio
#

so it can look like this instead.
lol

#

You just want the line?

#

OR

#
Some balling code?

eternal osprey
#

?

thick gull
#

cosmos that is a terrible idea

eternal osprey
#

what are you citating all the time

thick gull
#

man wants an embed not a quote

unique patio
#

Embed though has limits

eternal osprey
#

i am using weather-js package to actually make the searchs

#

i want to define one google maps link to each country

#

but i've got no idea how to do that.

blazing portal
#

Yo guys, I am a bit confused, maybe you can help me out. I'm using Discord.js 12.3.1.
I am trying to fetch a message from a guild text channel, but i get the Missing Access error.
But when I log the permissions i have in the channel of the text, i have

[
  'ADD_REACTIONS',
  'VIEW_AUDIT_LOG',
  'STREAM',
  'VIEW_CHANNEL',
  'SEND_MESSAGES',
  'EMBED_LINKS',
  'ATTACH_FILES',
  'READ_MESSAGE_HISTORY',
  'USE_EXTERNAL_EMOJIS',
  'CONNECT',
  'SPEAK',
  'USE_VAD',
  'CHANGE_NICKNAME'
]
``` these... Since I have `VIEW_CHANNEL` and `READ_MESSAGE_HISTORY` I don't understand why i have missing access. any ideas?
eternal osprey
#

does your actual bot have the permissions through discord developer portal?

blazing portal
#

yeah

earnest phoenix
#

@blazing portal hey

eternal osprey
#

aman

#

help or shut up

blazing portal
#

wait. what permission in the developer portal do you mean exactly?

earnest phoenix
#

Lol

eternal osprey
#

srry, but hey is not helping

unique patio
#

When you invite bot to server you set perms for it to have

#

Trial it as an Admin in your server and request it.

eternal osprey
#

i usually give all my bots all the permissions

#

only administrator leaaving open

unique patio
#

If it works, yeah you need to set more perms for it.

#

That's brave, I'd admin for testing, no bot in my mind needs admin priv unless it's coded wrong.

eternal osprey
#

i said so

#

i usually give my bots the permissions it needs

#

but admin permissions are left open

unique patio
#

yea

eternal osprey
#

i might have wrote it done wrong.

#

anyways

unique patio
#

Other night watched a main discord bot token get stolen

eternal osprey
#

does anyone know how to send a link to the country in google maps, that changes for every country?

unique patio
#

as it spammed links all over the discord

eternal osprey
#

oowh fuckkk

unique patio
#

Yeah...

eternal osprey
#

you gotta regen that shit fast

unique patio
#

it was awkward as hell

#

It only had mod perms so it wasn't bad

#

but imagine

blazing portal
#

But the Permissions it has on Server level don't matter, if the channel overwrites give these permissions i logged

unique patio
#

Some public bots get takenhard

eternal osprey
#

but

#

no clue tbh

#

just try giving the perms to your bot

#

and see if that fixes your problem.

#

btw guys

unique patio
#

Doing some homework on your request there jonny.

earnest phoenix
#

I just made Koya gay XD

blazing portal
#

I can't replicate the permission error myself, so it's hard to test if admin would help it. My public running bot sometimes logs this error, might it be related to a guild not being ready or smth? But would that resolve in a missing access error?

unique patio
#

IT's possible

#

Are you awaiting the promise

#

and executing when it's there?

blazing portal
#

yeah im awaiting it

unique patio
#

Blind-firing is always a problem sometimes

blazing portal
#

but wouldn't that result in an unknown message error?

unique patio
#

Yeah undefined

#

I only ever pull on the go, cause discord blocks a bit of the retrieval process without, "hacks"

#

so on events, never; tell the server like, YO gimme dat.

#

Tends to be a fight with discord, especially when they revamp code restrictions, I think it was last API they revoked priv on guild usage in bot.

#

But I don't think it'd prevent what you wanted to do.

earnest phoenix
#

tested my rainbow gradient on Koya's pfp and I made him gay ๐Ÿณ๏ธโ€๐ŸŒˆ

unique patio
#

Nice!

blazing portal
#

hmmm

earnest phoenix
#

had to do a bit of math

pale vessel
#

@pale vessel can you use HEX colors in CanvasGradient.addColorStop()
yes, you can use rgb, rgba, hex on anything that uses colors

@pale vessel can you draw a gradient in canvas with transparency?
@earnest phoenix yes, use rgba, e.g. grd.addColorStop(0, "rgba(255, 212, 111, 0.2)");

earnest phoenix
#

@pale vessel thanks for introducing me to this awesome thingy i wanna hug you now man attachug

#

@earnest phoenix yes, use rgba, e.g. grd.addColorStop(0, "rgba(255,212,111, 0.2)");
@pale vessel I have a HEX value

pale vessel
#

add those two extra hex for opacity support

#

so it like #3179bd -> #3179bde6

earnest phoenix
#

uhh ok

#

nvm i used globalAlpha and it works

unique patio
#

neat

pale vessel
#

cool

earnest phoenix
#

How can I get the dominant color and color palettes from a url?
Which module or api should I use?

#

nvm i used globalAlpha and it works
no need to set the transparency for everything. Just do ctx.globalAlpha = 0.5;, draw your stuff which you want to be transparent, do ctx.globalAlpha = 0; then draw the other stuff which you don't want to be transparent

unique patio
#

lol

#

A bit behind but what project code913?

#

Just turn all images rainbow? lol

earnest phoenix
#

What's the matter, little boy? @earnest phoenix

unique patio
#

@earnest phoenix Your repetitiveness, and ignorance with that last statement I'd assume now.

#

@earnest phoenix You make no sense, make sense before you ask for help.

#

But like code suggested, child-overflow be best for you.

misty sigil
#

god damn thats blunt as fuck

pale vessel
unique patio
#

lol

misty sigil
#

love it

pale vessel
#

grab the image and get its buffer and use that module

#

this returns a 2d array that contains [r, g, b]

unique patio
#

@pale vessel You do a lot of image work or something?

pale vessel
#

sometimes

earnest phoenix
#

Just turn all images rainbow? lol
lmao i've been using ping Telk's API for most of my stuff but i don't want rate limits so i tried to make my own

drifting wedge
#

can i get a random number not as an int?

#

like just a number]

#

rankdom number?

pale vessel
#

a number is an int though

drifting wedge
#

fair

#

its giving me an eror

#

ill copy

earnest phoenix
drifting wedge
#

return self.randrange(a, b+1)
TypeError: can only concatenate str (not "int") to str

earnest phoenix
#

@drifting wedgecode913_mad

#

can i get a random number not as an int?
"10" ??

#

xD

#

it is string

#

but still number

#

:))

#

no

drifting wedge
#

its giving errors

unique patio
#

yikes

earnest phoenix
#

LoL

unique patio
#

I need to laugh

#

brb

pale vessel
#

what's b?

earnest phoenix
#

according to the computer "10" is a string

#

@drifting wedge please send the code

drifting wedge
#
        for xp in exp:
            cur_xp = xp["XP"]
            randomxp = random.randint('15', '25')
            new_xp = cur_xp + randomxp

            collection.update_one({"_id": author_id}, {"$set":{"XP":new_xp}}, upsert=True)```
#

py

pale vessel
drifting wedge
#

no space?

pale vessel
#

why inside 's?

drifting wedge
#

o idk

#

good point

pale vessel
#

yeah remove them

drifting wedge
#

should i have spaces?

pale vessel
#

that's a string

unique patio
#

lol

drifting wedge
#

alr

#

cool

#

but spaces

#

or doesnt it matter?

pale vessel
#

you'd want an int, which is just a number without quotes

#

doesn't matter

drifting wedge
#

alr

earnest phoenix
#

@pale vessel how can i send a Discord.Attachment inside the image: {} object of an embed?

drifting wedge
#

works!
pog

earnest phoenix
#

poggers

pale vessel
earnest phoenix
pale vessel
#

code wait

earnest phoenix
#

ok now stop

#

code wait
@pale vessel you linking the docs?

pale vessel
#

you have a buffer right?

#

nope

earnest phoenix
#

yeah

unique patio
#

you buffer.... or else

earnest phoenix
#
let image = new DIscord.Attachment(canvas.toBuffer(), "image.png");
pale vessel
#

use embed.attachFiles()

unique patio
#

Yeah

drifting wedge
#

how can i make it reset my xp after a i level up?

unique patio
#

xp = 0

drifting wedge
#

like reset a thing in mongo

pale vessel
#

make it a zero

misty sigil
#

^

#

that simple

drifting wedge
#

yea

unique patio
#

Just don't make it "0" again

#

unless you intend on converting string to int

drifting wedge
#

lol ok buddy

earnest phoenix
#

use embed.attachFiles()
@pale vessel so i can't directly pass an embed object inside TextCHannel.send() cuz I'll need to do some SHIT to it

pale vessel
#
const embed = new Discord.MessageEmbed()
.setImage("attachment://image.png")
.attachFiles({ name: "image.png", attachment: <buffer> });```
earnest phoenix
#

@unique patio you seem like you possess a brain. Welp I guess we're on different teams now (I don't possess a brain);

pale vessel
#

like this

faint prism
#

Is there a buffer in Discord's message timestamps or something?

earnest phoenix
#

@pale vessel I'm using an embed object

pale vessel
#

you can make it an array if you want to include more files

#

yes

unique patio
#
const exampleEmbed = new Discord.MessageEmbed()
    .setTitle('Some title')
    .attachFiles(['../assets/discordjs.png'])
    .setImage('attachment://discordjs.png');

channel.send(exampleEmbed);

pale vessel
#

do the same

unique patio
#

from the library

earnest phoenix
#

i only use MessageEmbed when I need a constant

pale vessel
#

let me give you an example for embed objects

earnest phoenix
#

thanks

#

seems weird to take help from a pineapple

drifting wedge
#

pog

#

can i make ranking?

earnest phoenix
#

yeah

drifting wedge
#

like compare mongo db

earnest phoenix
#

figure it out

pale vessel
#

in your send options:js { embed: { image: { url: "attachment://image.png" } }, files: [{ attachment: <buffer>, name: "image.png" }] }

drifting wedge
#

to whoever has the most of one specific thing?

pale vessel
#

images inside embeds use the attachment:// protocol (if you were to upload images to discord instead of using a url)

elder rain
#

hello i was wondering how i could add my bot to tog.gg i have it all coded and is finished and i am able to run it

unique patio
#

Union searches

#

are easily done.

pale vessel
#

you include the attachment inside files as buffer

faint prism
#
            #region Message latency
            var end = DateTime.Now.ToUniversalTime();
            var start = context.Message.Timestamp.ToUniversalTime();
            var messageLatency = (end - start).TotalMilliseconds > 0 ? end - start : start - end;
            #endregion

Tryna figure out why end is less that start... I feel like Discord is adding seconds to the timestamp

pale vessel
#

and use attachment://<file name and extension> inside the embed object

#

the name is the one you provided in the array of files

drifting wedge
#

hello i was wondering how i could add my bot to tog.gg i have it all coded and is finished and i am able to run it
@elder rain top.gg

#

?

earnest phoenix
#

@pale vessel wait files: [] will also show the file outside the embed right

#

lemme test

pale vessel
#

yes

faint prism
#

It's gotta be some kinda buffer, right?

unique patio
#

I fixed my android issue, few firmware adjustments hard-locked it with screen-off; I must quad-tap to make it show-able again

#

left it on 24/7

#

This problem I swore took all night to even think about... like wth.

pale vessel
#

@pale vessel wait files: [] will also show the file outside the embed right
@earnest phoenix wait no, only if you didn't use it inside the embed, i misread

#

i thought you asked me whether the property was outside embed bruh

earnest phoenix
#

I guess I did something wrong

            var colorThief = new ColorThief();
            
            const image = trackIMG;
            const imageStream = new Buffer(image);
            const attachment1 = new MessageAttachment(imageStream);
            colorThief.getColor(attachment1)
           .then(color => { console.log(color) })
           .catch(err => { console.log(err) })
#

trackIMG is URL

pale vessel
#

you should use something like node-fetch to grab a buffer from the url

#

i'm not sure what you're planning to do with the palette though

#

do you want to generate an image? that requires some knowledge on canvas

earnest phoenix
#

i understood, okey

#

.setImage for spotify

pale vessel
#

ah

earnest phoenix
#

I want to set the background color to the dominant color of the song

pale vessel
#

i see

earnest phoenix
#

huh

pale vessel
#

you have to convert the rgb value to hex

earnest phoenix
#

yeah

pale vessel
#

you should use await

earnest phoenix
#

I successfully made a gay command YEETUS

faint prism
#

Isn't that just a random num

earnest phoenix
#

That's kinda gay

pale vessel
#

@earnest phoenix i don't think that function returns a promise though

#

you don't need .then

earnest phoenix
#

getColor returns a promise

pale vessel
#

oh

earnest phoenix
#

any API which returns random 4096 x 4096 background images?
my goals are beyond your understanding

pale vessel
#

neither do palette, which is what i use

earnest phoenix
#

Huh, wait brb

pale vessel
#

bruh voltrex

faint prism
#

How did you all implement message latency? I was comparing date time now to the message time stamp

earnest phoenix
#

m.createdTimestamp - message.createdTimestamp ?

faint prism
#

So would that require me to edit the initial message

pale vessel
#

yes

earnest phoenix
#
const embed1 = new MessageEmbed()
                .setDescription(`blablabla`)
        message.channel.send(embed1).then(m => {
            let ping = m.createdTimestamp - message.createdTimestamp
#

yeah

pale vessel
#

i use that method too

faint prism
#

Gotcha ty

earnest phoenix
#

end m.delete()

pale vessel
#

because you're using node-fetch with it lol

#

if you already have a buffer, it doesn't return a promise

earnest phoenix
#

How to get the already made buffer

#

So i can do a test

weak rain
#
at readdirSync (fs.js:955:3)
at /home/container/handlers/command.js:13:26
at Array.forEach (<anonymous>)
at module.exports (/home/container/handlers/command.js:11:32)
at /home/container/server.js:21:35
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/container/server.js:20:13)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32) {
errno: -20,
syscall: 'scandir',
code: 'ENOTDIR',
path: './commands/announce.js/'
[ .....] - postinstall:container: sill install printInstalled internal/fs/utils.js:269
throw err;
Error: ENOTDIR: not a directory, scandir './commands/announce.js/'
at readdirSync (fs.js:955:3)
at /home/container/handlers/command.js:13:26
at Array.forEach (<anonymous>)
at module.exports (/home/container/handlers/command.js:11:32)
at /home/container/server.js:21:35
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/container/server.js:20:13)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32) {
errno: -20,
syscall: 'scandir',
code: 'ENOTDIR',
path: './commands/announce.js/'```
#

whats the error?

cinder patio
#

fs can't find that file

sudden geyser
#

announce.js is not a directory

weak rain
#

but it was working fine before ae_Policeman

sudden geyser
#

it doesn't work now shrug

weak rain
#

on my another bot its okay

stable eagle
#

let dm = message.guild.members.cache.get(WinningUsers.map(u => u.id).join(`\n`)) dm.send(`Congratulations! You won a giveaway in **${message.guild.name}** Your prize: ${prize}\n${link}`); Im trying to dm every giveaway winner, but this code gives an error when more than 2 people won

sudden geyser
#

But you may want to look at your loader

earnest phoenix
sudden geyser
#

Milo .get takes a single ID

#

What you should do instead is iterate over every WinningUsers, try to find them your cache (or rest API), and DM them.

earnest phoenix
#

what should I make first, a profile card or a rank card? waitWhatSpinwaitWhatSpinwaitWhatSpinwaitWhatSpinwaitWhatSpin

sudden geyser
#

depends. which one is easier

weak rain
#

const ascii = require("ascii-table");

// Create a new Ascii table
let table = new ascii("Commands");
table.setHeading("Command", "Load status");

module.exports = (client) => {
    // Read every commands subfolder
    readdirSync("./commands/").forEach(dir => {
        // Filter so we only have .js command files
        const commands = readdirSync(`./commands/${dir}/`).filter(file => file.endsWith(".js"));
    
        // Loop over the commands, and add all of them to a collection
        // If there's no name found, prevent it from returning an error,
        // By using a cross in the table we made.
        for (let file of commands) {
            let pull = require(`../commands/${dir}/${file}`);
    
            if (pull.name) {
                client.commands.set(pull.name, pull);
                table.addRow(file, 'โœ…');
            } else {
                table.addRow(file, `โŒ  -> missing a help.name, or help.name is not a string.`);
                continue;
            }
    
            // If there's an aliases key, read the aliases.
            if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => client.aliases.set(alias, pull.name));
        }
    });
    // Log the table
    console.log(table.toString());
}```
earnest phoenix
#

@stable eagle Just do a loop to get all one by one

weak rain
#

@earnest phoenix profile

#

i think

earnest phoenix
weak rain
#

will be a better choice

#

@earnest phoenix lol

sudden geyser
#

See here: js const commands = readdirSync(`./commands/${dir}/`).filter(file => file.endsWith(".js"));

#

Look at your ./commands/ directory. You'll probably find the announce.js file which belongs to the ./commands/ directory rather than an inner directory.

earnest phoenix
#

is there any difference between arrow functions and normal functions?

slender thistle
#

Regular functions created using function declarations or expressions are constructible and callable. Since regular functions are constructible, they can be called using the new keyword. However, the arrow functions are only callable and not constructible, i.e arrow functions can never be used as constructor functions.

earnest phoenix
#

uhh k ||kthnxbai||

slender thistle
earnest phoenix
#

lmao i love this emote ||kthnxbai||

#

@slender thistle thank you

restive shell
#

@restive shell that's a frickin awesome image
@earnest phoenix thank you !

earnest phoenix
#

lmao that was ten hours ago

magic jackal
#

Is anyone good with UNIX that can help me real fast with scp

restive shell
#

I just woke up xD

weak rain
#

Look at your ./commands/ directory. You'll probably find the announce.js file which belongs to the ./commands/ directory rather than an inner directory.
@sudden geyser its in ./commands/ only

restive shell
#

sorry

earnest phoenix
#

Is anyone good with UNIX that can help me real fast with scp
@magic jackal just ask your question man

magic jackal
#

sorry i didnt mean to hit enter

earnest phoenix
#

@restive shell what even is that image lol

restive shell
#

it's the bank account

sudden geyser
#

So shouldn't it be in another directory, as you're trying to read each directory in ./commands/ as well (such as ./commands/general/)

earnest phoenix
#

profile card?

restive shell
#

The canvas

#

Yes

earnest phoenix
#

cool

#

i'm also working on one

restive shell
#

It's fun

magic jackal
#

I want to move multiple directories without a wildcard like this

scp -r folder1/ folder2/ folder3/ user@IP:/dir

weak rain
#

So shouldn't it be in another directory, as you're trying to read each directory in ./commands/ as well (such as ./commands/general/)
@sudden geyser oh yeah

#

ty

magic jackal
#

can you do this?

pale vessel
#

only $399

earnest phoenix
#

my profile card is just a ran- don't want my idea to be stolen lol

restive shell
#

Make it customizable

earnest phoenix
#

yeah

#

rn it is just a smol thing

#

i'll add customizable stuff later

restive shell
#

If you ever need help just dm me a_pp_bunn

earnest phoenix
#

i like it when people don't act like gods here

#

They do, it's just not always

severe hare
#

hey i need help in adding more commands to my bot

restive shell
#

@severe hare huh ?

severe hare
#

me and my friend made a bot today and we need to add more commands

#

like meme

restive shell
#

So you need help with making the meme command ?

severe hare
#

yep

lethal raptor
#

how to get the users who wrote a certain command that i will setup

restive shell
#

Use reddit

lethal raptor
#

i mean startswith

#

if test is a startswith

earnest phoenix
#

till now all i got is a function inside a function inside an async function (yeah i counted). need to stop using let someImage = new Image() and should start using let someImage = await loadImage().

#

Meme is just fetching random queries from reddit @severe hare

lethal raptor
#

i want to get thr users u ran the command

severe hare
#

hmm yea

earnest phoenix
#

Use a package like node-fetch to fetch the json from the reddit api as a get request

restive shell
#

or use ("random-puppy")

earnest phoenix
#

Then filter it by nsfw if you want and get a random post from the posts property

#

Random puppy is not stable

severe hare
#

ok

earnest phoenix
#

randompuppy isnt stable???

restive shell
#

wdym ?

#

it works fine for me

lethal raptor
#

can anyone help me? any ideas?

restive shell
#

@lethal raptor sorry I didn't understand

severe hare
#

so random puppy is for dogs and all ri

earnest phoenix
#

For it to be working doesn't mean it's stable

restive shell
#

@lethal raptor you want to like log the messages ?

earnest phoenix
#

do you need to await User.avatarURL() in discord.js? I used it without it and got some timeout errors

lethal raptor
#

kinda and will use them later

earnest phoenix
#

@earnest phoenix No it's a sync function

lethal raptor
#

@lethal raptor you want to like log the messages ?
@restive shell temporarily

restive shell
#

yes you can do this

earnest phoenix
#

@earnest phoenix No it's a sync function
@earnest phoenix then the issue is probably with smth else

lethal raptor
#

how to

earnest phoenix
#

how to?

restive shell
#
console.log(`[(${message.guild.me.user.username}) (${message.guild.name}) (${message.author.username}) (${command}) (${args.length == 0 ? "No args detected." : args})]`);
#

something like that

earnest phoenix
restive shell
#

in you message handler file

earnest phoenix
#

spoonfeeding

#

Spoon feeding spoonfeed

restive shell
lethal raptor
#

ok

restive shell
#

@lethal raptor do you have like a message handler ?

lethal raptor
#

no

#

btw what will this log?

#

any message?

restive shell
#

only the commands

lethal raptor
#

oh

#

how can i make it log a certain message

restive shell
#

do you wanna log the messages ?

lethal raptor
#

yes

earnest phoenix
#

It won't log the commands that are being used if you don't have a command handler

sudden geyser
#

I want to move multiple directories without a wildcard like this

scp -r folder1/ folder2/ folder3/ user@IP:/dir
@magic jackal I did some research on the scp command. I don't see how you're using a wildcard.

restive shell
#

It won't log the commands that are being used if you don't have a command handler
exactly

lethal raptor
#

like if msg == 'test':
#then it will log it

earnest phoenix
#

Unless you put a logger under every emit of commands

lethal raptor
#

who like after every commands?

#

but what if i log one and only message

#

like as i said above

earnest phoenix
#
// Bind message event to client
console.log(`${<message>.author.tag} used a command!`);
// End of the event```
lethal raptor
#

like if msg == 'test':
#then it will log it

restive shell
#

@earnest phoenix he is not asking for that

lethal raptor
#

oh

restive shell
#

he want to log all the messages

#

<

lethal raptor
#

no no

restive shell
#

then he said msg == 'test'

lethal raptor
#

a unique messsage

restive shell
#

๐Ÿคฆโ€โ™‚๏ธ

lethal raptor
#

like test

#

is someone says test

restive shell
#

ohhh

lethal raptor
#

i want to log that

restive shell
#

just do this

lethal raptor
#

with his id

#

ig

restive shell
#
if(message.content == "test") console.log(`${message.author.username} just said "test"`)
earnest phoenix
#

So if a message equals to something log it

restive shell
#

this should work ?

lethal raptor
#

hmm?

#

and where will it log

restive shell
#

message.author.id

#

yes

earnest phoenix
#
if (["test", "bruh", "no", "yes", "holy", ...string[]].some(e => message.content === e)) console.log(`${message.author.tag} said ${message.content} with the ID of ${message.author.id}`);```
lethal raptor
#

oh

restive shell
#

this is more complicated to him ><

lethal raptor
#

lol

#

btw wont both work?

earnest phoenix
#

It would but my is more efficient because it can detect more than one string

restive shell
#

yes

green kestrel
#

lmao, triviabot's running so many active games at once that the !active command cant show them, the table is over the size limit for a discord message ๐Ÿคฃ

#

i guess im going to have to make that web based.

restive shell
#

@lethal raptor if you wanna log more than 1 word

#

yes

green kestrel
#

instead of a command

subtle osprey
#

is anyone here good at erela.js?

earnest phoenix
#

This isn't general Brain

green kestrel
#

thats a development statement

#

๐Ÿ˜›

#

the message is over the api size limit

#

theres no other way, right?

#

i mean i could split my ascii table into multiple messages but that will look spew

earnest phoenix
#

Just slice off the strings to fit?

#

To a minimum char size

green kestrel
#

thats not the reason its too big, its an ascii table ๐Ÿ˜„

earnest phoenix
#

Ascii tables sure does take a lot of chars, but there's no way to limit it until you slice it

restive shell
#

how can i check my bot?
@wintry timber what does that even mean

lethal raptor
#

@lethal raptor if you wanna log more than 1 word
@restive shell where will it get logged?

restive shell
#

@lethal raptor you can do channel / console.log / author

wintry timber
#

@wintry timber what does that even mean
@restive shell verified

lethal raptor
#

@lethal raptor you can do channel / console.log / author
@restive shell can i log them in json file?

restive shell
#

@lethal raptor you can do

bot.channels.get("channel.id").send("TEXT")
lethal raptor
#

oh

restive shell
#
ley Logs = bot.channels.get("channel.id")
Logs.send("Text")
lethal raptor
#

cant i log those ids in a json file?

earnest phoenix
#

it's not suggested to log your client logs to a channel

#

also why json

lethal raptor
#

also why json
@earnest phoenix bcaz i will be iterating through them and send them rewards

#

im making a currency bot

earnest phoenix
#

use a database for that

restive shell
#

use MYSQL

#

with heidiSQL

earnest phoenix
#

mysql is shit

lethal raptor
#

i dont have any idea how dbs work ;-;

restive shell
#

I used mongoose , sqlite3 , better-sqlite

earnest phoenix
#

if you're going for a server based sql database, go for postgresql

restive shell
#

Mysql with heidiSQL is perfect for me

earnest phoenix
#

i dont have any idea how dbs work ;-;
there's a first time for everything

#

mysql is anything but good lol

lethal raptor
#

hmm

restive shell
#

@earnest phoenix how so ?

lethal raptor
#

ok then how do i start then?

earnest phoenix
#

do research on databases, what are some popular ones and pick one that suits your needs

lethal raptor
#

so which db should i use?

earnest phoenix
#

do research on databases, what are some popular ones and pick one that suits your needs

lethal raptor
#

ok

restive shell
#

I used to handle 60,000 players in fivem

#

using MYSQL

#

๐Ÿคฆโ€โ™‚๏ธ

earnest phoenix
#

...ok?

misty sigil
#

oof

subtle osprey
#

mysql might be suck

sudden geyser
subtle osprey
#

but it is famous

misty sigil
#

but at least it isnt a json "db"

earnest phoenix
#

oracle is known to fuck up everything they touch

subtle osprey
#

for idk wide use?

earnest phoenix
#

cough jdk distributions

#

use postgres over mysql

misty sigil
#

*cough* update ur java

earnest phoenix
#

Cough why you guys talking about MySQL

#

postgres is opensource, constantly updated, has a fuckton of features that just throw mysql in the bin (jsonb, native unsigned longs etc)

restive shell
#

@earnest phoenix scroll up lmaooo a_pp_fluttercry

earnest phoenix
#

I know but seriously, MySQL?

#

L

lethal raptor
#

y do u guys hate MySQL

earnest phoenix
#

read above

misty sigil
#

why is mysql exist

lethal raptor
#

ok lol

hardy vector
#

im tryna publish something to npm but i get this

npm ERR! 403 a package version that is forbidden by your security policy.```
sudden geyser
#

is there more to the forbidden error

hardy vector
#
npm ERR!     /home/nerd/.npm/_logs/2020-09-11T14_53_09_074Z-debug.log```
earnest phoenix
#

what's the full stacktrace

restive shell
#

idk dude, for me ? it's working just fine a_pp_fluttercry

hardy vector
#
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/nerd/.npm/_logs/2020-09-11T14_53_09_074Z-debug.log```
#

thats everything

earnest phoenix
#

How do I buffer a picture from a URL.

#

in what language

pale vessel
#

node

#

i use node-fetch

earnest phoenix
#

in "guildMemberAdd" if member join is bot then return;
what command?

pale vessel
earnest phoenix
#

we will not spoonfeed you code

#

if (!user.bot) return

#

?

#

use the docs

hardy vector
#

client.on("guildMemberAdd")?

earnest phoenix
#
<node-fetch>(<URL>).then(res => res.buffer());``` @earnest phoenix
pale vessel
#

yes

#

but not user, it provides a member

#

so member.user.bot

cerulean salmon
#

i need idea about how a lock command works ?
like if i say -lock #channel_name bot will lock a channel for everyone except for the people who have mods/admin role.
i know if i overwrite the channel permission of 'send message' to false will may be work .but my question is how i can revert it as it was ?

restive shell
#

@cerulean salmon make a timer

#
  • lockdown unlock
earnest phoenix
#
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/nerd/.npm/_logs/2020-09-11T14_53_09_074Z-debug.log```

@hardy vector Do you have any file in the base path that are empty that you're publishing

restive shell
#

@cerulean salmon just revert the changes when the time is up

hardy vector
#

nope

#

all the files have something in it

earnest phoenix
#

is this coding right?

#

im trying to add meme commands

misty sigil
#

no

#

its . not _

restive shell
#

just change the _

#

make it .

earnest phoenix
#

ok thx

restive shell
#
  • add this
#
if(!message.channel.nsfw) return message.channel.send(
          new RichEmbed()
        .setDescription("Please run this command in a `NSFW` channel."));

earnest phoenix
#

ok

restive shell
#

memes should be in NSFW channels

earnest phoenix
#

don't spoonfeed code

nimble kiln
#

oh boohoo

pale vessel
#

memes should be in NSFW channels
@restive shell wHaT

earnest phoenix
#

instead lead them to that solution

hardy vector
#

also richEmbed is for v11

#

lmao

restive shell
#

because it's random flaz

pale vessel
#

bruh i use the reddit's json interface and filter out using over_18

restive shell
#

@earnest phoenix it's fine :)

pale vessel
#

too bad

earnest phoenix
#

what flaz said

#

lol

#

you can just not use images tagged with nsfw content

grim mesa
#

how to use client.channels.get on onether shard?

pale vessel
#

fetchClientValues() or channels.fetch()

earnest phoenix
#

how do i get information from a server where the bot is not available? example: number of members, id, server name

#

you don't

#

gm devs

#

"how do i get inside of a car if i don't have keys for it"

restive shell
#

dod it's just a question lmao you don't have to make fun of him pp_pinkstretch

earnest phoenix
#

i'm not making fun of them

#

my friend. you must probably be crazy.

#

it's just an anology as to why you don't (& can't) do it

#

If you don't know, just say I'm not sure. YOU CAN NOT! instead of saying.

#

what are you talking about

#

bb.

misty sigil
faint prism
#

Anyone have experience with selenium

earnest phoenix
#

why would you use selenium

faint prism
#

I've got some. But I have an issue that's being can you save, even on Google

#

It's what my company uses

earnest phoenix
#

oh

#

yikes

thick gull
#

is this coding right?
is, is he using notepad?

#

what a gamer

near ether
#

how can i check that a message still exists before i attempt to edit it?

earnest phoenix
#

fetch?

#

const msg = message.channel.messages.fetch(MESSAGE_ID)

near ether
#

alright

#

ty

earnest phoenix
#

fetch like aprox said (that'll cost you 2 requests, one to fetch, one to edit)
or
try catch the edit (costs a bit of memory but that's 1 request)
or
keep track of the deleted messages via the event

near ether
#

oooo

#

i can afford the mem cost

#

thanks man

frigid mesa
#

How do I control the amount of memory my bot uses?

earnest phoenix
#

memory isn't something you can directly control

misty sigil
#

new Discord.Client({
memUsage: 0
})

frigid mesa
#

how do I control/fix the bot crashing because of running out of memory?

misty sigil
#

you need to get a better server

earnest phoenix
#

inb4 hosting on a free hosting

frigid mesa
#

better what? ram?

earnest phoenix
#

yeah

frigid mesa
#

I have 32 GB available

misty sigil
#

yae

#

really?

frigid mesa
#

yes

cinder patio
#

jesus what does your bot do

earnest phoenix
#

are you sure the process uses up all of the 32 gigs? (or a big sum of it)

frigid mesa
#

the bot only uses like 2 GB

cinder patio
#

Ooh yeah I remember node having a maximum memory usage

#

I think you can set it with a flag

frigid mesa
#

ok, I currently have like 20 avalible total... but the RSS memory for the bot is up to 2 GB

earnest phoenix
#

that's still an absurd amount for a bot

#

how many guilds is it in

cinder patio
#

Use this flag --max-old-space-size to set the limit of memory the process can use

frigid mesa
#

thanks, It started fine, I put it on 6GB just for a test

#

usually it crashed after like 2 or 3 days due to the memory usage...

cinder patio
#

in megabytes, right?

frigid mesa
#

nodemon --max-old-space-size=6144 index.js

native osprey
earnest phoenix
#

you never login

frigid mesa
#

dont you need to log it in / start it

native osprey
#

oh.

frigid mesa
#

//Bot Login
bot.login(`${settings.token}`);

pale vessel
#

why `

torn ravine
#

or bot.login(token) since you did define it

native osprey
#

Where do i put that?

torn ravine
#

right at the bottom

#

also put your token into a .env file

misty sigil
#

or a .json file

still merlin
#

I'm trying to make a eris bot and I was wondering if you can use
switch and case "": in eris

cinder patio
#

why wouldn't you be able to? It's a javascript feature

#

eris is a library

earnest phoenix
#

How can I convert the given 3 numbers (RGB) to hex?

var colorThief = new ColorThief();
fetch(trackIMG)
.then(res => res.buffer())
.then(buffer => colorThief.getColor(buffer))
.then(color => { message.channel.send(color)} )
gilded sage
#

I want make my bot
Which manage
Web moderator
Moderator for server

pale vessel
earnest phoenix
#

divide r, g,b by 16 and multiply their remainders by 16

near ether
#

quick question -

when users vote, i dm them with rewards. if they have my bot blocked or something, i get the DiscordAPIError: Cannot send messages to this user. i know i can catch the error, but doesnt this contribute towards being ratelimited if my bot is getting api errors?

gilded sage
#

I want make my bot
Which manage
Web moderator
Moderator for server

earnest phoenix
#

@near ether it does

#

unfortunately you can't do much about dming

#

discord does not offer and refuses to add a way to check if you can dm a user before actually doing it

near ether
#

damn that really sucks

#

so going off of that, if i try to catch the error when attempting to edit a message, doesnt that also contribute to being ratelimited?

misty sigil
#

yes.

#

also, you can't edit messages that aren't yours fyi

earnest phoenix
#

yes, however the ratelimit bucket for that message is going to be dead since the message is gone

near ether
#

ah ok

#

i see

#

thanks!

gilded sage
#

How I make bot

faint prism
opaque seal
#

Why do I sometimes get:
Cannot read property 'bot' of undefined
on

module.exports = async (client, reaction, user) => {
    try {
        // Don't listen to DMs or Bots
        if (reaction.message.channel.type !== 'text' || user.bot) return;
faint prism
sudden geyser
#

@opaque seal user is undefined sometimes.

opaque seal
#

why that

sudden geyser
#

What event are you listening to

opaque seal
#

this is message reaction add

sudden geyser
#

And can you show where you call it

opaque seal
#
//Get events files and bind them to the bot client
    const events = requireAll({
        dirname: __dirname + '/events',
        filter: /^(?!-)(.+)\.js$/,
    });
    for (const name in events) {
        const event = events[name];
        client.on(name, event.bind(null, client));
    }
#

it works fine

#

it just happens some times

#

which is weird

sudden geyser
#

So sometimes it works, and sometimes it doesn't work. ThinkO_O

#

One solution would be to check if user was undefined in the event handler, but I'd also try logging name or seeing if something weird is happening. On the documentation (and it's source code), user shouldn't be null/undefined.

golden condor
#

What event are you listening for?

#

Also you don't need to use event.bind, you can just run it like this

#
client.on(name, (...args) => event(client, ...args))
honest perch
#

@gilded sage out of curiosity how old are you?

gilded sage
#

22

golden condor
#

hmmm

sudden geyser
#

They said message reaction add, so I assume it's the messageReactionAdd event.

golden condor
#

ok

#

Sec

gilded sage
#

@honest perch help

golden condor
#

Oh it only gives user?

delicate shore
golden condor
#

o nvm

delicate shore
#

WTF why my bot aborts itself

#

If pokemon isn't found

honest perch
#

@gilded sage you need to learn programming

misty sigil
#

try catch

delicate shore
#

I did

#

i have try

earnest phoenix
#

you're probably not using it correctly

misty sigil
#

show code

delicate shore
#
const Discord = require("discord.js")
const fetch = require("node-fetch");

module.exports = {
    name: 'pokemon',
    description: "pokemon info",
   async execute(msg){
  const { get } = require("request-promise-native");
    const { MessageEmbed } = require("discord.js");
    const args = msg.content.split(" ");

    let pokename = msg.content
      .split(" ")
      .slice(1)
      .join(" ");

    if (!pokename) return msg.reply("Tell a name Boomer");
try{
    const options = {
      url: `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php?pokemon=${pokename}`,
      json: true
    };
  }catch(err){
    console.log(err)
    msg.channel.send(`Frick, Caught an error ! ${err}`)
  }
    try {
      msg.channel
        .send(
          "Fetching Informtion for API. If You don't get any result within 5 seconds then pokemon doesn't exist in records of API. **Not every pokemon is in our records**"
        )
        .then(msg => {
          get(options).then(body => {
            let embed = new MessageEmbed()
              .setAuthor(
                body.name,
                `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/${body.images.typeIcon}`
              )
              .setDescription(body.info.description)
              .setThumbnail(
                `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/${body.images.photo}`
              )
              .setColor("#ff2050")
              .setFooter(
                `Weakness of pokemon - ${body.info.weakness}`,
                `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/${body.images.weaknessIcon}`
              );

            if (!body.info.description) return msg.reply("Pokemon Not found");

            msg.channel.send(embed);
            msg.delete();
          });
        });
    } catch (err) {
      console.log(err);
      msg.channel.send(err);
    }
   }}```
gilded sage
#

@honest perch yes

delicate shore
#

this is my code

#

This is in a bin

#

if you want

earnest phoenix
#

it's the same issue from yesterday and the day before yesterday lol

delicate shore
#

really?

earnest phoenix
#

it doesn't go into the catch

#

try catch finishes before the promise does

#

Should all commands be in one folder??? Sry I'm new

#

File I mean

#

either await it or .catch the promise, await is preferred though, pgamer

delicate shore
#

try catch finishes before the promise does
I seriously don't get the meaning of this

gilded sage
#

@honest perch I need to learn programming help me

honest perch
#

its not something i can help with

earnest phoenix
#

@earnest phoenix it genuinely does not matter however it's suggested you split your commands into their own folders/files for easier readability

honest perch
#

pick a language and learn

delicate shore
#

either await it or .catch the promise, await is preferred though, pgamer
@earnest phoenix what should i await

earnest phoenix
#

the promise

delicate shore
#

but I am try and catching this thing

#
try{
    const options = {
      url: `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php?pokemon=${pokename}`,
      json: true
    };
  }catch(err){
    console.log(err)
    msg.channel.send(`Frick, Caught an error ! ${err}`)
  }```
#

here how should i await

#

i don't think any promise is there (unless I am dumb af)

earnest phoenix
#

you're try catching an object

#

there's nothing to catch in the first place

gilded sage
#

@honest perch how much you help me

earnest phoenix
#

@earnest phoenix it genuinely does not matter however it's suggested you split your commands into their own folders/files for easier readability
@earnest phoenix OK, and what command should I use to run the bot? I use discord.js

#

huh?

delicate shore
#

there's nothing to catch in the first place
Sorry, but i still don't get it

misty sigil
#

OK, and what command should I use to run the bot? I use discord.js
@earnest phoenix you run it with node <filename>.js

earnest phoenix
#

๐Ÿšถ

misty sigil
#

why are you making a bot if you can't use try catch

delicate shore
misty sigil
#

you need to try catch the bloody fetch request

earnest phoenix
#

help vampirism at its finest

#

@earnest phoenix you run it with node <filename>.js
@misty sigil thx

misty sigil
#

not the bloody options

honest perch
#

@gilded sage learn yourself

delicate shore
#

you need to try catch the bloody fetch request
@misty sigil
oh only dat?

misty sigil
#

i'd just try catch the entire command if u dont know where to put it imo

delicate shore
#

I have that as well

#

I have 2 catches

#

but it won't work

#

Because cry said some promise related thing

earnest phoenix
#

you can also just catch straight in your command handler when you execute the command lol

misty sigil
#

would <fetch>.catch() work

#

because fetching is a promise in most fetch libs

delicate shore
#

ok

#

wait

#

Is that why tim said me to do await send ?

#

in a try catch

misty sigil
#

theres no need to await sends unless you need to resolve the promise

delicate shore
#

oh

#

one more thing

#

i can't recall

#

.catch(err, =>{
})

#

is this how you do it ?

misty sigil
#

no

opal plank
#

catch is for promises

#

try catch is for code blocks

opaque seal
#

Also you don't need to use event.bind, you can just run it like this
@golden condor I wanted to have events in different files in a clean way and it has always worked. It works fine too now. It just happens rarely which was just weird

earnest phoenix
#

catch takes a single argument

#

a function

delicate shore
#

Are there any docs related to catch try which i can read

opal plank
#

yeah one second

earnest phoenix
#

.catch and the catch keyword are also two completely different things that you don't quite seem to distinct yet

delicate shore
#

oh ok

#

thanks

earnest phoenix
delicate shore
#

ok

misty sigil
#

promises are hard at first

#

but once u know how to promise its fine

earnest phoenix
#

asynchronous programming never sits well with people who didn't take CS

delicate shore
#

ok

#

Thanks cry,Matthew,Erwin

opal plank
#

np

misty sigil
#

aye

delicate shore
#

can we do .then on .catch
I mean can we do promise.catch().then()

misty sigil
#

i feel like promise.then().catch() would work

opaque seal
#

Why do I sometimes get:
Cannot read property 'bot' of undefined
on

module.exports = async (client, reaction, user) => {
    try {
        // Don't listen to DMs or Bots
        if (reaction.message.channel.type !== 'text' || user.bot) return;

?

delicate shore
#
 .then(msg => {
          get(options).catch((error) => {
            console.error(error);
            msg.channel.send("Another Error! I suck tbh ```" + err + "```")
          })
          }).then(bod```

Something like this
#

oh

misty sigil
#

but not .catch().then()

delicate shore
#

ok

misty sigil
#

but probs works both ways

delicate shore
#

k

earnest phoenix
#

it works because catch returns a promise

#

it's usually an antipattern though

#

you'd usually chain a then on a catch if you're working with multiple promises and you're wrapping them under a single one

opal plank
#

the miracles of await

#

๐Ÿ™

delicate shore
#

ohh

earnest phoenix
#

it's the best to just use async/await instead yeah

delicate shore
#

k

#

it's just confusing to me so

earnest phoenix
#

what's your code

delicate shore
#

one min

earnest phoenix
#

are you doing it in the ready event

#

you

#

you create the activity list outside of the ready event

delicate shore
earnest phoenix
#

pgamer please start binning your code this is annoying

delicate shore
#

ok

earnest phoenix
#

you're calling then on an object

misty sigil
#

bruh

delicate shore
#

E

#

can we do .then on a .then

#

btw hello pgamerx
Hi

earnest phoenix
#

why didn't you read the links you got sent

delicate shore
#

I am trying

earnest phoenix
#

because that's the first thing that the mdn promise docs cover

#

stop being a help vampire, it's quite annoying

#

we gave you resources that you asked for and you still don't use them

misty sigil
#

goddamn

opaque seal
#

Why do I sometimes get:
Cannot read property 'bot' of undefined
on

module.exports = async (client, reaction, user) => {
    try {
        // Don't listen to DMs or Bots
        if (reaction.message.channel.type !== 'text' || user.bot) return;
#

This is the messageReactionAdd event

#

And it happens rarely

misty sigil
#

i'd presume it means user not cached

#

but might be wrong

near veldt
#

my discord bots been hacked yet again

#

this time i KNOW i didnt have jack shit to do with it

earnest phoenix
#

a discord bot can't be hacked

near veldt
#

Well it apparently was

earnest phoenix
#

you leaked your token

misty sigil
#

it can only be compromised by your own stupid self

near veldt
#

My

opaque seal
#

Is use this Matthew:

// Listen to raw events to emit messageReactionAdd event on uncached messages
client.on('raw', async event => {
    // Listen only to reactionAdd events
    if(event.t !== 'MESSAGE_REACTION_ADD') return;

    const { d: data } = event;
    if(typeof client.channels.cache.get(data.channel_id) === 'undefined') return;

    const channel = client.channels.cache.get(data.channel_id);

    // if the message is already in the cache, don't re-emit the event
    if (channel.messages.cache.has(data.message_id)) return;

    const user = client.users.cache.get(data.user_id);

    const message = await channel.messages.fetch(data.message_id);

    // Custom emoji are keyed by IDs, while unicode emoji are keyed by names
    const reaction = message.reactions.cache.get(data.emoji.id || data.emoji.name);

    client.emit('messageReactionAdd', reaction, user);
});
near veldt
#

bot was hacked

misty sigil
#

it cant be hacked

near veldt
#

I didnt leak my FUCKING token

misty sigil
#

bots cant be hacked

opaque seal
#

I didnt leak my FUCKING token
yeah you did

near veldt
#

Cant isnt in my vocab

cinder patio
#

Giuliopime, do you use partials by chance?

near veldt
#

try again

misty sigil
#

it can be compromised by your own stupid self or your stupid team

opaque seal
misty sigil
#

just regen the token lmfao

opaque seal
#

I use raw events

#

And eveything works

near veldt
#
  1. I dont have a team
  2. my token was not leaked
opaque seal
#

It just happends some times

misty sigil
#

it must've been leaked

#

the bot cannot be hacked

near veldt
#

it mustve not been leaked

#

cuz i didnt leak shit

#

it can be

#

hacked

opaque seal
#

You host your bot on a VPS?

earnest phoenix
#

@opaque seal the user isn't in cache

misty sigil
#

bots do not get hacked

earnest phoenix
#

use fetch instead

near veldt
#

ofc they can

misty sigil
#

no they cant

opaque seal
#

@opaque seal the user isn't in cache
@earnest phoenix I'm using raw data

near veldt
#

yes they can

opaque seal
#

it automatically gets the user

pale vessel
#

yes, fetch the user

earnest phoenix
#

i saw

opaque seal
#

You host your bot on a VPS?
@near veldt

earnest phoenix
#

and i told you to fetch

opaque seal
#

yes, fetch the user
how?

near veldt
#

no

opaque seal
#

it automatically gets the user
shouldn't it?

misty sigil
opaque seal
#

no
@near veldt localhost?

earnest phoenix
#

@opaque seal it does get the user... from cache

opaque seal
#

ok

near veldt
#

no

earnest phoenix
opaque seal
#

How can I fetch it and get it in the cache?

#

oh ok

earnest phoenix
#

fetch automatically puts the user in cache

opaque seal
#

ok thanks

#

no
@near veldt how the heck do you host your bot then

earnest phoenix
#

fetch is a cache lookup -> if not found make an api request -> cache the user

opaque seal
#

localhost or VPS, one of these two

misty sigil
#

or a free host

opaque seal
#

fetch is a cache lookup -> if not found make an api request -> cache the user
@earnest phoenix yep got it

misty sigil
#

free hosting is a great way to get your bot fucked over

#

(see pins)

near veldt
#

Nvm

#

i found the issue to how my bot was hacked

opaque seal
#

What was it

#

We all wanna know

misty sigil
#

"hacked" Thonk how

cinder sandal
#
const economy = require('../economy');
const tokens = require('../tokens')
const { MessageEmbed } = require('discord.js');

module.exports = {
    name: 'balance',
    description: 'shows ur balance',
    cooldown: 5,

    async execute(message, args) {
       const target = message.mentions.users.first() || message.author
       const targetID = target.id

       const guildId = message.guild.id
       const userId = target.id

       const coins = await economy.getCoins(guildId, userId)
       const tokensMoney = await tokens.getTokens(guildId, userId)

       const BalanceEmbed = new MessageEmbed()
       .setAuthor(`${target.tag}`, `${target.displayAvatarURL()}`)
       .setDescription(`Crystals: ${coins}\nTokens: ${tokensMoney}`)
       .setFooter('Your balance is per-guild. don\'t ask if you have 0 crystals in one server and 10 in another server.')
       .setTimestamp()

       message.channel.send(BalanceEmbed)
    },
};```
#

i get Tokens: undefined

#

how to fix it

near veldt
#

i'm hosting my bot on repl.it and i forgot that i created a test account that was visible and had the bots token in it

opaque seal
#

do you have a file in ../tokens?

misty sigil
#

lmfao

opaque seal
#

lol

cinder sandal
#

it's tokens.js

misty sigil
#

i knew it was free hosting

earnest phoenix
#

so you leaked the token

misty sigil
#

^

#

thats legit what leak the token means

opaque seal
#

it's tokens.js
@cinder sandal ../ means one directory up the current one

near veldt
#

but i still dont understand how they coulda used an invalid token

opaque seal
#

if it's in the same directory as the current file it should be ./

cinder sandal
#

it's in the main folder

near veldt
#

well whoever they are came from the same server that tried saying they didnt hack shit

cinder sandal
#

the commands are in command folder

opaque seal
#

In my raw event I used this, should be fine now right?
const user = await client.users.fetch(data.user_id);

earnest phoenix
#

yes

opaque seal
#

it's in the main folder
then should be fine but it isn't so you are wrong somehow

#

yes
great ty

cinder sandal
#

/[mainbotfolder]/command/balance.js

#

/[mainbotfolder]/tokens.js

opaque seal
#

share the tokens.js file

cinder sandal
#

tokens is an economy value like coins so

#
const mongo = require('./mongo')
const profileSchema = require('./schemas/profile-schema')

const tokensCache = {}

module.exports = (client) => {}

module.exports.addTokens = async (guildId, userId, tokens) => {
    return await mongo().then(async (mongoose) => {
        try {
           console.log('Debug  Mode: running find one and update')
           
           const result = await profileSchema.findOneAndUpdate(
               {
                   guildId,
                   userId,

               },
               {
                   guildId,
                   userId,
                   $inc: {
                       tokens,
                   },
               },
               {
                   upsert: true,
                   new: true,
               }
           )

           console.log('Debug Mode: RESULT:', result)

           tokensCache[`${guildId}-${userId}`] = result.tokens

           return result.tokens
            } finally {
                mongoose.connection.close()
            }
        })
    }

module.exports.getTokens = async (guildId, userId) => {
    const cachedValue = tokensCache[`${guildId}-${userId}`]
    if (cachedValue) {
        return cachedValue
    }
    return await mongo().then(async mongoose => {
        try {
           console.log('running findone()')

           const result = await profileSchema.findOne({
               guildId,
               userId
           })

           console.log('[DEBUG] Result:', result)

           let tokens = 0
           if (result) {
               tokens = result.tokens
               return tokens
           } else {
               console.log('[DEBUG] Inserting docs')

               await new profileSchema({
                   guildId,
                   userId,
                   tokens
               }).save()


               return tokens
           }
        } finally {
            mongoose.connection.close()
        }
    })
}```
#

if i try a command to get a Tokens: 1
it returns
(node:23) UnhandledPromiseRejectionWarning: CastError: Cast to Number failed for value "[Function] { addTokens: [AsyncFunction], getTokens: [AsyncFunction] }" at path "tokens"

spare mirage
#

how would I give out a role to the most active chatter each month

misty sigil
#

you'd need to store the amount of messages in a database

#

and at the end of a month, you check the db

spare mirage
#

alr

native osprey
pure lion
#

@native osprey you're doing node comma

spare mirage
#

its a comma

#

and do node index.js

pure lion
#

No just do node .

#

copy โ†“

#

node .

native osprey
#

Yes.

#

But dont work

thick gull
#

you dide

#

node ,

#

you did that

#

you do

#

node .

#

are you in the right file ?

spare mirage
#

he is

thick gull
#

wait why is your folder called index.js

spare mirage
#

no hes in the indexjs file

thick gull
pure lion
#

Wai-

spare mirage
#

..

pure lion
#

@native osprey learn js please

native osprey
#

What should it be called then?

spare mirage
#

oh shit here we go again