#development
1 messages · Page 1454 of 1
alr
why are you extending a class smh
cuz sanity?
I mean what are you doing that requires you to have ~30 extentions?
some of my classes are nice and neat and beautiful and make sense, however about 70% is crackhead energy level stuff
a full on API wrapper?
thatll do it
in ts can you make multiple constructors with different inputs like you can in java?
class MyCommand extends Command {
public constructor() {
super('meme', 'Sends a dank meme');
}
public async execute(event: CommandEvent) {
// Stuff
}
}
or:
const myCommand: Command = {
name: 'meme',
description: 'Sends a dank meme',
async execute(event) {
// Stuff
}
}
like idk if one has something better over the other
I would do classes since you can configure more as you go
yea makes sense
say you want it to be a ToggleCommand type you can just set requiredPerms and toggle and it will work
instead of duplicating code
wait thats ts?
yeah
o
o
I made a smol ts project
just to understand syntax I built a url shortener
for shortening urls i guess
i think i read google had a url shortener service or something
not quite sure what you mean but thats because im tired and can't think straight
there are 2 methods
post: /url
get: /U:id
/url saves the link in the DB with a corresponding ID
/U:id checks the DB for params.id and redirects
ok
took like 10 minutes to write
but I kinda just wrote js
only thing different was import not require()
well most small scale typescript looks like actual js lmao
alright
typescript shines when scaled
then you don't have to worry about your coworker storing phone numbers as an int and getting errors when operating on em
well nevermind who does that
indeed
anyway
I need to understand this tsconfig before I upload to github
not gonna post code I don't understand
idk lemme go turn on my pc
ight
I also have a question for you
wut
I have a file, lets cal it placeholder and I want it in the output directory, how can I tell ts to place it there
but I have to import them for it to work?
yea
it won't just realize I want a file
well technically yes
but ts doesn't know how to compile an html file or an image, for example
so you'll probably get an error if you import other files
well in short, you can't 
hmm
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"resolveJsonModule": true,
"paths": {
"*": ["node_modules/*"],
}
},
"include": ["src/**/*"]
}
``` is current but idk what most of it means
ik resolveJsonModule
thats it
aight
so
module indicates the target module (bruh)
idk that much about it
but most of the time i leave it at commonjs
alright
esModuleInterop makes ts compatible with ES modules
Something about module.exports and that stuff
so that would be required to use packages built for js?
So most likely you always need it to use npm libraries
ok that makes sense
ight
target is the compile EcmaScript version
So stuff like promises will be sort of "pollyfilled" for compiling to versions like es3, for example
hmm
i guess if you're running node it doesn't really matter that much, since its up to date with ecmascript for the most part
but just in case i put es5
ok
ight next one
That one is something about function params i think
maybe it applies to other stuff
basically forces you to add types to your function params
so i always have it on
ok that makes sense
and sourceMap?
that one makes the compiler emit sourcemaps to the output
which track errors from the compiled code to your ts
i think they're mostly used for debugging and finding errors quicker
oh so good for testing
yea
and is it unnecessary for prod?
o
well outDir is pretty self explanatory
yea
I was gonna say that but couldn't think of the word
what is the standard outDir?
out?
i think by default ts compiles each script next to its original file
so i don't really recommend leaving it blank
what do you use for your projects?
ight
baseUrl is the base for the paths option
resolveJsonModule lets you import json files
and paths act as sort of "alliases" for importing stuff
could you explain this a bit more?
yea im on it
so
you could add this for example:
{
"paths": {
"commands": "./src/some/folder/commands/*"
}
}
So now you can do
import PoggersCommand from 'commands/PoggersCommand';
o
so thats also what baseurl is for
do you normally use "*": ["node_modules/*"], in paths?
nah
ok
this is so useful pog
indeed
loggers
pogger logger
loggers
loggers
LMFAO
the commit history looks like a mental breakdown 
hmm
oh yea
um
i think that one makes typescript compile the stuff in that folder and thats it
Better than mine tbf
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"resolveJsonModule": true,
},
"include": ["src/**/*"]
}
``` new and improved
XDDDDDD
Fixed a bug
added bug whoops is my favorite tbh
lmao yes

darn
so I kinda just like
smashes keyboard
so now the question is
do I add function where if the file doesn't exist it makes it
or
not
you can check fs.existsSync('loggers.json')
"who tf told you that you should be here, test file"
wut
I have a streak of 22 commits that all read "why isn't this working" in a repo
mood
The last one is "holy fuck"
wait does that not work
Mood
no it works
but I might make it so it just writes the file instead of erroring
so if you are using ts you don't have to deal with fucky wucky code
fs.writeFileSync('pogchamp.txt', 'yo whats up')
yea
https://github.com/Million900o/jason.db here you can see perfect code
"This package stores JSON data which is prone to potential corruption and data loss."
no testing™️
yo
Is this a communist initiative
Ourcord start with js yes?
soviet anthem plays
hmm maybe
I don't think so
bruh i hate having to manually install types for 50% of my packages
packages that include typings with them have my respect
you speak spanish right @mellow kelp
do not worry I include typings
laughs in peruvian
legend
-probably said the guy who pushed to google just before it crashed
hmm
Yo million
lemme test rq
Update your readme
Options
imma pr too
im gonna make a great contribution
perhaps the greatest contribution github has ever seen
oh no
aight pr done
check my last commit
i see it
im gonna be that guy to get onto the contributors section for adding the license
basically
if writeFIle: true, write the file
else error
now on ts you can just cd into /dist/ and add writeFile as true
ez pz
i dont understand, why would you ever pass in writeFile: false now
no more fucky wucky code
hmm
you should make a "philosophy" section on the readme
why?
"Keep everything as configurable as possible, even though only 5% of people will configure it"
That way you can throw away pull requests and issues saying that they don't apply to you philosophy
Cough Cought CREATE REACT APP cough cough
still waiting for a schema wrapper
beautiful
"This is a placeholder"
the default is false, correct?
please CRA is actual garbage i have no idea why people use it
it's so much bloat
because who the fuck wants a random file somewhere in some random dir
say you mess up directories
no big deal just error
there are far better resources for learning react other than CRA
hmm maybe
realistically the file should already be saved
i ain't using it anymore anyways lmao
probably yea
unless you are using ts
then you can either do some weird shit with import or just use my new feature
ah yes
/**
* Read the Collection
* @returns {object}
*/
_read() {
return this.options.caching ? this._data ? this._data : (this._db._read())[this.name] : (this._db._read())[this.name];
}
the ternary operator
any way to find out who "Initiated" a reaction?
why would you write that
.author
whats wrong with you
wdym
its crazy
there is a reaction.users manager lol thats it

Nitro vs gif
if caching if data return data
else return read
else return read
best understood like that
anyway I have got to go
confused confusing confusion
it should probably be written like that lol
lmfao
noooooooooooooooooooooooooooooooo
thats it
im stealing jason.db
nvm
you HAD to add a license
nvm
its MIT
i like how you kept your fork even though you only added a LICENSE
lmao
cuz i wanna make my poggerscollection class
It stores that in a poggers format
With a .poggers extension
if (message.content.startsWith(prefix + "slap")) {
return message.channel.send("Please mention someone");
var embed = new Discord.MessageEmbed()
.setDescription(message.author.username + ' slapped ' + message.mentions.users.first().username)
.setTimestamp()
.setImage('https://media1.tenor.com/images/af36628688f5f50f297c5e4bce61a35c/tenor.gif?itemid=17314633')
message.channel.send(embed);
}```
it will not send the embed
@lucid prawn dont use vars, avoid using embed builders
ok
ye
also mentions.users might not exist
check it before sending
also that image url doesnt look like it'll load
im fairly certain it needs to be a .extension ending
well it probably does
@opal plank why avod embed builder
python?
i also used some query params for tenor
do n.tag embed builder bad in #commands or #265156322012561408 @earnest phoenix
remove embed = new Discord.MessageEmbed()
what
Its only 100msss
you can send it directly
wdym only 100ms
its legit 20x slower
it went from 13ms to 263

remove var embed = new Discord.MessageEmbed()
form it
well yeah, but if you remove it only it wont send the embed
pass the object directly onto channel.send(object here)
return statement
im still fairly certain that image url is borked or the mentions.user is error'ing
u a return statement
@opal plank return statement
See?
There is no any trigger for thst return
It will always return
yeah also that
Yup
the embed worked but when i added return to this it stop sending the embed
I was about to say that
hayper and barnie esxplained
how does your IDE not shadow the rest of the code?
like
Notepadd++ ide for sure
like if (!user) return message.channel.send("Please mention someone");
if (someConditionNotToSendMessage) {
return message.channel.send('bruh thats cringe')
}
actually
if not its always gonna return
message mention
Ya
Also no need for bracket, can convert it to one line.@ElCholoGamer#3291
yea
i try that
No
but for longer stuff i like to keep it inside brackets for some reason
That's an example, you must define the user's mention
Alright we got person expect spoonfeed
more or less
it's defined
Like let user = message.member.mentions.first();
can anyone help me in getting this kinda page ?
i dk anything bout html/css
oh thats markdown
there's this handy cheatsheet
still not working
Uh
oh ik why
Send SS
probably
probably what?
why it doesnt work
ye tq
Ok so
no prob
Tell us
its message.mentions.users.first()
like
No
It should be message.member.mentions.first();
message.mentions
There is something else that doesn't let the code run
not the other way around
yea
Oh
mentions is part of emssage payload
wait i just realized
you speak spanish
Sí we
Awebo
Hablemos en inglés q luego nos regañan bn culero
Ok so
That was my error
Sorry
Xd
@lucid prawn try this:
let user = message.mentions.member.first();
Or msg
Idk how did you define the message
yea that
I usually use message
althought i never use the await i always make my commands as an async function
like client.on('message', async message => { Some code });
Today i tried to use guild.displayAvatarURL();
Lmao
That was an epic error
"guild.displayAvatarURL is not a function"
Lol
like this
if (User == null) {
return message.channel.send(`You did not mention a user!`);
}
Wait
Why nullM
just use if (!User) {
And pay attentios for cases
JavaScript is case sensitive
Attention*
Lmao
i fix it
look
if (message.content.startsWith(prefix + "slap")) {
if (User == null) {
return message.channel.send(`You did not mention a user!`);
}else{
var embed = new Discord.MessageEmbed()
.setDescription(message.author.username + ' slapped ' + message.mentions.users.first().username)
.setTimestamp()
.setImage('https://media1.tenor.com/images/af36628688f5f50f297c5e4bce61a35c/tenor.gif?itemid=17314633')
message.channel.send(embed);
}
}
What did i say about that null?
And the user var must be defined at the same if
Why var
And not const
The same thing on this case
var, let , const
Nope
They are not the same
It gonna be a local var, it's not neccesary to use const
I believe
🤔
Its better practice to use const lol
Is your choice @lucid prawn
Now what did i say about that null
i will fix the null part
It's better to use !user and not user == null
ok
this is what i pulled from various docs, if you're still wondering const vs var vs let
Ik that const's values cannot be changed
on another line i mean
Does anybody use oh-my-zsh here?
some one know free node js hosting?
lifetime
other then heroku?
Can someone help with this error? i am trying to make a "say" command and there is an error is "let" Error: They keyword 'let' is reserved.
Hm?
Now there is an error in "args"
why
const
'args' is not definded.
hOW?
🤦♂️
I'm sorry I'm dumb idk.
hm? Just put that above?
args is not in code
Okay, read the guide. https://discordjs.guide
Specifically this page
nonono, never.
why?
there really isn't a difference
except var is function scoped and let is block scoped
what
?
also, you should get a linter
uhhh
Someone is probably going to pop in here complaining their music bot doesn't work - youtube reverted a change (sometime in the last 7 hours) and now the last working version of ytdl-core is https://github.com/fent/node-ytdl-core/releases/tag/v4.1.4 - so yeah. just use that for the moment. xoxo - aj
saved you an hour of headache
mine is just fine, v4.1.5
Uh oh
if anything, my quality is better
using cleverbot.io?
No
lol
I'm trying to create a webhook server to catch votes and stuff from Top.gg for my Discord Server listed on there.
I've tried Ksoft.si, and DBL Vote, but they don't really meet what I am looking for.
I want to code a webhook system into my Custom Discord Bot for the Discord Server using express or whatever.
I've taken a look on google but it doesn't really help.
Can someone point me in the right direction?
i don't know why would u suggest that
let is equivalent of var. ES6 buddy
var doesnt respect the scope let does
found 1 moderate severity vulnerability
run npm audit fix to fix them, or npm audit for details
how do i fix this while installing dblapi.js?
i ran npm i dblapi.js
hey guys how to display author pic in .setauthor i tried displayurl and avatarurl but it doesn't work
oh right, i was looking at thumbnail, sorry
use @discordjs/opus
Hi so
umm
Idk how to explain this
but
On starting bot
I get this error
just node .
Can anyone give me a css code for this?
Can you have the will to learn?
Also, you can use your browser's developer tools to get the CSS
Anyone? sorry for being impatient
yes
ok
onst interaction = new DiscordInteractions({
applicationId: "",
authToken: "",
publicKey: "",
})
interaction
.createApplicationCommand(command, "774875404698910731")
.then(console.log)
.catch(console.error);```
I am trying to make a slash command
so
maybe
thats why
the / commands
like /nickname
No
Leave it
Thanks for your help
No it won't help
I was trying to do something which breaks TOS
But now I won't
thanks
const Discord = require("discord.js");
const User = client.users.fetch('302050872383242240');
msg.channel.send(User.id);```
Users are cached
u cant break tos
what breaks tos?
So how to fix it? ;3
with this;
client.users.cache.get("302050872383242240")
or fetch
i forgot which one
so;
const Discord = require("discord.js");
const User = client.users.cache.fetch('302050872383242240');
msg.channel.send(User.id);
@elfin tulip with fetch you have to use await
the code you used is correct, you just forgot to await it
it's users.fetch(), no cache
#development message only works if the user is cached
I recommend using fetch() since it looks in cache first and try to fetch it if it's not in cache
const Discord = require("discord.js");
const User = await; client.users.fetch('302050872383242240');
msg.channel.send(User.id);```
@tight plinth so like this?
yep
well I dont think you'd need to put a ; after await <_<
SyntaxError: await is only valid in async function 
wait you can color text in Console API?!
Use ANSI escape code?
You need to put that in an async function or use the old syntax. You need to read more about Promises and async/await...
All guilds unavaialble
const client = new Discord.Client({ ws: { intents: 'GUILD_MEMBERS' }})
is this wrong way to define it ?
use the guilds intent too
it isn't a privileged intent
no it is not
I made a reload command for my bot
It is exactly the same as my command handler loading commands but for some reason it never works smh
No errors thrown in console nothing happening
Code for my command handler: https://hastebin.com/izefocebod.js
Code for my reload command: https://hastebin.com/holalufome.typescript (bruh hastebin that's not typescript)
Yay it worked
have you tried console.logging through your code and seeing where exactly it just refuses to work
not yet
but it should throw promise rejections or shit
hm
but how would i console log an entire chunk of code
you wouldn't
i think i got it
for (let filename of fs.readdirSync("./commands")) {
let data = require(`./commands/${filename}`);
bot.commands.set(data.name, data);
}
you would place a bunch of console.logs throughout the code
fs is not required anywhere
ah
but how it doesn't throw an error idk
is execute awaited?
nope
it's getting swallowed then

This article has kindly been turned into a video by the folks at Webucator who do JavaScript training. When dealing with asynchronous code, JavaScript’s ES6 promises can make your life a lot easier. No more callback pyramids, no more error handling on every second line, and no more reliance on external libraries to do things... Continue reading ...
so the errors are thrown but the Promise ignores them?
kind of yeah
Fixed it! Thanks @dreamy gulch @zenith terrace @tight plinth
const Discord = require("discord.js");
async function storejson() {
const User = await client.users.fetch('302050872383242240');
msg.channel.send(User.id);
}
storejson()```
why was i mentioned
lol
but if I await it wouldn't it make my main thread busy
but no problem!
h
chain .catch onto execute
oof sorry
ok
Cause why not
.catch((e) => errorHandler(message, e))
also everything is running on the main thread in node

moment
bruh
Then how're you sending message ?
Maybe misspelled discord and Discord
because message.reply is an HTTP request
not smth that requires discord.js
also @pale vessel WHY U LIE TO ME THAT IMPORTED PACKAGES CAN ACCESS VARIABLES IN MAIN FILE

message can't be defined if no Client
Client can't be defined if no Discord
are you embedding ?
show code
It's just error in MongoDb so I am gonna send the MongoDB part k
bruh
what happend
you can access it through functions
let newData = new welcomeinfo({
const welcomeinfo = require('./models/welcome.js')
GuildID: reply.guild.id,
status: "yes" ,
channel: channel ,
message: welcomemsg
})
newData.save()```
My Code
My schema
```js
const mongoose = require('mongoose');
const setwelcome = new mongoose.Schema({
status: {
type: String
},
channel: {
type: String
},
message: {
type: String
},
GuildID: String
});
const MessageModel = module.exports = mongoose.model('welcome setting', setwelcome);
@near stratus
I will send whole code in hastebin just a sec
no need
I think I already got the problem
lemme be sure
Okk
Do you need assign the model to MessageModel 
Last line?
yeah
of this
F
:(
where did this come from
Hold on,
that was inside
is my nick back?
No no in code it's fine
If I have an Emoji object:
let emojis = [...message.guild.emojis.cache.values()];
for (let emoji of emojis) {
// ...
}
How can I convert it to a GuildEmoji object?
I tried doing:
emoji = message.guild.emojis.resolve(emoji.id);
But it didn't work
But they ARE guild emojis?
smh nope
emoji.author is undefined which should be for normal Emoji objects but not for GuildEmoji or ReactionEmoji
the author just isn't in cache
lol
shouldn't it be null instead of undefined
It should be null yeah
also why are you spreading values() into a new array
Yeah just put it in the for loop
Since .values() is iterable
You don't need to put it inside an array
bonk typescript for saying that'll throw an error
i guess it doesn't handle Iterator objects properly
you should just be able to use for of
in ts, do you push the compiled code to github or do you leave it empty
transpiled*
and you just push your ts code
for a library, if you've got dependencies set up properly, you should have a build script that just runs tsc
transpiling is just transforming your code to another language that's similar in nature
Compiling is like java
Making the code into an executable
ok that makes sense
compilation is compiling high level code into low-level code, something that would be annoying to code by ourselves
so we let the compiler do it for us
@mellow kelp posted my ts code on github so if you want to rate my code
I didn't do anything wrong did I?
o
same, my mac is dying rn
oof
install node
^
i already did
try restarting vscode
^
sometimes that makes recently installed commands work
when an item gets added to PATH you need to reload the thing that uses PATH
or just delete the PS
because its a new powershell terminal
and if you create a new one it should have the updated PATH
yes thank you
no prob
(node:14864) UnhandledPromiseRejectionWarning: FetchError: request to https://discordapp.com/api/v7/gateway/bot failed, reason: read ECONNRESET
What does that mean?
The bot won't start.
that means an error when connecting the bot
i don't remember what econnreset meant but it's somewhere on the internet
nah dont think so
K! 👍 Phew..
Does someone knows how I can get image url dominant color?
Wdym?
maybe you can use canvas
to draw the image and get pixel data
const m = await message.channel.send(embed);
^^^^^
SyntaxError: await is only valid in async function
I'm not mistaken, but it is in an async function
But the const m = await message.channel.send(embed); is in an (if..) statement, does that affect anything?
nope
you sure the last function before it is async?
it won't work if it's on a not-async nested function
Ill check something and reply to you.
ight
Hm.. didnt work
The last thing before it is this. module.exports.run = async (bot, message, args) => {... all the stuff here ... }
Not sure why it's not working
share your entire code
const reactions = ["🙂", "😀", "😄"]
module.exports.run = async (bot, message, args) => {
Data.findOne({
userID: message.author.id
}, (err, data) => {
if(err) console.log(err);
const noAccount = new Discord.MessageEmbed()
.setColor(colors.red)
.setDescription("❌ You do not have an economy account, be sure to create one by performing the **`!register`** command.")
if(!data) return message.channel.send(noAccount)
// Perform the command here...
const embed = new Discord.MessageEmbed()
.setColor(colors.cyan)
.setTitle("Available Lootbox")
.setDescription("These are the available lootboxes you have in your inventory. To open one, be sure to react with one of the reactions below. ")
.addField("Loot Box", [
`**🙂 - Mystery box:**`,
`**😀 - Attitude box:**`,
`**😄 - OP box:**`,
])
//.addField("Current lootboxes left", `After opening this lootbox, you will have ${data.mysteryBox} left.`)
const m = await message.channel.send(embed);
const reacted = await promptMessage(m, message.author, 30, reactions);
await m.delete(embed);
if(reacted === "🙂") return message.channel.send("Hello1")
if(reacted === "😀") return message.channel.send("Hello2")
if(reacted === "😄") return message.channel.send("Hello3")
})
}
does findOne not have an async counterpart?
you got a nested function on Data.findOne
What can I do?
You could just turn it async
make the callback async
Since it doesn't have to return anything
or you can promisify findOne and avoid the callback approach
yea
async findOne?
ah wops.
use await with a promise instead
Ohh, but I'm just trying to know, How can I async the data.findOne thing?
read the doc link i sent you
Alright Thanks!
But wait, the Data.FindOne is the code to the database, I can't change that.
it... doesn't matter
it should have a promise alternative to callbacks
if it definitely doesn't, just make the callback async
oh shoot i made a recursive thing and my vscode debugger crashed
So if I had this code only ```js
Data.findOne({
userID: message.author.id
}, (err, data) => {
if(err) console.log(err);
if(!data) {
const noAccount = new Discord.MessageEmbed()
.setColor(colors.red)
.setDescription("❌ You do not have an economy account, be sure to create one by performing the !register command.")
return message.channel.send(noAccount)
}
Oh wait, k, Ill work through it, I understood a bit.
I just copy pasted the code, I didn't do anything
👍
if not its still gonna execute the code after it even if theres an error
How i can get the video formats with the link (youtube link)?
wdym video formats?
hmm
is the first format of the array
what object is that?
do you know any npm I can do it
npm install canvas
i dunno if that's possible
but there might be some package for that
Yes but any other? easier one?
well i don't think there's one to directly get the color of an image
but maybe sharp can help
shouldn't be too hard with canvas tho

hi do we have any bot for custom leaderboard?
What about this? https://www.npmjs.com/package/color-thief-node
so what did you think of my code, or havn't had a chance to check yet?


its kinda annoying how there is no requirements for a npm package
not yet 
kids make some discord-embed-generator or something and use shit code and boom their package
i made a package that converts images into ascii art
LOL
it was pretty interesting ngl
now that seems useful
nice
try npm i -g ascii-converter
how do you do command line interfaces?
and run ascii on some folder with pictures
some packages for that are chalk and inquirer
chalk for loggin colored text
and inquirer for asking questions
o
o
you gotta add a bin property on your package.json
{
"bin": "./src/index.js", // If your command is the same as the package name
// or:
"bin": {
"custom-command": "./src/index.js" // If you want another command name
}
}
ye
jason.db command
and you need to add #!/usr/bin/env node to the file
imagine
lmao
im finding to do like the animated background thingy
a cli to manage some json files
I accidentally hit my phone super gently on my bed and the whole thing restarted and the battery went down by 36% fuck you samsung
you should add that?

And the vote requirement
good idea 👀
yes
@mellow kelp comments in json wait thats illegal
perhaps
MIT
ok
Thats the one you had on ur package.json
alright
Hello anyone knows how to do the animated background thing
and thats the story of how i got into the contributions section
Like this
yes
alr lemme see
good contribution
im about to make a PoggersCollection
its gonna store stuff in some kind of special encoding
i use firebase real-time database to store user data (emojis, user IDs and names, and that's it) is that allowed or do i need to do some hackery to encrypt it
which relates to poggers
hmm
Did you see it?
you should probably hash passwords
There are no passwords
then i dont think theres any encryption stuff needed
ok
Use vlc media player
