#development
1 messages ยท Page 208 of 1
creating my own chatbot cuz i got nun to do
https://github.com/OceanicJS/Oceanic
doesnt look that bad
netherlands?
looks like some custom discord library that was written for whatever this is https://hacktoberfest.com/
yuh
lmao
tim my pookie i haven't seen you in a long time
looks pretty basic, like straight up copying most things djs/eris did
banger idk why but i can read it soo good
would be cool to see some benchmarks and memory usage statistics
and i'm german lmao
where are you from?
whahahha i know
german looks a lot like dutch so i can also kinda speak it
ayy was geht
:๐ฑ
das klingt doch toll
weird that i dont speak german at all but i can understand most of it
it looks like a mix of eris and discord.js
*ich habe 3 jahre deutsch gehabt an meiner schule
:)
i dont like when people just make random libraries though
at least set a goal to differentiate yourself
what do you do better than the other libraries
well they have 200 stars on gh
and apparently people are migrating from eris to it
because eris is dead/unmaintained
yeah so how can i the sidebar
wait nvm
just had to drag the explorer to the icon bar on the left
doesnt look too bad honestly
promising even
but id also like to see benchmarks
whats the default caching like
well... i mean it's been a long time
like 4 years ago maybe
or even longr
const client = new Client({ auth: "Bot [TOKEN]" });
wtf is the point of this

What other kind of tokens are you going to be using
unless it also has oauth2 capabilities but idk
const headers = {
'Authorization': Bearer ${token}
};
axios.get('https://myapi.com/endpoint', { headers });
and they still use @discordjs/voice for voice support 

well i dont fucking blame them
i could see this being used if youre using the library to makee a user bot but im not sure if they support them
the voice gateway is annoying asf
since user bots of course dont use "Bot TOKEN" for authentication
the api doesn't even support them
pretty sure discord stopped allowing user tokens to be used for auth on the bot api
i think users and bots use the same gateway url
oh?
im trying to make it customizable for multiple answers or a single answer but i think somethings wrong with the value
and the api is relatively similar with some minor differences
I thought user's had their own gateway
ill check this
I mean, it'd make sense if you were completely trying to get rid of self bots to have separate gateways
the voice gateway is a can of worms not many want to touch
It's more annoying than the normal gateway
ah i see
the voice gateway uses the same heartbeat interval as the on you log the bot into
which can be confusing to people if they don't read the docs
as the voice gateway responds with its own interval mistakingly
not really what makes it annoying tho, but those who don't read the docs properly get tripped up by it and wonder why its not working ๐
how the hck are you gonna implement it if you're not reading the docs
I said properly
properly
tim
propolis
you would be surprised at the amount of people who "read" the docs
vs those who skim through it
lmao
they don't read it properly and wonder why their shits not working
i never tried dealing with voice
I dislike it
https://discord.com/developers/docs/topics/voice-connections if anyone gets bored here's the link for the docs
the UDP part seems the most annoying at first glance, along with all the security signature and shit
You have to do a lot of stuff before even initiating a connection with the gateway
ye
its basically 3 connections
the main gateway for voice channel events, the voice gateway for voice events, the UDP for audio streams

most people already use a 3rd party voice system tho
by the way i accidentally went through the eris github and the code structure is identical to eris
it looks like they used Eris as their base and converted it to typescript
its a fork
so its basically an eris clone
they literally forked eris ๐
huehuehue
theres your benchmark answer
I mean
:^)
I'll give them the benefit of the doubt and say they may have made some improvements
but there is no benchmarks to say so
most people dont know how to even benchmark a discord lib
i'd just benchmark the memory aspect of it and do a couple of operations like enumerating guilds or whatever to determine changes
performance is going to be relatively similar across libs i reckon
js is js
and plus were dealing with api's here so youre mostly at the mercy of how good your http client is and discord latency
the only other major aspect besides memory is the event handling
like how the library unpacks all the events into structures and shit
let me do a barebones ram test real quick
theyre all quite similar no?
discord event comes in
new Class(client, raw_discord_data) {
this.class_params = raw_discord_data.params
}
thats what a lot of them do anyways
yes, but there are quite some differences
last i tested anyway
which was years ago
events processed per second per shard
tiny discord goes hard
yeah i made this test just to benchmark it
lol detritus
thats still in heavily active development
nah im good
no its not
cakedan stopped development on that lib quite a while ago
unless someone forked it
my heavy use of adjectives implies the use of sarcasm

sorry too big of words
last release 2021
i was joking
Alright guys today the top.gg development channel will be make a discord lib
its main purpose is bitcoin mining
:D
we wont tell them that tho
lmao
needs to include cache
buddy there will be 5 layers of cache just to make it seem like any usage is normal
gotta store the same thing in ram 5 times
lmao
bet
last time i tested djs i got like 800mb
less guilds???
same guilds
did you call the gc afterwards? it may also be a lot of leftover memory that havent been garbage collected yet
and do a side by side with discordjs again
wait like 20 seconds then --expose-gc then its gc.gc() i think then do your memory usage reading for a more accurate reading
lmao fine
omg i created this chatbot and it's literally so fucking cool
i never knew i had the capacity to do this type of shit lmao
powered with open ai?
said the guy who learned quantum engineering and nuclear physics last year as a homework
if its not comparable to llama i dont wanna hear it
just see his questions on this channel lul, things that not even tim could answer lmao
hahahah no, just using a fuzzy algorithm that would pick the best category based on the answers
the easier thing I helped him with was a pathfinding algorithm
ion know my study just tells me i gotta learn it so i do
like, who tf learns this outside college?
sounds like natural language processing
ChittyKat apparently
Yeah, it wasn't that easy after all. Apparently we had to use ford fulkerson, but using a twist by using capacity scaling to traverse through nodes.
Im curious what is your study
CS
see?
sounds like a graph problem
What fucking college are you going to
no way its not an ivy league right?
I've never heard of some random college teaching that
My most fucked up course after all was computability which talked about theoretical computers
https://www.cs.ru.nl/~freek/courses/t1b-2021/public/exam.pdf
there was also the boxing thing
where one box had to fit in another?
That was a bipartite graphing problem
pretty easy after all
just the runtime was shit
oh its a dutch college
yeah a dutch uni.
nvm
const response = await axios.get(`https://top.gg/api/bots/${BOT_ID}/check?userId=${interaction.user.id}`, {
headers: { Authorization: 'nuhuhuh' }
});```
it's telling me that i can't check the bot even though my other code for the last 1000 votes work perfectly fine. what did i do wrong?
graph problems are fun
yeah i started to like them too
i like the way how you can be creative
i had to learn some graph algorithm for determining the shortest path to a set point on a chess board using knight's movements in googles foobar challenge
definitely
I just wish I knew more about my field of study
damnnn that's actually really smart. I suppose you used dijkstra?
what do you follow?
Computer Science
tbf cs is just a math degree at this point.
ahh
Comp Sci is what I want to go on studying, but it doesn't look worth it
i mean if you like it, fuck it just follow it.
it was a variation of it that focuses on the minimum moves to a specific node, the first time it encounters that node when traversing is guaranteed to be the shortest path since the algorithm goes from shortest paths to longest
it doesnt seem worth spending thousands on a degree that probably wont teach me much of anything valuable
breadth first search i believe it was fun to learn
I eventually had to choose an orientation as well, i chose software and data science. Was i scared for data science, yeah, did i choose it and am i enjoying it? Yuhhh.
ahhh i see, that's actually cool to know!
need to do it for the degree 
but its obviously very memory intensive the more nodes you have
Wouldn't the problem probably be:
- Defining the field
- Making only a set amount of tiles accessible (create a link for these nodes) from the starting node of the king.
- Run a dijkstra algorithm, where the amount of tiles traversed is the cost?
yeah exactly.
like what? a pattern matcher? nope
Idk, as you have only a set amount of tiles you can traverse through, you can actually use a adjacency list instead of a matrix right?
dijkstra doesnt necessarily find the shortest path first but yeah, the next challenge in this problem was doing it under a set execution time
so if your algorithm was too slow the solution wouldnt work
that shall save you some memory
ahhh i hate that so fucking much, the time constraints always make me cry
so you had to use an algorithm that actually finds the shortest path first
mm algorithm hell
but after you precompute all possible knight movements from a node and make the connections its relatively quick
ill find my solution for it i ended with
hmm i see, it sounds painful.
Omg hollup you know what really was painful? Creating my own btcp parser
I kid you not i spent 2 weeks on it
and it still doesn't fully work
only 2 weeks
which is which
oceanic is left (929mb)
yeah but i was like actively working on it. 3-5 hours a day
djs is right
this was the problem
uhm whats right and left?
i forgor some people use mobile
my solution
once you know the algorithm the solution isnt too bad
oceanic <
djs >
so oceanic uses slightly more?
ye
not bad
whats the difference in readable terms
I mean in terms of both of them
oceanic is slightly worse than djs
but djs has seen an increasingly higher rise in memory usage over the years
at 10k guilds to be using that much is atrocious
owhh i see, why didn't you use a prioirtyqueue?
The solution looks pretty good tho
if im understanding there is no point
the first entries in the array will always be the shortest and most direct nodes to explore
so it all kinda falls into place
but i initially didnt even use deque for the problem and used the native python array and was wondering why i was failing the performance requirement
i thought python optimised the array shift operations internally
but turns out they didnt and its horribly slow
ahhh, yeah i don't know all the details of the program, but usually for distance related stuff a prioirtyqueue is like really handy.
i see, python overall is fking slow. I only use it when i create AI models or for data analysis/mining.
i was really surprised it was as bad as people make it out to be
thats why you have all these handy libraries like numpy that do it in c
i dont think theres even a purely 100% python implementation of tensorflow like there is in js where you can run tensorflow without c bindings or gpu
because its that bad
@warm imp you have to provide intents to the client
I am trying to turn on my bot and idk how
Show how you are creating the client
Oh
it has an intents option field
Where would i put that?
i always tend to use sklearn.
i love it's preprocessing methods that it comes with.
youre remining me of my machine learning era
i need to get back into it
especially in these times
i actually wrote a research paper where i compared different classification algorithms for labeling people as high risk/low risk in insurance companies (spoiler: ockhams razor fucked my hypothesis )
yeah it's really fun you need to pick that shit back up
Do i need a bot.js file

when you have intents in your code enable it here otherwise add the intents to your codehttps://files.sky.h4ck.me/files/MjPZRn.png
i feel like i need to understand the intrinsics more but all tutorials ive tried make me fall asleep half way through because they can be quite redundant and boring
from a mathematical standpoint anyways
ahh i still have access to my slides thankfully
i swear once i graduate i am downloading all the necessary slides
might become useful
do you need any help with the math part? I found that part actually pretty easy and interesting.
especially the evaluating part and hyperparameter tuning was actually fun to do.
@warm imp https://files.sky.h4ck.me/files/0TECrL.png
crazy pronouns
ternary pyramids my beloved
Bro is The Goat
also a Cheater
zipline alert
๐ฅ
And a Demon
lol
I dont have intents
๐ญ
anything wrong????
i have 1 million views with 200 files lmao
i dont really remember but i think its mostly understanding everything overall, and just learning all the essental functions and where they come into play
i remember doing the bellman equation
"what are your intents with my daughter"
no thats intentions
thats for SARSA
Ah damn i see. Well if you need any help whenever you're stuck or something i can explain that shit to you and send some slides on that topic.
brb let me type
I really do not have time to help you
Ask someone else here ive given you the resources I can
if that doesn't help then learn the programming language and read the docs of the library you are using
i am trying to hide ratings when a player hasn't played enough matches. i'm trying to use map to remove fields, but they are still showing up. any idea why combined_player distinct_player and overall_player fields aren't being removed here?
Does anyone know how to fix a 402 Namenode error? I am running hadoop on a relatively sized cluster of 10 machines, i had gathered a few tb worth of videos and i am now trying to do some anaylsis on it. However each time my client talks with the namenode it just returns me a 402 error. The whole web doesn't even talk about it and i am pretty sure my config is correct.
the lack of indents tho
maan fuck hadoop i should have used spark from the beginning
oh nvm, u collapsed it
also tip
i think you can do ```js
{
...(condition && {})
}
saw it in some source code somewhere
dont take my word for it though
Is a 9 ms bot ping good? 
thanks ill keep that in mind
guys recently i discovered that you can actually punch a hole in a normal host's firewall..
i read somewhere that each time you send a packet, the firewall needs to go through it's tables and apply certain filtering rules on the packets. However this takes a bit of time, so a hole occurs in the firewall. So if you spam packets you can actually go through the firewall.
Idk if it's fixed already, but it was about iptables, the firewall filtering linux used.
O.O?
Are you using typescript?
nope
damn
Typescript on top
what i'm doing should work. it works here
spreading will overwrite whatever is being spread before
i'm still seeing the overall_player field when playerRating.matces < mathes_until_ranked. it should be replaced with undefined
i must be doing something else wrong
that or what is before ?? is not null
lol
playerRating.matches is 3 and matches_until_ranked is 5 in the response i get from the endpoint
Actually that makes sense
thanks Tim!!
?? is such a funky operator, but also I get the logic. 2 boxed to bool is true
Ive had weird bugs pop up because of ?? I didnt have issues when using ||
I cant figure how to turn on my bot
Bruh you coded it?
Kinda?
Can you send the GitHub repo?
In here
Ye
here is it
this it what i got it off
I found a newer one
Ohh this bot
I am just trying to make a good bot lol
Or he is trying to create a "new" bot with code from many other Bots?
still not something he made
they have slightly difference precedence, but they are both still below comparisons
so either way
True
No i copied it and i am going to do the whole thing over
I do not help people with cloned bots
I am just getting the based down
Not clonning
someone else might help you
It sounds like you dont even have programming knowledge or knowledge of the discord.js library
Your time would be better spent learning js
I am just trying to get the base down to get customize it
I understand that, but helping someone with no programming knowledge is like shooting yourself in the foot
if you dont have the basics down at least
take it easy
huh
Real
How am I being rude?
Passiv aggressive
Its almost as if you guys havent said the same things ๐
its not being passive aggressive its being truthful
Im not going to sugar coat my words to make him feel better, I'd rather get the point across
this code uses discord.js v12 which is very old, latest version is v14
oh
Its a modded Code by @rigid juniper
Migrating from v12 -> v14 will be hard enough as is
Ye
Should i just delete it all
๐คท๐ผโโ๏ธ
do you have any knowledge of programming/coding in general?
if no, are you interested in learning?
or are you just interested in getting a bot running with minimal effort?
I want to learn
And become a progammer
But i dont really have experience or knowledge
alright, then i would recommend starting with some basic tutorials for a programming language
nuh uh i only picked that because i dont know how to start
this is by far the best resource
javascript.info has a lot of useful chapters on the language that teaches you the ins and outs
Will i learn it fast or no
Ehhh
It all depends on the effort you put in
if you are willing to put the time into learning it, you will achieve great things
you can get the basics down in a couple weeks, become alright at it in a few months
Yessir
I say this with experience and from countless other testiments. Making a bot as your first project is not a good idea. It doesn't teach. you what you need to know most of the time, unless you have a clear goal and know what you need to use
It's better to get the basics down, then try and make a bot.
Many People are seeing "Easy To Use Discord Bot" and thinking they can learn programming with that.
funny that literally everyone who says that did it first lmao
making a bot as a first project xD
well you can only learn from your mistakes, not from the mistakes of others
I tried to make a WhatsApp bot
and wasted a lot of time
so if they wanna make a bot as first project, let them have it
very true, which is why anything I say is really a matter of opinion, you can take heed what I say and still do it. its more of me just telling them it can be a challenge
Many people learn best when challenging themselves, I myself am like that
I also like the pain and suffering that comes with programming apparently

I learn from seeing Things
masochist
What can I say tim, you grow to love it 
Its so satisfying when you finally do something and it works
only to later realize what you just did is useless

After some "Syntax Error"
xD
I can't tell you the amount of times i've removed/added things in my backend
only to realize maybe I shouldn't have done that, or maybe I actually needed that

I did it so many times until i noticed i forgot ")"
In which file do you have 160 lines?
I probably wouldn't have gotten into programming or computer science at all if it wasn't for discord bots
I mean npm init -y creates a new Project
Package. json
I'm a person that likes to dive straight into something practical, I get bored with the theory and prerequisites quickly
Yea its fine in that file
ok
why is package.json 160 lines lol
idk why i have so much
If you use alot of packages ๐คท๐ผโโ๏ธ
Or other Stuff
i mean, a blank package file in a new project lel
Well that shouldnt have 160 lines
Blank
then you should start with 0 packages anyway
Nothing in it?
Yep
Yeah except my node_modules
And package.json, package-lock.json?
Yeah
You got all packages that are in package.json
Yeah
that will only install packages if you have a package.json with packages in it, not from an empty one lol
did you copy the package.json file from github?
Yea now it makes sense
Should i just make a new folder
show the contents of your package.json
idk
where did you copy that package.json from
lmao
just delete everything
The folder?
delete everything in the folder
Yes.
then run npm init -y
wow theres only like 3 things now lol
there you go lol
Fresh Project ๐ฅ
wow
now you only need one package to start working with discord, there are many to chose from
but discord.js is the most popular one
Yeah i wanna use that one
done
And start coding
this file is where you will write the code
I made it
then go to the discord.js website and check their quick start example
If the bot gets complicated i would recommend sub folders like ./Commands
can deal with that later
Yessir
did you check the example in the discord.js website?
I found guide but not example
// Require the necessary discord.js classes
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
// Log in to Discord with your client's token
client.login(token);
Thats the Example code
I put that in my index.js
okie
After that the Guide Shows you how to create slash Commands
Where is says client.login(token) do i put my token
Create a config.json file and put this in it: ```{
"token": "your-token-goes-here"
}
Change it with your bot token
Ok did that
Open a terminal in your folder with index.js
k
gj
Ty
gg
Now try to create your First command
Should i make a folder called commands?
Well if the guide said so yes
So i made a sub folder and now i got to make a file. what should i call the file in the sub folder called
Ping.js
k
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
},
};
Save
saved
And restart your bot
k so how again
Does your bot have a /Ping command now?
no
missing the deploy step
Oh
Yea
module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};```
This it?
^^^^^
Nah
growth will stagnate
My bot is Active since 1 week lmao
I was around 10,000 servers before I pulled the plug
Over 6 years
music bot too so was a popular topic
Until YouTube ruined it lol
You can only stream one track from spotify if you really wanted to be a masochist and base a player off of its api
Where do i put this
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();```
deploy-commands.js
node deploy-commands.js
Did you set config.json?
{
"token": "your-token-goes-here",
"clientId": "your-application-id-goes-here",
"guildId": "your-server-id-goes-here"
}
I did that
"token"; "",
"clientId"; "",
"guildId"; ""
}
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();```
The info is filled in at the top
Nooo
oh
Do this in config.json
๐
this is the part of the guide i disagree on, but if it helps to make it its own file then all the more merrier
๐
What I said earlier was just a forewarning that it doesnt always work best for people
wasnt to discourage you to give it a go
also, whenever possible try to read the code and learn what is going on
for example, every time you see the line require('./config.json');, that means its loading the config.json file
and reading its contents
oh ok
the require function is how you load files in node
you can load packages, js files and json files
Anyways good Night ๐ค
you should also learn how to work with variables, as they are the most fundamental concept in programming
the keywords var const let is how you create variables in javascript
a variable is a name that holds a piece of data
for example if you do const config = require('./config.json');
that means you are reading the config.json file and saving its contents in the variable named config
which then you can access its contents from it, for example config.token will access the value of the token
Is var still frowned upon in a lot of cases due to its ability to ignore scope?
right
Also, if you only need specific keypoints of something, you can destructure it
const { token } = require('./config.json')
boolean, number, string, object
alr
almost pulled out i32 until I remembered this isnt rust
xD
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();```
Does this go in my index.js
yes
So it should look like this
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
// Log in to Discord with your client's token
client.login(token);
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();```
js always does his best :)
pay attention to the code
avoid repeating lines unnecessarily
whataver a line of code already did, it doesnt need to be done again
Ohhh
so i can just put that one under it abovce
So like this
const fs = require('node:fs');
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
// Log in to Discord with your client's token
client.login(token);```

Honestly why do they pass the client into the ready event
you typically have access to it at all times
ig in cases where you separate it fro mthe scope of the client
its not the client, its the events enum
in like a handler
readyClient is of type Client<true> no?
ah you mean the param
yea
all events give you something to use in the param ye
the only way I see that being viable is if you take the listener out of scope of the client, but even then you're using the client to listen to the event
:p
you can define the handler in a separate file for example
unless someone does function(client) {} as the listener
then ig so because it creates its own scope, and ignores anything outside of it (I think)
Something isnt working
What errors do you get
ReferenceError: Collection is not defined
You have to import it
^
add it to your const {...} = require('discord.js')
I feel like this is wrong
const fs = require('node:fs');
const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
// Log in to Discord with your client's token
client.login(token);
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});```
ngl dont even know where that goes
find the difference between those two lines
So i should delete that bottom one
read the lines
Oh wait
and find the difference
event and collection
One has something the other should
the words inside the {} are the components of discord.js that you are importing
Read this error back
your error stated that Collection was not defined, because you forgot to import it
How to import it

my late grandma used to make an amazing tomato soup
with just onion and tomato sauce
and water
im sorry but campbells tomato soup made with water is disgusting
f u
like instant soup?
never seen instant soup that is done with milk
it gives it a bad aftertaste
@_@
btw tim is this correct?
I haven't used js in a while
so I forgor a lot about it
like anything defined outside the function can still be accessed
oh wait
nvm I am thinking of something else
function doesn't preserve the outside scope in the sense that this is not the same as what the function is being used inside of
it becomes the function
so if I was using function anywhere inside a class method, this no longer refers to the class it refers to the function
arrow functions on the other hand doesn't cause such a thing
yes
this inside a function is defined at function runtime
arrow functions on the other hand, their this is defined at define time

like if you define a function and then assign it elsewhere
the this inside it can change
based on where you assigned it
thats why things like someclass.prototype.abc = function() { this } work
the this is defiend when the abc method is run
the class instance
if you then do otherclass.prototype.xyz = someclass.prototype.abc
the this will be the otherclass this, not the someclass this
I don't remember the exact case of what happened but roughly I was doing
someMethod(){
SomethingFromSomePackage.on('someevent', function(someprop) => {
// needed something from the class
this.whatever // well this.whatever doesn't exist because its being overriden by the `function`
})
}
if you want to keep the this unchanged yes
is there any times where function is better to use?
an arrow function will use whatever was the value of this when the function is declared/defined, not when its run
quite honestly dont remember the last time i've seen someone use function over () => {}
you always use function whenever the function has a this that needs to be assigned based on context
honestly cant say i've ran into a case like that yet
and always use () => {} whenever you want to use a this from outside, inside it
and by context you mean how its called right?

its very useful to create dynamic classes tho
btw do you understand ts decorators?
for example you have several versions of a method, and depending on some parameter you can hot-swap the different versions of the method
like if you have one method that only works on node, and another that works on browsers
you can detect the environment at runtime and edit the class prototype to the correct method
icic
more or less
I don't
dont like them thatr much
I tried making my own and it sucks

I was making a class decorator that added slash command metadata to it
Why would i do that instead of making it part of the class? idfk I wanted to try decorators

I honestly don't see the appeal of them yet I see so many packages use them
i dont quite see their usefullness either
i had to learn about them when i had to learn about angular to teach a class abot it lol
I mean ig its useful if you don't necessarily need all those properties on the class
you dynamically add them with decorators

yea thats my point
I can see why but there is other options
it just doesn't make sense for a language like ts
Just mostly syntax sugar. Java benefits from it massively when combined with reflection, people got used to the pattern and probably wanted it in other langs that donโt necessarily benefit from it
wtf is a colored function
https://langdev.stackexchange.com/questions/3430/colored-vs-uncolored-functions reading this it sort of makes sense
but i've never in my life heard of this terminology
From what I can tell is that a colored function is something that must be run in something that also takes on a similar signature
like rust async functions must be called using await but you can't use await outside of an async function, so therefor the function making that call must also be async
whereas go has async functions but are called similarly to sync functions. Meaning whatever is calling that function doesn't HAVE to have the same signature as the function being called
Please someone let me know if I am wrong :p
nobody calls them colored or uncolored
not sure where they got that from
oh this is langdev section
they might have their own terminology
I assume they do
It's my first time hearing about it, which came from a youtube video on a new programming language and I decided to google it
that was the first page I saw talking about it

colored functions are more diverse and come from multicultural backgrounds
such an inclusive and thoughtful statement tim
gotta raise my ESG score
does anyone have experience with Twilio SMS verify API
you can't pass a custom code without having a paid plan
so im trying to get the SMS code it sends
but its not working
i spent like 4hours today to generate a mandelbrot set on a pixel sheet using c.
It's actually really cool, it has a strong link to the chaos theory.
where one pixel 'activates' another pixel. It produces pretty sick images as well
it reminds me of synapses for some reason
is there any nodejs package for ssh2 that handles all sftp events for me? I dont want to reinvent the wheel for that
sort of like a game of life
now make a mandelbrot zoom animation 
Yeah, game of life is based on the Mandelbrot sequence iirc
๐ญ๐ญ๐ญ
ughhhhh changes ur sys lang to english if cool
Why?
is gwn beter โค๏ธ
how would i get the total ram a system has through java?

(i dont know java at all)
oshi is a PITA and will probably break once i update it but yeah that works
look at the source!
Ayoo ben je ook Nederlands?
oh
it builds on my machine

ah yes
i redeploy
and it builds
how interesting
(same code)
ofc
Process flops 1.322960
Process flops 1.323176
Process flops 1.054708
Process flops 1.053313
Total flops 2.667088
could someone enlighten me
i am using openMPI to calculate the amount of gflops my parallel program makes.
i used 4 threads, the imbalance is like 1.3. Is this considered high? Second of all, how the fuck do these numbers add up to the total gflops count?
@radiant kraken gaming
I dont know much about flop calculations, but its likely to do with inefficiencies in multi threaded processing.
So each thread on its own can get 1-1.3 but you lose some when doing them all at once.
Unless your threads don't depend on each other entirely you're going to lose some 'gain' with each thread
pog
Ahhh I see, so basically mpi adds an overhead for each action as well as the initialization I think
hey im using native discord.js sharding on auto, my bot is in 513 servers and its hitting rate limits for some odd reason. i dont know why. auto sharding is just 1 shard, should i raise it to 2 shards manually or more? or should i switch to discord-hybrid-sharding with clusters and idk if that will work better
what rate limits are you hitting?
thats related to excesive login attempts
ie bot constantly crashing and restarting
its prob crashed like once an hour? i fixed the error just now i was sleeping
i changed the port but i guess discord goes by IP
maybe the bot was on a crash loop while you were sleeping
if you check the headers from gwateway 429 it will tell you how long you have to wait to login again
you can also try logging in from a different machine
Does discord.js tell you the headers? It just tells me the body
Welp I've moved it to Germany vps for now
ayy germany
I wonder how long it'll take for the rate limit to clear
Because I can't see the headers
its usually 24 hours
whut
most gateway 429 are caused by a cloudflare ip ban
Alright I'll move it back tmrw I guess
its unclear what triggers it exactly, but its usually too fast repeated login attempts
hmm
you can manually make a request to /gateway/bot from any http client
A post request? Or just a get or idk maybe a patch or put
I don't need to send any headers or body right?
you need to send the bot token in the headers
its a get
Ah no body needed either?
Alright so I just needa do console log the headers from the response?
ye
Alright
Also sometimes my shard takes forever to be ready it's finished all of its tasks for the client and it should be ready so it just dies for taking too long I have auto respawn on and usually it takes 10 mins to go online. Is there a reason for this? Saw some people had the same issue on GitHub they made a issue but no updates from discord.js or anything. Changing the IP doesn't help.
Even if I dont shard if I just straight up run my client it doesn't want to go ready then.
Hmm I should do a speed test on my vps then
it can also happen when there are bugged guilds
you can check whats going on by listening to the raw event
Hmmm I'll look into that
I see there's a client.on raw but is there one for shard.on for native discord.js sharding?
its the same thing
shard events are emitted through the client
Ah ok
hello tim
h
im gonna assume its bugged out guilds, speedtest looks decent
https://www.speedtest.net/result/c/ba3eca5a-10ee-4e6e-944d-1feede8303fa
Dubai? 
what event should i be looking for? in raw or should i jsut listen to all the data/packets
console.log(raw)
})```




