#development
1 messages · Page 40 of 1
let channelId = client.channels.cache.get(971718503914680340).
could also be an issue of sourcebin idk
Can an Express.JS post method return or res.send() an .html file?
responses regardless of request method can include a body
well, I guess except for HEAD
module.exports = {test:()=>{}}
Test comes out undefined if I call it?
the {} are seen as scope closures, if you want to return an Object, do …=>({})
So how do I do so.
resolve(number) returning undefined when calling the async function using await function()
Right now, I'm at my index.ejs file and have the code of: <%= for (let result of local.results) %>.
If, supposedly, local.results return the following array:
[
{
template: Row {
word: '(N.) Meow',
definition: 'The characteristic crying sound of a cat.',
synonym: 'Cry',
antonym: 'No Antonyms',
derivatives: 'No Derivatives',
examples: 'With a meow the brown kitten jumped down.',
translation: 'مواء'
},
pronounciation: 'You can check out the pronunciation of the word at here:<br>https://audio.oxforddictionaries.com/en/mp3/meow__us_1.mp3 (American English)'
}
]
Is it possible to send a <p> with, let's say, the value of definition, if that made sense.
yes can append an element somewhere with local.results[0].definition
What?
Cause right now, I'm trying to loop through template's properties and send a <p> tag that has the property and the value.
Right now, I have this object to work with:
for (let result of local.results) {
for (const [key, value] of Object.entries(result.template)) {
console.log(key, value);
};
};
Fair, but with the key and value, how do I send a p tag? Basically, doing it inside the 2nd for-loop.
You need to append a new element to a specific element you can get by ID
or to the body
Well they technically don't need to do that since they're using EJS
idk the dom too much, but like HTMLElement.appendChild(…)
ah. Didn't know ejs was much different
I'm using EJS, yes.
show code btw
You can just do it directly:
<% for (const result of local.results) { %>
<% for (const [key, value] of Object.entries(result.template)) { %>
<p><%= `Key: ${key}, value: ${value}` %></p>
<% } %>
<% } %>
EJS can be pretty hard to work with, sometimes
Hey guys! One of my buttons doesnt seem to work, even though i have done exactly the same as the other button which works.
I dont get any errors, but when clicking the button it says "This interaction failed".
means you don't respond to the interaction then
i mean i am trying to reply
Then your code is probably short-circuiting at an early point before being able to reply to it, such as a faulty condition
Show code
Try putting logs before the interaction.reply() method calls and see if the expected ones aren't reached when you click on the said button
log what
first of all await your promises
then defer the interaction since you're doing async database calls
doesnt log anything
Then that means the conditions are faulty, try logging the values you have in the if statements and see if they're what you expect
Date has also toEpoch iirc
shush shush shush
Date.now() is also a thing
happy bday @earnest phoenix
Thank you Waffle
sane C++ developer and well known llvm god
happy bird day
wdym "github link"?
I don't think it got deleted, unless u deleted the branch
...you deleted the branch?
idk how to explain, but basically they're different versions of your project, usually sharing the same ancestor
check if the project files aren't still there
unless you deleted the branch, you cant lose the files
even then, u can restore the branch from history
ok that was dumb
no offenses but you really fckd up on this one lul
do you have any local copies of it?
and that folks is what we call a major fuckup
If you didnt delete it permanently it should be in a recycling bin on your pc
unless you cleared that as well
yyea well
rewrite time
that's like, you killed the man, fed to boars, killed the boars, made a soup, threw it in the trash, burned it and buried the remains
I can tell you now it wont be fun

Unless you like busting your balls with css
You can't just use html
that aint web development
yes
and css is hell on earth
dont let anyone tell you otherwise
react and html/css/js are mutually exclusive
don't try to use them both on one project

css is alright
Noob question incoming..
I am currently setting up a tag system (kind of like lucas) but with slash commands...
What I have setup right now is a JSON file with different tags and the content is would send.
And what I am trying to do is when I go to grab something from the JSON file, I want one of the things to be "tag" so that it gets the name of the tag and then grab whatever it needs..
It's hard to explain in text and it would be better if I show it..
But here is the code so you can maybe get an idea of what I am trying to...
JSON Code:
{
"tags": {
"wrongdiscord": {
"title": "Looks like you have the wrong Discord!",
"body": "Hey there!\n\nIt looks like you might have the wrong Discord server!\n\nThis is a server for the \"blub\" Discord bot, and not any other\nWe recommend that you join their Discord instead :)"
}
}
}```
**JS Code:**
```js
const { tags } = require('../tags.json')
const tag = interaction.options.getString('tag')
if (tag === 'wrongdiscord') {
interaction.reply({
content: tags.tag.body
})
}```
should be tags["wrongdiscord"], so essentially in your case you could skip the if part by going tags[tag].body
unless you wanna catch if a tag doesnt exist
since in your case, tag is a variable, you'd need to directly reference the json object by using tags[tag].body


how do i get the top middle of the box
i can get top middle coordinate of the box elements one by one but when i select two i can't find how to get it
in xy coordinates?
it doesn't give me the x y coordinates of the box when i select both
what program is that?
my website I'm using konvajs
then you have to check the konvajs docs and ask their community
I didn't find anything about it in the docs :/
yeah nevermind, no clue unfortunately
Wdym by string options like these?
No need
For a chrome extension coded in JS, would an ip premium method be flexible enough?
like if your ip is in the code then you can use the extra features
but then I could see the code and see a bunch of IPs
If so, how would I make it so the file (when inspecting the extension) is not visible to users? I don't want people's Ips being visible
Oh
so you can't hide it
nope
what if you use a txt file?
the only way is to have a server
then have the extension ask your server
about the ip
Oh so a database?
yeah
wait but the thing is can't my username and password for the db be leaked if i just add it to the code?
or do you use localhost?
no
your extension sends a request to yourserver
for example yourwebsite.com/check?ip=xxx.xxx.xxx.xxx
Oh ok
then your website checks your database
Alr
then return the result
Ok
And how do you wanna prevent the user from finding out the URL and spamming requests?

yeah
I am kinda in a pickle, any1 knows how to store lists/arrays into a .json file and perhaps even access the .json file and use the saved list? Currently I am using the json library. I am using python for this.
import json
array_list_to_save = [992058629517742080,3012146008341360720]
# export list into .json file
# Extract array from .json file and save it.
extracted_list = [992058629517742080,3012146008341360720]
Yes please don’t use json as a database
and that
I originally thought of a txt file, but it would cause a lot of errors.
Don’t use files as databases in the first place
Use a proper database like Postgresql or Mysql or Sqlite or Mongodb
Relying on files as your database is going to cause a lot of issues down the line
Thanks, I'll check those out.
But what about my csv database
Imagine calling mongo and mysql a proper solution
Any file based database is a bad idea
nobody mentioning that any database is file based
You know what I mean ^_^
well technically, everything is file based 
MySQL stores stuff in files iirc
Everything that essentially retains data after a restart is technically file based 
why do I always bring up the shit you have already said istg

Always
I will call the police if so!!1!
Yes, but writing your own database is not the same as using a file for it
Databases are designed to be efficient and cache friendly, and are often quite complex at a low level to achieve things like concurrency without any risk of data loss
Shut up nerd

#development is my home
kick's waffle out
Use proper database
or
Mysql
Choose only one waffle
fuck…
json
I mean tbf it’s pretty much a good database if you know it downsides
Proper database
But since this is against Waffle… yeah let’s harass about him for this comment
:c
what bot do you guys think is best for admin help? like clearing channels, adding triggers, mutes/bans/warns, etc?
commands are easier for me to use rather than diving into server settings
#WrongChannel
is it illegal to send components in webhooks?
very illegal. You can get your account destroyed if you do that ever.
Jk it's not illegal. Idk if regular webhooks can properly have them, but I do know that / commands route through webhooks and can have components no problem.
even though the execute webhook (send message) endpoint is documented to have components
so…???
which one should i use, i was trying to figure it out heh
i put it in general but it didnt seem like the right place either
I may sound dumb but does someone know how to convert a normal website to a express website?
Static website
for what purpose
express is quite bloated and if you're just gonna continue to use "static" website, then you're better off without
sounds like a reasonable thing to do if your site is partially static, such as having a login page within it. Though if its really entirely static like just a homepage, theres no need to, true
so mainly depends on the use case
Even then, express is just... It has a nice interface, that's all I'll give it. I wrote my own route handler which I can control
For majority of people express is the go to
not everyone knows how to make their own route handler with the native http library or whatever you used
http
const Discord = require('discord.js');
const config = require('../config.json')
module.exports = async (client) => {
let channel = client.channels.cache.get(config.channelID.interactionsChannel);
let msg = (await channel.messages.fetch({limit: 10}))?.filter(m => m.author.id === client.user.id)?.last()
let toSendEmbed = [
new Discord.MessageEmbed()
.setTitle(`Interactions`)
.setColor(`BLUE`)
.setDescription(`📩 - Create a ticket\n💻 - Apply for beta tester\n👨💼 - Apply staff`)
]
let timeZoneEmbed = [
new Discord.MessageEmbed()
.setTitle(`Assistance Info`)
.setColor(`BLUE`)
.setDescription(`Availability GMT+3 [08:00 - 12:00] \nIf the problem is related to javascript/python, try the channels [#1015668644862234664](/guild/264445053596991498/channel/1015668644862234664/)/[#1015668677569417256](/guild/264445053596991498/channel/1015668677569417256/) \nUse decent language, if you don't do this you will get **time out**.`)
.setFooter({text: `Last Time Updated`})
.setTimestamp()
]
let ToSendComponents = [
new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('CreateTicket')
.setEmoji('📩')
.setStyle('SECONDARY')
.setDisabled(!config.settings.interactions.createTicket)
)
.addComponents(
new Discord.MessageButton()
.setCustomId('ApplyDeveloper')
.setEmoji('💻')
.setStyle('SECONDARY')
.setDisabled(!config.settings.interactions.developer)
)
.addComponents(
new Discord.MessageButton()
.setCustomId('ApplyStaff')
.setEmoji('👨💼')
.setStyle('SECONDARY')
.setDisabled(!config.settings.interactions.staff)
)
]
if(msg) msg.edit({embeds: toSendEmbed, components: ToSendComponents})
else channel.send({embeds: toSendEmbed, timeZoneEmbed, components: ToSendComponents})
}
i want to send toSendEmbed
and timeZoneEmbed
how?
embeds field is an array of embeds
you can just
embeds: [toSendEmbed, timeZoneEmbed]
what
display only 1
used to know a guy that made a bot that used a json db, had a file for each user in a directory for each server that had a file two
there was like 4k json files
worked pretty well
@raw sigil the embeds property can accept an array of embeds, try this out

how would you get the channel a 'voiceStateUpdate' event came from?
Arrays are objects with indexes as keys and elements as values, technically everything is an object in JavaScript internally, so you can assign anything you want to them (except for nullish values, which are null and undefined)
is there a way to get a user's server banner?
I have 3 objects in an array
All of those objects have a uuid to identify each
All properties except the uuid are equal
How do I only have 1 of each kind?
array.filter ?
Only keep 1
[...new Set()] doesn't work since 1 of the properties aren't equal
probably a shitty way to do it, but could loop through them all, add the names to another array (assuming the names are unique), and then delete it from the array if its already in that other array
Or store the name property in a object and don't continue the "for" statement?
Bad way to explain*
Stops the entire script hmm
nvm
Fixed
anyone have any experience using the node_microphone package?
cuz im trying to make it so that the bot can be in more than one vc but stream the same audio resorce
and when i try to use the same source it just bricks the entire bots ability to stream anything
at the moment i can run one vc command that streams an mp3 and the node microphon commands at the same time in diferent vcs
and that all works
wait i have an idea
nvm didnt work
poor Dis
at least it doesnt die like on mobile when trying to appeals@top.gg
Can you show the code
´${time}´?
oh wait, they fixed using backticks in code markdown
oh nope, they didn't
Yeah if you do that then it’s going to be confused, when it’s a string it’s expecting it to be in ISO format
Pass it in as a number directly instead of a string
👍
does someone know how to make a beg command using a button? Im not talking about coding it for the most part, more of the logic on how to know whos recieving money, this is how it should be:
user 12345 does /beg 1000
makes a message with a donate to him button
user 54321 presses the button
now user 54321 would loose 1000 and user 12345 would get 1000
more of the logic on how to know whos recieving money
store the user id in the button's custom id
can I still execute the button that way?
yes why wouldn't you?
someone said I need the id to be static to execute buttons
that doesn't make any sense
I mean yeah, buttons will have static ids once sent, but you can set them to whatever you want
the event will still fire regardless
how would I go about executing the button interaction?
I currently have this which prob wont work because I have no Idea what Im doing
https://paste.rjansen.de/hnIGCR4XEz
whatever u need to do with the interaction you'll add inside this
also, don't simply copypaste code from the internet, try to learn what it does
bots aren't simply "code and forget", they require active maintenance which you'll not be able to do unless you understand your code
I do understand my code, I wrote about 90% of that file, I just dont understand how to execute buttons
(more like 60% because 30% is button code)
this is the index file without buttons;
https://github.com/rotvproHD/0xBOT/blob/main/index.js
that line I sent u, it's where button handling should go
yeah, thats where it currently also is, after the interaction.isChatInputCommand() if statement
so?
ok, I think I got most of the customid logic, the last part is how do I make button.execute execute the right button?
for the custom id part I can just check the first three letters and if they are BEG I just get the other vars and send them to the button, but how do I execute it? like yes, button.execute, but what does it look for?
wdym "look for"?
it doesn't do any check automatically, you're the one filtering what gets executed and what doesn't
ok, I think I got it now, last question; is interaction.customId the custom id I set in the beg command?
yes
ok, thanks
got it
does anyone know how to get data from json file and store it into a var
@neon leaf play ncs song
?
const data = require('data.json');
```?
SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at Y.json (/root/MELLIE/node_modules/petitio/dist/index.js:30:574)
at ke.json (/root/MELLIE/node_modules/petitio/dist/index.js:30:2499)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
syntax error
whatever json you're trying to parse isn't a valid json
should i just opensource a modmail bot or try to code it in a way that makes it work with every server
That depends on you.
Open source doesn't really exist so people can figure out how to adapt some software to their needs.
It exists more as a collaborative process in developing software.
You can develop a modmail bot to make it work in any server
You could also open source it at the same time.
So pick which one you want to do
If I were developing a modmail bot meant to be used privately, I would still make the bot work in multiple servers to make it invitable elsewhere and maybe consider open sourcing it.
Although, isn't there already a modmail bot open sourced?
that's not really anything that is relevant though
seeing as its not limited to 1 bot being an opensource
No its not
i'm not that good with embeds/stuff alike so would something like this be alright for it
But with there being an already very popular open sourced bot, you will have to likely face challenges if you wanna get yours out there
so its good to expect it even if it doesn't happen
yea
Embeds are better than just normal messages
is tim a live per chance?
im sure you (tim) suggested some vps type provider in the past when iw as talking about contabo, could i ask if you recall what that was? 🙂
how can I get each list length?
you cant loop through an object on its own
actually
I think you can
I mixed it up
Use Object.keys()
key in object works, otherwise you can also do key of Object.keys(object)
you were doing it wrong
Object.keys(list) would be in the condition of the for loop
for(const key of Object.keys(list))
but what tim said should also work
TattoosList[key].length
or for(const array of Object.values(list))
then array.length
thats a typescript issue, not a js issue, it works on js
but in typescript you need additional things
for example you cant use fixed array type
You could do some weird typings
you have to use a Record
can you send me some example please?
You can probably use a interface instead of just going for a record no?
const TattoosList = {
mpbusiness_overlays: [
'MP_Buis_M_Neck_000',
'MP_Buis_M_Neck_001',
],
mphipster_overlays: [
'FM_Hip_M_Tat_000',
'FM_Hip_M_Tat_001',
'FM_Hip_M_Tat_001',
'FM_Hip_M_Tat_001',
],
}
there's the list if helps
const array = (TatoosList as Record<string, string[]>)[key] something like this for example, but thers probably a better way
Just type the variable, that works iirc
couldn't you just put that type on the entire variable
like
const TattoosList: Record<string, Array<string>> = {
mpbusiness_overlays: [
'MP_Buis_M_Neck_000',
'MP_Buis_M_Neck_001',
],
mphipster_overlays: [
'FM_Hip_M_Tat_000',
'FM_Hip_M_Tat_001',
'FM_Hip_M_Tat_001',
'FM_Hip_M_Tat_001',
],
}
Yeah that should work I believe
you can type cast the entire variable yes, but you also lose access to its specific types
Wdym
you wont get intellisense for the exact key names for example
TattoosList wont autocomplete the object keys
in order for TattoosList to accept a dynamic key, it needs to have a dynamic type
like Record<> or { [key: string]: value }
but if you type the original as that, you lose the original type, which gives you the object specific keys intelisense
so you assign the original to a new variable and typecast that
You're iterating over a number...?
like this?
Please store the result of Object.keys in a variable
So it doesn't need to eval that every single iteration
It doesn't evaluate it every iteration, it does it only once
That's what the iterator methods are for
U sure? At least in java it'll check the condition on every iteration
So it'll need to evaluate it every time
Personally I just cast it when I do something like that
no you dont need all that
Yes it would, but generally it's mostly preference
keep TatoosList as the original object, without any type since its a static object
then make a typecasted variable
like const list = TattoosList as Record<string, string[]>
Object.keys(...) is c here
Hey guys, im using sequelize (6.21.4) and typescript (4.8.2) and in my data class im getting this (Only on INTEGER, BIGINT etc... type) anyone know why ?
No overload matches this call.
Overload 1 of 3, '(options?: IntegerDataTypeOptions): BigIntDataType', gave the following error.
Type '25' has no properties in common with type 'IntegerDataTypeOptions'.
Overload 2 of 3, '(options?: NumberDataTypeOptions): NumberDataType', gave the following error.
Type '25' has no properties in common with type 'NumberDataTypeOptions'.ts(2769)
thank you all for the help btw
does anyone have a plugin/anything that could assist me so i dont need a lengthy line
the thing i want to do is change 1 to 1st, 2 to 2nd, 3 to 3rd, etc. but i don't have a good way considering 11 = 11th and not 11st, 12 is also 12th but 21 is 21st so i can't do the ending i was going to do
@tight island
function toOrdinal(i) {
const j = i % 10, k = i % 100;
if (j == 1 && k != 11) return i + "st";
if (j == 2 && k != 12) return i + "nd";
if (j == 3 && k != 13) return i + "rd";
return i + "th";
}
src: https://stackoverflow.com/questions/13627308/add-st-nd-rd-and-th-ordinal-suffix-to-a-number
but i edited a little as it was old-ish
tf
can't u just do ```js
function toOrdinal(i) {
switch (i.toString().slice(-1)) {
case "1": return ${i}st;
case "2": return ${i}nd;
case "3": return ${i}rd;
default: return ${i}th;
}
}
Nope. Some have different rules than the others, because natural language sucks
That would give like 11st and 13rd
1st
11th
21st
31st
you can also use the intl. class to do it if you need to consider other languages
11, 12 and 13 are pretty much the only exceptions, no?
yes
can someone help me with storing all my cmd and it info into a json file like this
Define help.
How do you want it stored?
In what way?
What's a regular command?
Like i have shown in pic above
But how do you expect it to get in that form.
I don't know where the commands will come from.
It would help for you to explain your main problem in more detail
it's recommended that you store the data of the command at most once
to prevent unnecessary duplications
design the data structure first
do i get anything for boosting? 😳
damn was hoping I could move my bot up ranks or something

you'll need more than $10 for that
🗿
eg. if i do it it would be ```js
commandName => {
name: string,
description: string,
slash: boolean, // if executable via slash
message: boolean // if executable via messages
}
lol
aight
i will do the rest tmmr
Make sure you check during boot for duplicates
Else you might see yourself facing UB when executing said commamds
Without restarting can we make changes in the bot
Like change in interaction and message create files
Depends, you’ll have to have some special code for reloading those things
Umm reload can happen only in commands i think
No
Then
You can change code and reload it dynamically as long as you’re not using ES6 style imports
That's super easy, you can create a reloading command to reload certain core features of the bot.
To be honest, if your bot isn't released, just restart it, or use a dummy.
Can we make changes in interaction create too without restarting the current instance
Yes.
It's released
Any small example can anyone send
Use a dummy, or just create a reload command.
You can change preeeetty much anything (to a certain extent) as long as you delete the file from the require cache and re-require it
However if you’re using import you unfortunately won’t be able to do that
Ok then you can definitely hot reload events and commands
I'm going to un-nerd what he just said.
Unload something from memory, then reload it.
But I believe you can use TS to allow both import and require(); statements.
Okay so I have to delete the old event from the client and register a new one right
Unbind the listener, delete the require cache for the file you want to reload, re-require the file, and bind the listener back
That’s the basic overview
^
Umm 👍
Somebody else will have to help you with the details though, I’m not very caught up with how deleting the require cache goes since I use ES6 style imports
Why not use both?
TS intensifies...
Because you can’t use both really
There’s two types of imports, one is a function, the other is a keyword
They do not do the same thing
You can’t use the keyword and require in the same module
The typescript compiler just turns it into require functions if you use both.
And it’s pretty much impossible to bust the ES6 import file cache
Trust me I’ve tried, there’s not an easy way around it
It’s the biggest complaint I have with ES6 style stuff, the rest is great
It's in a promise?
^ ?
Do you need to wait for anything to happen here? It should be instantaneous.
So unsafely fill up memory and wait for a memory dump?
Huh
Can we change the default memory use of vps for nodejs
My way of saying crash your system
Ah I see
I do it every time lol.
Wdym
Node.js does not have any memory restrictions?
I mean you can use --max-old-space-size..?
Like it crashes at 3gb? How many servers are you in..?
8.6k servers
Are you storing all of your servers in a certain variable?
Or all of something?
Mean?
I didn't get it
const serversbotisin = idk_i_havent_progremmed_in_discordjs_in_30_years()
Trust me it's a good function
Yeah
snake case ew
Okay ykw just ignore my question.
I was thinking maybe you were storing big HEAPS amount of data in memory.
😑
e
heh

Is the process crashing at 3gb of ram?
You see that's what I'm confused about.
you have 15 gigs, and you crash at 3. That's not a memory problem.
Maybe a CPU problem, or a thrown error.
Eh it could be a problem with memory, it depends
Sometimes v8 doesn’t like extremely large objects
Because garbage collecting them is painfully slow afaik
@earnest phoenix we need you in here big man
Buffer.allocUnsafe()
Who needs garbage collecting? You are the garbage collector.
Average C developer mentality
Pointers are in every language whether you see them or not
Editing an object in javascript.
Or just creating one in the first place
const o = {n:1};
function pointer(_o){
return _o.n+1;
}
No sane language is going to be able to store dynamically allocated objects on cpu registers lol
Good idea.
Fk memory, we're using the CPU cache now.
Friendship ended with heap, rax is my friend now
You think you could store an operating system in memory?
It's a good question I promise.
I mean, what would be your memory?
Idk enough about OS dev to answer that question
And if you store an operating system in THAT memory, what would be THAT memory's memory?
I'm getting too deep into memory.
I mean that’s kinda what VMs are
lol
If possible, I have a question.
Sure
I want to create an auto quest system.
Each item has a level, and the user needs to get an item one level higher than the user to complete each quest.
My question is how would I go around with this? Since each item has a different rarity.
C is awesome tbh
I don’t think I quite understand what you mean here
For example: I don't want my quest system to create a quest to get more items than there is in existence of the game.
ANY other language. Name it.
So you want to like auto generate items..?
Seriously, scratch is better.
i mean C is good when you want total control over everything
Wait I misread that
like multithreading
Not quite.
which is hell in Rust
Rust
Why do that when your compiler does everything for you?
Multithreading in rust is fine, it’s sharing mutable state between threads that sucks
This
Since it’s inherently unsafe from any language’s standpoint
Can't say nothing never programmed in it.
You should try it
Blazingly fast 🚀🚀🚀🚀🚀🚀🚀
That's hell
Creating a discord bot with rust by using the discord API?
Yes
I should try tokio
Many async await libs out there
Tokio being the most popular and probably the best supported
Serenity
Never done it. Certainly wouldn’t recommend it as your first project though
^
Rust is a language that is very different from the rest
Learn rust's borrowing and ownership system first
So jumping right in would be very difficult
I'm watching this conversation of 2 nerds talking about languages I have never even heard of, and there's me, with React JavaScript, and python.
It's a big obstacle but you'll be almost guaranteed an expert if you know it
The borrow checker will fight you 24/7 and will win most of those battles if you don’t know how to work with it
Rust's compiler error messages 
But once you figure it out, you don’t fight it a whole ton
And most of the time when you DO fight it, the compiler will just show you the solution
Rust has ownership and borrowing?
Yes
Yes
What does that mean? I've never understood what that means.
It’s a difficult concept to wrap your head around at first
No, References
References and pointers are literally the same thing.
Not quite
Pointers are much more unsafe
References are there because you’re guaranteed stuff about them
References can be mutable and immutable
References can have an explicit lifetime annotation
Rust has pointers, but very rarely will you work with them unless you’re doing low level stuff
Ah yes because Ritchie forgot to add a garbage collector.
No garbage collecting is needed when you have the borrow checker
Garbage collector is yikes
What's the point of an immutable reference? Can't you just pass in the original variable?
That’s the point of it
The reference is read only
No garbage collector, no manual memory management, just semantics the language ensures you follow at compile time
You can only read the value, not modify it
There can be multiple immutable references at once, however only one mutable reference can exist at any given time
Because if data is unchanging, it’s safe to read from it
Immutable reference can also be passed in multiple threads
But if data is changing it’s not safe to read from different parts of the program at once
Can't you await?
Wait for the data to change.
That’s what async await sort of solves yes, in a way
However it’s not the ideal solution all the time
I rarely deal with threads so I’m not qualified to talk about that, would probably just be me guessing based on what I understand about the language from a single threaded standpoint
Mutexes are pog
I never programmed in CPP, well, I did, but for a small 2 weeks.
C++ is hell compared to rust
i really wanted to get a hand on the language, I mean, the performance is incredible with over 90 keywords!
“Modern c++ is like rust without the quirks” - C++ user who has never used rust
Most of them just looked at the lifetime syntax and raged quit
Yeah lmao
Lifetimes are intimidating when you don’t understand them
But you’ll come to see their usefulness eventually
Honestly i was one of them
Same
'a looks so cursed
Yeah the syntax is quite weird but I understand why it’s like that now
I know what those are. Give me like 2 minutes while I do a quick google search.
When you have a cursed amount of lifetimes it’s nice to have proper names for them
Don't look at the syntax
Yeah it’ll freak you out
I promise they’re not that complex
Pretty simple when you get the hang of it
Idk, quirky compiler devs
Find high-quality images, photos, and animated GIFS with Bing Images
Why Bing
Oh that’s just a use of lifetimes that the compiler normally infers for you
I don't bother switching.
You don’t have to write that yourself for that use case afaik
What does a lifetime do?
Anyway 'a means that it's a lifetime annotation with the name a
Lifetimes tell the compiler how long something lives for before it is dropped from memory
So you schedule a drop?
Rust looks very fun to program in
However the problem with that is if you have something that holds a reference to that thing that is being dropped, you will now be referencing memory that you don’t know the contents of
So you get the duration on how long a variable lasts?
So that’s where lifetimes come in
Lifetimes tell the compiler: “hey, I need this reference to live for as long as my struct does, don’t drop it from memory until my struct is dropped from memory”
Syntax this.
In... rust.
struct Something<'a> {
name: &'a str // hey, don’t drop this from memory until lifetime a is dropped from memory!
}
I still don't understand the syntax, but that doesn't matter since I understand the general meaning I guess...
Otherwise you might access memory that doesn’t belong to you, potentially causing a segfault
It’s a more complex area of rust, don’t worry about it for now
Multiple variables can have the same lifetime, which means that all of the variables will be dropped at least at the same time throughout the function
fn func<'a>(thing: &'a str, _unused2: &'a str) -> &'a str {
// both of these strings are a str reference (like a char * in C/C++)
// but since they are a reference, you don't know when one of them will be dropped (which would lead to a dangling pointer)
// the EXPLICIT lifetime 'a here makes sure that they both will still exist throughout the entire function
// return thing (return keyword is optional in the end of a function)
thing
}
I would’ve typed out a more detailed explanation like null did but I’m on mobile and that would be hell
^^, most of the cases, the compiler will suggest things to you with helpful messages anyway
Basically it’s to ensure you don’t accidentally have a reference to garbage memory
And the compiler will enforce it as a part of rust’s safety semantics
But pretty much any time you have a reference in a struct, you’ll need a lifetime annotation
Rust looks like an interesting language.
It 100% is
Maybe I should become a rustacian
Yes
It also has no null type 😉
But it has an Option type though
One of the best decisions made by compiler developers to this day
I have to go now, It was really fun learning about lifetimes.
Like ?String in JavaScript
Cya!
Cya
Bye 👋
Yeah but this way you know for a fact that something could potentially return None and that you need to handle it
True
I see a lot of people in my CS classes (Java) that forget that all objects could potentially be null in some cases and don’t handle it
Then they get confused when they get an NPE
Whenever rust has a chance to return “null” it is always explicitly annotated and forces you to handle it
It’s the smallest things about rust that make you fall in love with it
This
And also other things like traits, procedural macros, helpful community, and guaranteed memory safety
God the community is actually great when you have a question with rust
I get responses in usually under 5-10 minutes and they’re always thoughtful and detailed, never once had an ounce of hostility in it
C++’s community on the other hand is a lot more passive aggressive with things about 75% of the time
lmao true
(In my experience, maybe I’m just asking stupid questions)
A lot of the time the question just gets buried
Rust’s community has been a huge help to learning everything I know about rust so far for sure
It's hell to make a C++ program cross platform or even use third party libraries
I learned it the hard way when i wrote a compiler in C and i can't port it to macOS 
Lmao
Library support in C++ is just really outdated and poorly organized
I think rust was the language the world needed in order for a more modern experience
Everything just feels updated and clean
FFI is still a bit sketchy when working with C/C++ libs tho, can’t be avoided
true
but it's still not that painful
you can easily interoperate C/C++ libraries into Rust
Yeah
I hate dealing with DLL linkage and shit like that, much better than dealing with setting include dirs and stuff with C++ tho
C++ users telling you to learn an entirely new language just to build your program
C++ users telling me to spend 2 hours to compile 40 different libraries after spending 3 hours just trying to get their include dirs set up
Relatable
Just for the linker to tell you “you done fucked up, your target type is wrong”
I like to think of the c++ linker as a really punchable hillbilly with a beer belly ngl
this omg
i hate __impl_... symbols
Hmm, I don't really get Interaction and Collectors
Let's say in an Menu component for example. If I create a new menu and let user interact to it.
Isn't that I can still use interactionCreate event to modify the interaction message?
Then what would be the idea of using something like an interactionCollector. It sounds a bit redundant for me but I feel like it should have some meaningful idea behind
think of a collector like a mini interactionCreate event
All they do is spawn the appropriate event, eg reactions would be reaction related events, messages would be message related events, interactions and components would be interactionCreate
and at the end of their life they get destroyed
All it is, just a temporary event that collects and returns the responses
So like a interaction event with timer?
if you provide a timer yes
no timer makes em run indefinitely until stopped
also with collectors you can do filters so they only collect when a certain condition(s) are met
for example if you wanted say a button to only collect for the person who ran it, you'd make the appropriate filter
you could 100% do all this in the interactionCreate event mind you
the collectors are just easier as they can be used then and there
So it just make it easier?
Yea
It has its benefits and drawbacks
A lot of people frown upon using collectors
How would a collector spawn itself then.
For example if I create a new component and I have a collector with a timeout. Would a new collector create at that moment or a collector already started during the initialization of the bot?
Wdym?
You never want a collector to spawn itself without you calling the appropriate method
https://discord.js.org/#/docs/discord.js/main/class/Message?scrollTo=createMessageComponentCollector
You'd call it when you need it
there is also awaitMessageComponentCollector
it is like this but it just spits out the collected without you catching the event yourself
Yeah, I see, that's enough information I am trying to investigate
Was making a select menu function that would edit the message
I want to have a timeout function where it would disable the menu after x seconds but only based on the latest interaction so I was wondering
https://twitter.com/BanbeuHobby/status/1560167435030110208?t=nlBhhAq3y8QwwzMQB4Lgag&s=19
I don't think their issue is related to memory in this case, their program might be causing a bottleneck through some imports that cause cyclic dependencies or something similar
Although it can be related to memory however if their program crashes with an OOM (Out-Of-Memory) error, which they haven't told us so there's also that
Also @bright thorn ^
🤐
If an error is thrown when your program crashes, does it say something like JS Heap Out of Memory?
Or does it not thrown an error at all when the program crashes?
0|Real |
0|Real | <--- Last few GCs --->
0|Real |
0|Real | [26383:0x59ed7c0] 166458406 ms: Mark-sweep 1845.5 (2080.8) -> 1831.4 (2080.8) MB, 3522.5 / 9.2 ms (average mu = 0.250, current mu = 0.203) task scavenge might not succeed
0|Real | [26383:0x59ed7c0] 166462689 ms: Mark-sweep 1845.0 (2080.8) -> 1831.6 (2081.1) MB, 3434.7 / 0.1 ms (average mu = 0.225, current mu = 0.198) task scavenge might not succeed
0|Real | <--- JS stacktrace --->
0|Real |
0|Real | FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
0|Real | 1: 0xb09980 node::Abort() [/root/.nvm/versions/node/v16.14.0/bin/node]
Even 12gb is Empty in my vps
You get it
Before we get further into this, I recommend updating your Node.js version to the latest LTS release (v16.17.0 as of writing this, simply run nvm install --lts)
Now if you didn't know, the V8 JavaScript engine which the Node.js runtime runs on has a strict heap limit which is 512MB on 32-bit systems, and 1GB on 64-bit systems, if you need more memory you need to use the --max-old-space-size CLI option to increase it, you can set it to 4096 to allow V8 to allocate 4GB of memory
An example of running a program this way is:
$ node --max-old-space-size=4096 foo.js
Okay can I do this 14gb
On 64 bit
pm2 start "--max-old-space-size=14336 src/index.js" --name "Real"
Should work
Although run it like this instead:
$ pm2 start src/index.js --node-args="--max-old-space-size=14336"
i really love the download attribute on html 5, it makes things so much easier
yup
?
how would I make the button edit the message? I already know how to pass data using customId but message probably wont work with that
Button has the reference to its own message, simply use interaction.message
how can we delete duplicate documents from schema
@earnest phoenixhttps://patorjk.com/software/taag/#p=display&h=0&v=3&f=Big%20Money-ne&t=Type%20Something%20
try look here
Ty so much
usually you'd have unique ids for each
umm i have guild ids
in schema
but idk some guilds hav multiple schema
well that's what happens when you try to use relational data on a non-relational database without proper structure
is there a way to stream the same audio to multiple vcs?
cant use createAudioStream twice on the same source apparently
also how do you get the "add to server" thing in the bot profile?
In an EJS file, what's the difference between <% %> and <%= %>.
does anyone know how to fetch data and edit messages from a button? this is my current non working code
I already answered u
^
I am using that, I dont know how to fetch and edit though, edit I dont know yet because I need fetch to work
you're not, you're fetching the message
this makes zero sense
also, you'd need to await that
because I dont know how to do it correctly, im currently here for that problem ^^
is interaction.message the message content?
it's the message, as in, the object
how can I get the embed content then? something like interaction.message.content?
you first need to get the embed
message is a message (read, a message)
not embed, not tree, not dog, a message
well how would I get it?
messages can have author, embeds, images, etc
<message>.embeds for all embeds
will that output the embed text (including description)?
it'll output all embeds within the message
so, interaction.message.embeds?
for all embeds, yes
Can I somehow only extract the description?
sure
Just get the embed you want and access it's description property
The embeds property is an array of embeds as messages can have multiple embeds, so if you only want to get the first embed, access the first index, embeds[0].description for the description
thanks, can I somehow make my buttons event not fail? it works but discord says it failed because I dont send a message or something with the button, I just edit a message
you need to acknowledge the interaction within 3 seconds of it being fired
yes, you didn't acknowledge
what do you mean with ackknowledge?
so instead of interaction.message.edit I should use interaction.update?
while we are here, do you know why this returns NaN? its probably the array to string but i dunno how to fix that, I just want to search for the previous number in the embed
because your regex didn't match anything
oh wait, that'll never return anything other than NaN
I tested it and it only shows numbers which is what I want ( I tested with normal string tho )
embeds is plural (so it's a collection)
and you don't need to await something that's already there
just as a headsup, whatever you're doing will fail miserably if you ping someone inside the embed
because mentions have numbers
Is there any way of turning the array / collection into a simple string at all? I logged it and it looks like this
you need to get that element
do you know javascript at all or just doing it blindly?
I never did anything with Collections / Arrays before
ok so that's a no
yes, basically
This tutorial introduces you to JavaScript array type and demonstrates the unique characteristics of JavaScript arrays via examples.
making a bot in cpp? what a madlad
so, cache[0].description I guess?
yes, its just for this mini counting game
nono, you see, it wont work the way you expect it
for example, if you tested it with your name in it it'd return 0 always
because the first numeric match is 0 (0x4096)
nice, my new tweaks have cut memory usage
i thought they'd increase it, as its caching prepared statements now
and hmm, how do i have a third of my user base on one of 18 clusters
must be a chonky server or two somewhere
In an express post() method, is it possible to render a middle page before loading the final page?
Example, once the method is called, a page called loading.ejs would render then result.ejs would render.
How can I do that?
with ajax you would render page A, then page A uses js to make a fetch request to page B, wait for the result, then edit page A with the new result
with a redirect you would render page A with a timed redirect for example, that after X seconds automatically redirects to page B
its also possible to do long polling if page B takes a while to load
page A loads and immediately redirects to page B, then while your browser waits for page B to load, page A is still there stuck
How can I do multiple filtering? For example, there are 5 objects in the array and the objects have specific ids. I want to filter those objects whose ids are 2 and 3
Is there anything I can do instead of .filter().filter() ?
[2, 3].contains(id)
Woops
how I can insert data in a map without overriding the data of an key (Typescript)
fetch
append
insert
so get the data in some temporary variable, add the data you want to add, then override the old data with the new one
but i need to increase the data
save data to variable -> increment variable -> save data to map
show how you coded your map
depending how it is, you could also do for example ["data1"]["dataToIncrement"] = ["data1"]["dataToIncrement"]+1 ?
you see that GetHashKey?
i want to increase that array
without overriding the old value
const existing = hashList.get(category);
existing.push(GetHashKey(...))
thank you i will try that..
I...think I beat intellij analysis algo
lmao
it works thank you :)
/se(?:ason)?(?:.+)?6/gi
That will only fit the listed ones
Dunno how much different possibilities there are
You can test it yourself
const chat = inter.options.getString('string');
switch (chat) {
case "hi":
await inter.reply({ embeds: [hi] })
}```
so I have bee trying for a while now but I cant seem to figure out how to make an else statement like elif from python. So if someone doesnt say respond listed then it would send an embed called 'error' or something like that
if(condition) {} else if(condition) {} else {} etc
so it would be something along the lines of else if(AImsg) inter.reply ({ embeds: [error] })? or am i special
Check if the content matches that pattern
Usually, all of my commands is wrapped in a try {} catch(){} statement.
This is recommended. For example
try {
message.channel.send({
embeds: [new MessageEmbed().setTitle(“Hello, World!”)]
})
}
catch(err){
console.log(err);
// do stuff here, probably send a message in a specific dev channel
}
Since you’re using infractions, you would do interaction.send(), of course.
You would use the string.prototype.match(); statement.
Without awaiting your send() promise this won’t trigger an error anyways iirc
If you fail to await a promise and it rejects, it will not be caught by try catch blocks
yep
Also wrapping anything in try/catch blocks is just awful imo
Either add catch() as chain behind send() to catch errors or create an own send function or overwrite the prototype and add error catching in there
or here me out, just make an error handler in your command handler
This would also allow you to check for a Message Instance or Interaction to respond accordingly
Wut is command handler

True
sadly
But sometimes you gonna send messages also outside of command handlers
And people still forget to catch the promises
Also don’t have a top level error handler
why bot not working anymore
For js your statement is understandable since all the shit that might fail unexpectedly is wrapped as a promise
Tbh, I hate the whole thing about promises, the concept is nice but them being contagious is annoying af
And I have to deal with this shit in flutter 😩
Hey all, i would need help with python package please.
don't ask to ask, just ask
Ok so first, is the python package topggpy maintained?
I am getting
AttributeError: 'ClientSession' object has no attribute '_connector'```
From examples provided in package
iirc i dont think topggpy package is maintained anymore or atleast there arent any active maintainers afaik
could be wrong tho
You're not wrong
@civic gorge would be easier to simply use standard HTTP request on python, if you just want to post server count
Topgg api is not complex enough to warrant a specialized lib
Plus you keep external dependencies at minimum
Yeah figgured that out that ill make a simple wrapper for myself
Thanks
Does anyone happen to know how to request with ipv6 using undici/global.fetch (node 18)
"websocked closed before connection was established" randomly
IPv6 only? Could end up in many unresolvable hostname errors once the other site doesn’t support it.
Log commandFile.data and you will eventually understand your own error
?
Do it
I cant log the problem in this server that i hodt in
Their are no shell
So i have to move to replit
Then move again to the sercer
Server*
Then keep it on the platform you took the screenshot by and console log what I mentioned
no, I'd be using Happy Eyeballs
for instance though, the requesting would be to get around YouTube's ip rate limiting
LavaLink already does this
just want to include it in my LavaLink remake
Did anyone ever do rock paper scissors with buttons? If yes, how did you store the choices
Ah nvm then
I have never made a game like that however, its for short-term access so you could store it in a dict/map
or two variables even
can’t help you if you don’t show your code
Man anybody got tts code in djs? It is nowhere to be found online or tutorials also doesn't exists for it
Have you tried reading the docs?
Actually everyone is thinking about the tts: true, but I was talking about the bot joins the vc and speaks
Nvm I made it
But having this error
Everyone is thinking that because you provided no other information
maybe be more descriptive next time
Hey guys, i have a question in c++
ok
me when question
How make function in JS no scam 2022 freee
idk switch to php
@quartz kindle pls help why code no work ```c
int number = *((int *)0);
printf("%d\n", number);
Is the following code PHP? I think I got it.
function myFunc() {
print(“Hello world!”)
}
myFunc()
var_dump() :^)
sure```cpp
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Localv8::FunctionTemplate t = v8::FunctionTemplate::New(isolate, callback);
v8::Localv8::String fn_name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kInternalized).ToLocalChecked();
t->SetClassName(fn_name);
@earnest phoenix can confirm
So true


