#development
1 messages · Page 1821 of 1
presence intents gives u data about statuses of users and events
server members intents gives u guildMember data and events for eg. guildMemberAdd (im reffering to djs)
only choose the intents u need
they’re talking about embedding their website into their description, they mentioned it earlier in #support
not seeing anything in the api reference about embed buttons, where could i find that? using dpy
why cant i do this?
i can use that feature everywhere else so i must be using it wrong here
it's happy with this
what does the double question marks do
Basically if the left hand side is null or undefined it’ll use the right hand side instead
|| is different
If the left hand side evaluates to 0 or false it’ll use the right hand when using ||
Or NaN
yes
Null coalescing is just null or undefined
they're different
const a = 0 || 1; // 1
const b = 0 ?? 1; // 0
that's pretty much the only difference
so false dosen't count here I see
|| checks for any falsy value, not only null and undefined
^^
?? only checks for null and undefined
I get it now
so it's kinda useful
Yeah
Especially for false values
const myVar = false;
let result;
result = myVar || true; // result = true here
result = myVar ?? true; // result = false here
Hello I would like to add a video on the page of my bot but when I add a video it is extremely large how can I make it decrease in size?
Use css to change the width and height
Is there a way to check whether a server has enabled two factor moderation or not using djs?
https://discord.js.org/#/docs/main/stable/class/Guild?scrollTo=mfaLevel will be 1 if it's enabled
can anyone help me?
I am making a website and with a body how do i make it so the font can change on the same line?
Use the style tag or attribute
how would i make it so one body is a different font to another?
im quite new to html
can i ask a question about mongoose?
just ask 
What should I search on YouTube to make this?
"markdown tutorial" I guess
is it possible to edit the style of this sort of thing: <a href="page.html"> Page</a>
Anyone have some basic docs of how to use the new v13 discord.js menus?
Or do I just go in blind?
There isn't an example but docs for it https://discord.js.org/#/docs/main/master/class/MessageSelectMenu
which menus?
Context menu
app.use(cookieParser())
app.use(cors())
app.use(express.urlencoded({ extended: true }));
app.use(express.json({
type: ['application/json', 'text/plain']
}))
app.post("/api/user/submit", async (req,res) => {
....
res.cookie('user_id', "123456")
res.json({ success: true })
})
this does not set the cookie in my browser, im using localhost rn
my frontend:
fetch(' ... /api/user/submit', {
body : JSON.stringify({
user_id: response.id
}),
headers: {
'Content-Type': 'application/json'
},
method: 'POST'
})
If you talking about selectmenu
cookies are confusing the hell out of me
omfg i love this website
Helped me a boat load
You just eat them 
does anyone know how to work with cookies
You need dough
Maybe try js res.cookie('user_id', "123456") .json({ success: true })
uh, there it is if bout sites : https://www.w3schools.com/js/js_cookies.asp
Not sure if it makes a difference
thats setting the cookie in frontend
im trying to do it from the backend

Ah right
You can't set cookies in localhost
Test it on a proper server with a domain
Ok
What is this error about?
(node:114481) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)
11 message listener might be you making client.on('message',...) 11 times
Which is bad idea
what
how tho
I do be learning
I already made a settings type thing using discord-buttons
Really fun
But I dont think users would really like a random package like that
discord-button doesn't support mster branch I think, and yeah. 3rd party is not good.
Yeah, thats why I am gonna recode my bot
Will also have to switch the db thing, because I dont think keyv really likes node v16
keyv got vurnabilities, switched to enmap
I think enmap have much more features for discord bot than keyv
Not really, all the average discord bot dev needs is add, remove, and fetch
Dont exactly see the need for more functions
But then again enmap was created with discord.js in mind
The math function make me easy to navigate back and forth result of images from duck duck go
you realistically shouldn't even be using them as production databases
by using them you're completely ignoring the power of your database
(and optimisation)
Well, Im young and dumb and just want to do it the easy way
Can anyone give me the steps that I need to follow to implement Discord login in a website.
Atm I can't understand when and where to do the code challenge
boy it's a little complicated if you want to make your own stable and efficient version of it but there is a thing called passport discord which does that with express
I'm using nuxtjs js and it's auth module for frontend, my issue is that I'm not understanding when I should use the backend to do the code challenge
I use kotlin for my backend btw
the code challenge? do you mean it literally or do you mean the code discord sends you
discord responds with a code and I need to challenge it to get an temporary access token to retrieve the user data from what I understood
challenge would be the wrong word to use but I understand
Can you just explain me the flow I have to follow
Cause I'm not understanding how should redirect back users to the website in the backend
can you access the code from your backend?
I never really dove into client side rendering much with states like this but you should be able to send the code to your backend via http, the backend then needs to make a request to the discord api (I'll get the relevant urls in a minute) to perform a token exchange (a token is what will let you grab the users info) from the code and then you make another request to grab the user details and send it back to the frontend
there's discord api libraries for java that let you query the discord api
or you can do it yourself
issue is, how do I send it back to the frontend?
I need to request it from the frontend
But the timing for that is not clear
I assume you're new to web development?
<a href="index.html">HOME</a>
<a href="edits.html">MY EDITS</a>
</div>``` How can i make this so it will put a gap between each one
not too much
but never done oauth before
this is mostly basic JavaScript but since you're using nuxt you should use the dedicated method for it https://nuxtjs.org/docs/2.x/features/data-fetching
I know how to fetch data from APIs via axios
the issue is the timing
like, how much I have to wait before asking my backend for use data
I don't think that it should just be a timeout
'cause I do the code challenge in the backend to get the access token
And I need to get that access token from the frontend
then with that I can make requests to the discord api in the frontend
Hello. 👋
hi
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
I have this array.. and I use the map method to map it to log every value.
console.log(array.map(x => x));
.. now I want to make 2 console logs whereas the first one shows the first 5 and the second one shows the rest.. is that possible? .. and if there is no rest.. it would return.
split it by 5
Kind-of a paging system.
idk, im not a person from JS ||and currently im busy cause of writing mine bot||
Bruh.
ye...
there shouldnt be any manual waiting time
use promises instead
I still don't understand what I need to do with the Discord code and where
const mappedData = Object.keys(inventory.inventory)
.filter(key => inventory.inventory[key] !== 0)
.map((key) => {
const { name, id, logo } = items.find((val) => val.id.toLowerCase() === key);
return `${logo} **${name}** ─ ${inventory.inventory[key]}\n**ID:** \`${id}\``;
})
.join("\n\n")
embed.addField("Owned Items", mappedData);
.. now this will keep doing on and on and on.. is there some way to make it show 5 every page/embed?
chunkify it
What do you mean?
so I followed the turoreal of making a form feeling out with express on https://www.tutorialspoint.com/nodejs/nodejs_express_framework.htm , But I get error cannot get index.js.
My files look like so:
Node.js - Express Framework - Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitate
I can show you how I do in java, but you'll need to convert that to js
never mind I mispleed html.
That won't help, but thanks anyways. 😊
the user visits the discord oauth2 url
the user logs in
the user is redirected to your redirect url with a code
your redirect url should run a script in your backend that sends the code to the discord exchange url
the discord code exchange url will take the code and give you a token
do something with token
I'll try.
How do I send the token back to the frontend?
basically, you split the whole into smaller parts
if the user was redirected, you redirect the user back to the frontend with the token
if the total count is not a multiple of the chunk size, gather the remaining into their own array
if the user was redirected in a separate window, then the separate window has to close itself and return the token to the main window
I'm supposing the user always stays in the frontend website
and from the website I make an api call to the backend with the code
after you have the chunks, just do .map(c => c.join("\n\n"))
where does the user login with discord? in which window?
on my website
because the login with discord is already not your frontend
then the backend should send back the token to the frontend but don't know how?
same window of my website
the moment the login with discord window appears, the user is not on your website anymore
yeah
he was redirected to the discord webside
then redirected back to the discord redirect url
You can use reduce and the modulo operator
so you have to redirect the user back to your main website, with a token in the url for example, or in the cookies
then on the front end use js to extract the token
My backend doesn't have any viewable page
So what does the user see when I redirect them to the backend?
I'm so confused
the user sees a double redirect
so:
- redirect user to discord auth
- discord auth redirects user to backend (blank page?)
- backend uses the code to get the token and redirects the user to frontend with the code in url / cookie, but how?
the user doesnt see a blank page
oauth2 in a nutshell
the user sees the browser loading, and the address bar changing twice
oh you let the backend do everything?
partly, yes
that's not what Tim is saying do right?
in the backend it would be like return 301 url?
ye
so it's basically just a get request?
yes
So here I should put my backend endpoint
which will do everything and then redirect the user
discord does the redirect to your backend, which means your backend received a get request from the user after they are redirected
you dont need 2 urls btw
I was just testing there ye
And where is it advised to store the token in the frontend?
depends how long you want it to be valid
I mean for security
discord stores it in localstorage
How should I handle the expiration instead?
uh, idk
ye
but the weirdest bit is the fact that it doesnt happen every time

and i know enough about javascript to know there is nothing wrong with this
i use firefox and never got this...
not the brwser
idk
this is really strange
check inspector and check if sometimes u didnt putted there some invisible "ascii art"
nothing shows in inspector tho until i press OK
check characters, maybe ur keyboard is modded and there is ascii art between characters
its not
im on a standard uk keyboard
but then it would show every time aswell, but it doesnt
no, i was saying about characters invisible, because u might idk. got hacked or smth and it puts invisible characters into text
but i tested it just adding the text into there without it being a const and its fine
then idk
but its because later i will make it a variable and sort out a form so i can change it on the website
empty charcters
??
<script>
const MontagePrice = '£5.00';
const IdentPrice = '£3.00';
alert(`A Fortnite Montage costs ${MontagePrice} and a Custom Ident costs ${IdentPrice}.`);
</script>``` nothing wrong here
this⠀message⠀is⠀without⠀real⠀spaces
im so confused on what has happened 😐
utf8
?
check ur content with this: https://www.browserling.com/tools/text-to-ascii and compare to real ascii chars
weird characters are normally a result of wrong charset
<meta charset="UTF-8">
add this to head
but it works when i change const to let
see if it works
<script>
let MontagePrice = '£5.00';
let IdentPrice = '£3.00';
alert(`A Fortnite Montage costs ${MontagePrice} and a Custom Ident costs ${IdentPrice}.`);
</script>``` it works like this
thats just weird
just try it, you should have the charset set to utf8 anyway
it works with this
is it the same?
<script>
let⠀MontagePrice = '£5.00';
let⠀IdentPrice = '£3.00';
alert(`A Fortnite Montage costs⠀${MontagePrice} and a Custom Ident costs⠀${IdentPrice}.`);
</script>
maybe £ is charset-dependent
you should use utf8 anyway since it's basically the new default
or use unicode hash
it is working now
they just didn't switch fully to it because retrocompatibility
Is this a good vps for bot hosting?
bug i have on the myself - why this something throws "ctx undefined?!"
@bot.command()
async def chmod(ctx, arg1, member: discord.Member):
if arg1 == 0:
await ctx.channel.set_permissions(member, view_channel=False)
elif arg1 == 1:
await ctx.channel.set_permissions(member, add_reactions=True, view_channel=True, send_messages=False, read_message_history=False)
elif arg1 == 2:
await ctx.channel.set_permissions(member, send_messages=True, view_channel=True, add_reactions=False, read_message_history=False)
elif arg1 == 3:
await ctx.channel.set_permissions(member, send_messages=True, add_reactions=True, view_channel=True, read_message_history=False)
elif arg1 == 4:
await ctx.channel.set_permissions(member, read_message_history=True, view_channel=True, send_messages=False, add_reactions=False)
elif arg1 == 5:
await ctx.channel.set_permissions(member, read_message_history=True, add_reactions=True, view_channel=True, send_messages=False)
elif arg1 == 6:
await ctx.channel.set_permissions(member, read_message_history=True, send_messages=True, view_channel=True, add_reactions=False)
elif arg1 == 7:
await ctx.channel.set_permissions(member, read_message_history=True, send_messages=True, add_reactions=True, view_channel=True, attach_files=True)
elif arg1 == "mod":
await ctx.guild.set_permissions(member, administrator=True)
else:
return
•~•
what the holy fuck???
ctx undefined after sending "$chmod 4 (user)"
godzilla dead after this
full error:
File "main.py", line 23, in on_message
await ctx.process_message(message)
NameError: name 'ctx' is not defined
•-•
and which one is line 23 ?
here is 11 line
i just copied err from terminal, so 23, here its 11
and there is (ctx, args) in async...
~_~
redis stores in memory 
redis is mostly a cache if anything
no, why would we?
nope, just thinking on smth
noice
but im not depressed 😉
so like can i use quickdb with grafana?
good 😉
for grafana i only see promtheus or loki
thk
does grafana support sqlite?
means?
oh it does
not sure
find where the sqlite file is generated
i want something like reading directly from a file on the machine
wait quickdb uses sqlite?
now a bot based on linux and made in python =p
and u?
quickdb is a sqlite wrapper
yes
it's not a db in itself
but the api does support variety of languages. I made mine from js
mine → .py (js scares me)
lol
xd
ye it can get bit complicated
yea, and generally - weird
but i am certified game dev in js so easy for me
js is like the easiest language ever created lol
i also was but i was cheatin (gdevelop, scratch, etc...)
what else you like to develope?
yes
like
yk that dino game where you jump around?
websites sometimes but without backend
scratch be like: am I a joke to you?
ik
yes lol
ye so that is totally made up of js
nothing else
i recreated it from scratch my self
hmmmmmmmmmmmmmmmmmmmm
scratch.com , this i meant
i like to dev websited a lot
(and in the reality im not even a dev - everything i know is only css, html and from about 2 months python :'D)
you're a dev then
ye
i dont think so 😂
knowing any kind of language makes you a dev
?!
yes
you code -> you're a dev
😳
you literally know 3 language
you don't need certification nor official entitlements
you coded something right?
html isnt lang
webdevving is coding
bro
Google basically pays a lot
just for web desing and stuff
yea
yea
html is considered declarative programming
eee ?!
so technically it is a programming language
TECHINCALLY but noone accept that as lang 😉
more like a structuring language
yea xml i also know. sometimes i also make ios shortcuts if about
this is a tree, tree has branches, branches have leaves
yea
then js comes: tree does X, branch does Y, leaves do Z
css says: tree is brown, branch is thin, leaves are green
e-e i dont understand this $#1t yet (means - js)
im more a graphic than a dev 😉
and how i understood .py - idk yet 😂
?
its simpler than a turing machine, it cannot represent itself like a turing machine can
?
therefore it is finite
it means it can be used to program only a subset of things
ye
it cannot program inifinite things like a turing machine can
a turing machine is the first computer ever made
wasnt it eniac?
a "turing complete" language or system is something that can do anything, including recreate itself inside it
idk also 😂
use iframe
yea ↑
quirky never saw someone add their dashboard to their bot page
where?
the idea is great, the execution not so much
the result? even less
longdesc
fast question (i dont want to stay weeks in docs again :'D) - how to get role from ping in argument? google shows me only how to ping roles via bot. what if i want to have role ping as argument? i know that user ping is discord.member ...
in which library?
You can annotate the arg with discord.Role if you use its command handler.
means?
message.role_mentions
i make smth like (ctx, arg1, user = discord.role) , yes ?
Not = but :, and it's capital R.
nvm but a good way?
Wdym?
that i just make a cmd for managing perms and doesnt work on users so i started messing up with roles =p
anyways - thk
testing now 😉
ey, and is this possible for bots also, not only real users?
cause seem broken
not ignoring bots is usually a bad thing
means? i just need to test on something
https://sourceb.in/vZX59L7ldj why is this ready.js making this error:
(node:117758) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)
bots can be legally automated, thus causing massive spam of commands by malicious users
no, this wouldnt be spammy cause this only manages roles =p
i just brang chmod to discord and made something like $chmod 0 @someone and this block user for example
or $chmod 7 @someone to give him ability to share files
Well that's still an API request
developer site to solve bug?
there are some toggles to which over 100 servers require verify so maybe there is smth like that
Privileged intents? Don't think you'd need that to edit permissions.
like getting user list
user list does require
verify, yes
but mentions automatically cache the user
I think I lost the context, what was the error?
Seems a code problem
and code not working this (before i was thinking that ctx is broken but it was for another thingy) :
@bot.command()
async def chmod(ctx, arg1, member: discord.Role):
if arg1 == 0:
await ctx.channel.set_permissions(member, view_channel=False)
elif arg1 == 1:
await ctx.channel.set_permissions(member, add_reactions=True, view_channel=True, send_messages=False, read_message_history=False)
elif arg1 == 2:
await ctx.channel.set_permissions(member, send_messages=True, view_channel=True, add_reactions=False, read_message_history=False)
elif arg1 == 3:
await ctx.channel.set_permissions(member, send_messages=True, add_reactions=True, view_channel=True, read_message_history=False)
elif arg1 == 4:
await ctx.channel.set_permissions(member, read_message_history=True, view_channel=True, send_messages=False, add_reactions=False)
elif arg1 == 5:
await ctx.channel.set_permissions(member, read_message_history=True, add_reactions=True, view_channel=True, send_messages=False)
elif arg1 == 6:
await ctx.channel.set_permissions(member, read_message_history=True, send_messages=True, view_channel=True, add_reactions=False)
elif arg1 == 7:
await ctx.channel.set_permissions(member, read_message_history=True, send_messages=True, add_reactions=True, view_channel=True, attach_files=True)
elif arg1 == "mod":
await ctx.guild.set_permissions(member, administrator=True)
else:
return
ye, intent-related errors would thrown something to the console
See, arg1 will always be str, it's never gonna be int.
means? i need to make "1" everywhere? ok
So, it's most likely been getting to the else block
but "mod" is string.... and also doesnt work
leading/trailing spaces
and spaces ok
and for the love of god use switch-case
Don't think Guild object has set_permissions method
means? there is no "moderator" perms for only one channel 😂
You need to edit the role instead
:/ ok
Try something like: await <Role>.edit(permissions=discord.Permissions(...)). I can't test it as I don't use d.py anymore
jeez quickdb is fkin ambigious
ok, thk
they dont even have proper instruction
plus there's an error on the first 2 lines of the package
lol
instructions as in documentation?
const db = quickdb('./json.sqlite');```
it says quickdb is not a function
xd
yeah
documentation
there's no resource to how to delete table
get all contents
delete all contents
bruh moment
what if role is a variable from input?
Doesn't matter, <Role> there was just a placeholder for a Role object
let/const
ah, ok
its just an example lo
variable = require... doesnt exist
i used let obv
I don't see that quickdb(something) anywhere in the docs
yeah wait i think it was an outdated one
i dont think so brother
thats on a table
day 1 of scraping data
have i done a good job?
this was one with the quickdb()
@rustic nova
lol
actually i dont know because quick.db doesn't seem to expose the database object
i dont see any raw query on the docs as well
yeah
there's no way i can change the filename also
im stuck with 1 file being filled with everything
you'd probably have to fork it, edit it and install your own version
i think i did that before when i wanted a quick database
i'd rather just spend that time on loki lol
nah it's like a 1 line fix
quick.db was actually easy and simple but these problems oof
no i need like multiple files
but if you're going to be using raw sql you might as well just use better-sqlite3 or something like that
to store data
ah
why though aren't multiple tables enough
yeah like im mainly using it for logs
there's no reason to use more than 1 database file
hi
yeah, but im using it for 2 purposes
logs and storing sort cache which would be long term which i dont wanna store in redis
xy problem at its finest
yep
uh
hi
i gotta sac mem for sorting or store the sorting data in db
which i dont wanna make multiple calls to db to get the sort details
so thought quick.db would be easier
store logs is prio
but i also prefer fragment files
since i can sort them according to log levels
i need these logs to check transaction history
so
also prefer to rotate them every 7days
or so
so you want different sql files to store different levels of logs
cant you just use something like https://npmjs.com/package/sequelize
allows you to use sqlite and abstracts sql completely behind objects
for postgres?
i joined their server
dw
they also dont know what they doing lol
i asked around
well you cant expect much from a module like quick.db
Err: it is not unmuted aka not removing the role
it practically takes away the power of sql
wait so i have to build out the sql connection
?
and create a sqldb
to use seq and sqlite
i think you're a little confused
i've used sequelize before with postgres
not sure if i need a db connection with sqlite
...
sqlite works with self-contained files, so it doesnt need a database server running independently
so no config needed, i can just directly use seq + sqlite
yes
this is why sqlite3 is popular hehe
noice, let me give it a try
channel mooted - db spam again
chanel
moot
they could optimize their queries a little bit more
or just do the queries yourself
chanel renamed 😉
yeah but when your whole infra is already in sequelize it's difficult
seq package is huge for my use
i mean i can overwrite the methods myself but it's the kind of bodging i dont like
the outcome is suffer either way
anyway, how do i write raw query in qdb?
in quick.db? you dont
you cant they dont expose the sqlite client
bye from this channel
you'd have to fork it
someone pls help
i mean
i can jsut switch branches
quite stupid of them but what do you expect
you can just use any sql lib and open the same file that quick.db creates
and use them side by side
one for raw queries, the other for the rest
ugh
two sql files open at once 🤮
mm, ig i can use that file in sql client and clean it up
those database locked errors looking tasty
😂
(unlikely for your use case)
well all i'd use is delete table query anyway
you'll only get db locked error if your queries take longer than that
wait i hope i can filter stuff with qdb? with a where clause or something
i love how the query for deleting tables is "drop table"
yow
which is terrible
bruh
but i guess i can just use the sqlite file
your use case is clearly not fit for quickdb
lmfao 😂
gonna drop my 10 million row table
lol
and will wait for myself to be dropped
wat?
imagine getting isekaid
u wanna be deleted?
?
weebs
who?
lol
?
lmao im out
why?
doesnt yet work. no errors in terminal and also modlog in server empty
•~•
Well, seeing you didn't get any error while accessing a non-existent attribute before, you error handler is likely messed up
idk but now logged in modlog 😉 so smth better
asap offtopic a little question - how to split words in a file by a NEWLINE ? it does by spaces defaultly... (again python)
How to create webhook requirer in heroku?
=[
-_-
oh, thk
python has so many utility methods at your disposal
ik

•~•
Hulo
?
What do you guys do here
bruh....
We copy bots off YouTube videos
yea 😉
I see..
me||e6|| too
lol
xd, u noticed?
welp if that helps you learn then why not
i dont watch yt but if he does...
i never really learnt coding. i just copy from docs and ask questions
-_-
and smh it works sometimes
I learned from doing small projects and looking things up as I went.
Starting big and complicated projects will get you burned out as a beginner
for me smh didnt, i yet sit on .py 😂
Often times complicated projects require complicated solutions, that may make you feel overwhelmed at first
That's why (in my opinion) it's better to start small and work your way up
so i left hard things and now im doing a little smaller
so umm
?
idk why grafana throws permissions error while im trying access the sqlite file
with the abs path
I can do coding..a little
means me or hoax?
what
Can you show the error and the code you're using to access the file?
its the grafana UI
$kill 266457718942990337
where i have to specify the absolute path
Never used grafana
this the error i get
$kill 173489654144696320
:faceplm:
$kill 266457718942990337
What are you doing @brave garnet
no lol that's a grafana prefix for status
trying to kik u both
idlerpg
wew
Commands don't even work in #development anyways
?
Bot commands
ok
"i think"
ik
it was just to stop next spam conversation again... its 5 time today with same question....
Spam conversation?
not possible cause i use this channel sometimes
i never moote, only generals i have mooted cause there is yet bigger overload
Is google down?
sounds like a bad idea ¯_(ツ)_/¯
nope
weird
if it was, discord would be suffering
yea...
Its weird cuz I can't connect to google or youtube but everything else seems to work
Also can anyone help me with this?, inventory is a map of type: <Map<material, number>> new Map(this.itemIdToItemObject(data.materials || {}, materialIds))
already did
it happens on both chrome and opera gx
we don't ping Tim here
did u checked firefox?
Tim helps if he wants
dont have firefox
true
-_-
whats the issue
im getting a permission denied while using grafan with sqlite
like it says it cant read the sqlite file
in the abs path
idk if i should use the ip or something there?
is the sqlite database on your local machine?
local machine or server?
server
wellp, I can't rlly help much with this tbh
welp
amazing
we pray, tim shows up
May you show the entirety of the code in that screenshot?
sure
google is down in belgium, none of my devices can connect to google
Why will Map.prototype.has ever take never as a param type?
public addItemsToInventory(items: {itemid: material | consumable, amount: number}[], profile: profile, fit: "materials" | "consumables") {
for (const item of items) {
let inventory = profile.inventory[fit];
let currentValue = inventory.has(item.itemid) ? inventory.get(item.itemid) : 0;
profile.inventory[fit].set(item.itemid, currentValue + item.amount);
}
}
I have no clue
ahh
not this
Did you define your map as :Map<never, any>?
:/ uh
It doesn't, TS decided that the code is unreachable, giving it a type of never
Now spotify is down too 😦
yet worse...
how is it unreachable tho?
idk
prob due to the heavy storms we had today
maybe 😉
Can you send a screenshot of the entire code?
The entire code? It's just a class that doesn't interact with the map in any way tho
So u won't have use of it
The code is what's causing the error soo
It probably does that because it thinks the inventory variable either doesn't have a value or something more obscure, I'm not sure
Maybe because the inventory is empty?
The map is of size 0
public materials: Map<material, number>;
public consumables: Map<consumable, number>;
public moves: string[];
public arsenal: Item[];
public tools: Item[];
constructor(data: any) {
if (!data) data = {};
this.materials = <Map<material, number>> new Map(this.itemIdToItemObject(data.materials || {}, materialIds));
this.consumables = <Map<consumable, number>> new Map(this.itemIdToItemObject(data.consumables || {}, consumableIds));
this.moves = data.moves || [];
this.arsenal = (data.arsenal || []).map(item => new Item(item));
this.tools = (data.tools || []).map(item => new Item(item));
}
This is the inventory constructor
Can you try logging inventory variable?
The one over here
owo what
square bracket notation on a map
uwu
Wait a second, <Map<material, number>>
What is the extra generic notation around that supposed to be
It's the type of key and value
huh¿
It's to cast it
It works
profile.inventory.materials.set("stone", 5)
profile.inventory.materials.has("stone")
this works
in a different file
man i need to check my eyes
i accidentally read item as items
Map(1) { 'stone' => 5 }
This is what it logged
the inventory
So it shouldn't set it as never right?
Right click the inventory and press peek definition
You probs set the wrong type for smth
Oh I think I know why that error happens
well just normal definition then
and profile is an argument of the function of type profile
Your inventory variable doesn't have a type, falling back to never
That's probably the issue
oh
Set the type to Map<material | consumable, any>
Ok
We're getting there
Now I got this
ACtually
I can just use inventory
I'm retarded
perfect 😄
thank you!
I'm quite new to TS
*new to brainfuck
ts is better wdym
It's better but it's brainfuck
nah
i only need the intellisense not the static types
It helps my brain more to understand the node
If we add optional static typings to JS itself which was proposed in a TC39 proposal, rip TS
it's why i was able to use this json in my code without using wrong properties
https://media.discordapp.net/attachments/748741525982150687/869226733491060806/unknown.png
blame Tim for telling me to use an html parser
...(... >) moment
is there a way to copy the nested property
We need more abstraction!
?
All the nested elements lol
What exactly do you mean by that, Example?
has anyone ever used one of these distance formulas in string similarity comparison?
- hamming
- levenschtein
- jaro-wrinkler
- smith-waterman
- sorensen-dice
- jaccard index
- overlap coefficient
and if you have, does it perform well? reason im asking is because i have a few choices and wanted an opinion on why one performs well
right click address bar
press a button
boom now i can paste the .ul.li.div.a... in my code to use the json property
i use this
string === string2
kek
In information theory, linguistics, and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. It is...
i had my eye on this one
Oh I love levenshtein
Its such a good algorithm
it makes me nut every time I use it

Idk it just provides more usability for my users imo
vs. hamming distance the levenshtein distance is not restricted to transposition only
I mainly use it to "auto correct" item names
sorry what
it's not used for correction
how so? it's used for comparison between two strings, not the correction of one based on another
levenshtein is for noobs
real people use google.com/complete/search
Hold on lemme get the code
mostSimilarModule(item, keys, factor = 0.4) {
const resp = keys.sort((key1, key2) => {
return levenshtein.levenshteinRatio(key2, item) - levenshtein.levenshteinRatio(key1, item);
})[0];
if (levenshtein.levenshteinRatio(resp.toLowerCase(), item) < factor) return false
return resp
}
there u go
you mean autocomplete
ye
its rlly nice for users
my purpose is to match strings against each other to check if it exceeds a certain score
I've had alot of positive feedback about it
oh
that could work too
It has alot of use cases I can imagine
this is for moderation purposes so im looking for strictly the best distance string metric
Ah, well I use it for my textbased rpg game
what do you think about the complexity of levenshtein
Regexp is good enough for that
regexp cannot compare 2 strings
Levenshtein seems way too good and might bonk innocent people
that's why im asking for if anyone has used anything else
Yeah but you can compare how close the word is to a swearing
that's not my intention
then what is your intention?
it's to match a user's previous message against the one they just sent
oh
yeah then using levenshtein is the better option imo
i once made this:
#development message
kekw
your downfall is that it only matches one swear word, and it looks very inefficient
now if you wanted to match a user's custom list of words to block how would you do that
ok well ill look into levenshtein
Levenshtein is really nice
also bruh who removes the swears with *
i have a few slices of test messages like this
;_;
some people do
You want the algorithm I have?
exports.levenshteinRatio = (target, source) => {
if (source == null || target == null) return 0.0
if (source.length == 0 || target.length == 0) return 0.0
if (source === target) return 1.0
let sourceWordCount = source.length
let targetWordCount = target.length
let distance = new Array(sourceWordCount + 1)
for (let i = 0; i < distance.length; i++) {
distance[i] = new Array(targetWordCount + 1)
}
for (let i = 0; i <= sourceWordCount; distance[i][0] = i++);
for (let j = 0; j <= targetWordCount; distance[0][j] = j++);
for (let i = 1; i <= sourceWordCount; i++) {
for (let j = 1; j <= targetWordCount; j++) {
let cost = ((target.charAt(j - 1) === source.charAt(i - 1)) ? 0 : 1)
distance[i][j] = Math.min(Math.min(distance[i - 1][j] + 1, distance[i][j - 1] + 1), distance[i - 1][j - 1] + cost)
}
}
return 1.0 - distance[sourceWordCount][targetWordCount] / Math.max(source.length, target.length)
}
t1 := []string{"join my server - abcde", "join my serv3r - 123ab"}
we have human moderators for a reason
bots aren't good enough
some bots attach a random string onto the end of their message
or ur code isn't good enough 
you want regex for swears?
I have a neat collection
or just don't use regex
is it from botghost

yeah... write all words in a list
no bruh
I mean levenshtein would be better imo as you can increase/decrease the threshhold and allow for custom inputs which is way better for customisation by the discord server's admins
yeah
i plan to allow flexibility on the threshold required
my concern is obviously with false alarms
some mod bots are too much for me
tf you tell me i can't send the letter f or a DISCORD link in #memes?
In information theory, the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.
Vysion, you should really look into the Damerau-Levenstein algorithm
isn,'t that like a coding interview question
what differences does it make
how many characters do you have to change in string x to get string y
The Damerau-Levenshtein distance measures the "difference" between two strings. A Levenshtein automaton recognises strings that are of a certain Levenshtein distance ("difference") from a particular reference string.
ah i got it
man where the bois when you need em
aka fuck -> fuk won't "work"
here i am
I think levenshtein is the best option
although what benefit does that provide over levenshtein
yeah ill probably go with that
looks like overall it will work fine
i think human mods are the best option
thanks for your help everyone
u mean those fat ppl who sit behind their screen for 12 hours a day?
yes
fam why you exposing my guy code913
Kinda sounds like bot developers too actually 
beluga
boot developer === cobbler
yes
cobbler cobbler mend my bot
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
helppppppppppppppppppppppppppppppppppppppppppppppppp
wat
quick question. for discord.js is there any validators to check if an ID passed into a command is a valid user or in the current server? cause like "1234" is too short. but "868289752074436658" isnt in the server (its my bot im currently working on) is there anyway to validate these
yes there is
iirc discord.id has an api for checkings IDs
It doesn't check or validate them, you have to use a regex
