#development
1 messages Β· Page 158 of 1
ayyy
π
Actually
just noticed something
It will always be 1 socket no matter if they supply otherwise cause of this dumb error TypeError: Cannot read properties of undefined (reading 'sockets')
I don't see why options isn't properly being attached
import { EventEmitter } from 'events';
import { SocketManager } from './';
import { IClientEvents, IClientOptions } from '../';
import { GatewayIntentBits } from 'discord-api-types/v10';
export declare interface Client {
on<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void): this;
once<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void): this;
emit<K extends keyof IClientEvents>(event: K, ...args: IClientEvents[K]): boolean;
off<K extends keyof IClientEvents>(event: K, listener: (...args: IClientEvents[K]) => void): this;
options: IClientOptions;
socketManager: SocketManager;
token: string;
}
export class Client extends EventEmitter {
public socketManager: SocketManager;
public token: string;
public options: IClientOptions;
constructor(token: string, options: IClientOptions) {
super();
this.token = token;
this.socketManager = new SocketManager(this);
this.options = options;
}
public async login() {
await this.socketManager.connect();
}
}
Anything you guys can see that I seem to be missing cause this looks fine, so I don't think this is the root cause
constructor(client: Client) {
super();
this.client = client;
this.sockets = this.client.options.sockets ?? 1;
}
this is whats in SocketManager where the error is occuring
Can you show exactly where this error occurs?
Oh

funny enough in Socket which requires SocketManager to use the client values it works fine
only SocketManager gives issues
You're assigning the options after passing it to the SocketManager
I don't think you understood, you're trying to access the options property in the constructor of the SocketManager class, but it doesn't have a value yet, so you'd have to assign the options property and then pass it to the constructor
I see
I can likely move it to my #createSockets method
#createSockets() {
this.sockets = this.client.options.sockets ?? 1;
for (let id = 0; id < this.sockets; id++) this.socketStore.set(id, new Socket(id, this));
}
Would this be fine?
Why not just do this in the Client constructor?
this.options = options;
this.socketmanager = new SocketManager(this);
What did you think I meant? 
idk why it took you to say that to get it
Honestly no fucking clue
I just brain farted there
Makes sense now that you pointed it out that SocketManager was trying to use it before it was assigned which I thought you meant in the SocketManager class itself not in client
Heh it happens
Oh shoot
I just realized something else I made a goof of
π©
using a normal for loop to loop through the shards to connect wont work
for (const [id, socket] of this.socketStore) {
const shard_bucket = id % session_start_limit.max_concurrency;
const previous = bucket[shard_bucket];
const current = Date.now();
if (current - previous < 5000) {
setTimeout(() => {
this.connect();
}, 5000);
} else {
bucket[shard_bucket] = current;
await socket.connect();
}
}
Unless im mistaken, this will loop through all the shards and connect the first one, but once it reaches the second shard in the loop it wont work cause 5s hasn't passed.
Actually wait no, it should work cause I call the this.connect method again
so its recursive and will keep calling until all shards are connected but because of what I am doing this is bad
each time the bucket variable is overwritten so any previous shards recorded as being connected will be gone, I need to make it a class variable
or no I can't π©
use promise chaining instead of timeouts
hm?
Hello guys this is my brother bilo
ok, now off to #memes-and-media
How would this make it connect if 5s has not passed?
well, it wont, it'll just ensure it doesn't try to connect the next shard before the first finishes
isn't this what u want?
Are you trying to wait 5 seconds after the previous shard has connected? I don't exactly know what you're trying to do here
When sharding discord only allows a certain amount of shards to connect concurrently, so the point of this is to follow that and only connect x shards every 5s
so if 5s hasn't passed when those shards connected than it should continue to check if 5s has passed until it finally has before connecting the next shards
https://discord.com/developers/docs/topics/gateway#sharding-max-concurrency this explains more of what I am trying to achieve
sorry wrong part
From what I'm seeing in your current implementation, you're connecting one shard, and then waiting 5 seconds to connect the next shard instead of doing it concurrently, is that what you intend on doing?
Not really
tim told me thats how he did it and I thought it'd be fine to do so for now which in truth it is
but I realize I wanna implement the full thing right away to get it over with
Yet I don't know how i'd go about doing so
Any idea? Cause reading the documentation on how it works and trying to apply it doesn't seem to be working.
cause if they are trying to load multiple shards and only able to concurrently load 1 shard every 5s then id % concurrency will always = 0
so every shard will be the same modulo id so it should wait 5s between in shard, yet it doesn't seem to be doing that, it simply just doesn't load any shards now
Your implementation is mostly correct (though I think you got it from Tim), you can just halt the loop with a promise waiting the amount of time needed to connect to the next bucket of shards
Basically:
import { setTimeout as setPromisedTimeout } from 'node:timers/promises';
...
if (current - previous < 5_000)
await setPromisedTimeout(5_000);
// Connect the shard here
I indeed got it from tim :p
If the time set for the previous shard bucket is less 5 seconds then it's highly likely that the next shards in the shard bucket have a value of less than 5 seconds, so doing that will wait the amount of time necessary for it to be higher than 5 seconds and for the next ones to be available for connection
Although actually you should just hardcode waiting for 5 seconds just in case, not the diff, let me edit
There we go
That's unnecessary because it would just wait then reach the connection part, see how I left the connection part outside of the if statement?
hum
Maybe im not understanding the code properly
cause to my understanding the bucket will hold all shards that can currently be identified which mind you depending on their max_concurrency can be 1-16
Basically:
- Get the previous shard bucket time value
- Is it less than 5 seconds?
- Wait 5 seconds to let the next set of shards become available for concurrent connection
- Connect current shard
So if only 1 shard is in the bucket, it'll load, but now the bucket is empty and won't be filled again cause its not filling it later
async connect() {
if (this.socketStore.size <= 0) this.#createSockets();
const { session_start_limit }: APIGatewayBotInfo = await fetch('https://discord.com/api/v10/gateway/bot', {
headers: {
Authorization: `Bot ${this.client.token}`,
'Content-Type': 'application/json',
},
}).then((res) => res.json());
const maxConcurrency = session_start_limit.max_concurrency;
this.#bucket = Array(maxConcurrency).fill(0);
for (const [id, socket] of this.socketStore) {
const shard_bucket = id % session_start_limit.max_concurrency;
const previous = this.#bucket[shard_bucket];
const current = Date.now();
if (current - previous < 5_000) {
await setPromisedTimeout(5_000);
}
this.#bucket[shard_bucket] = current
await socket.connect()
}
}
From my current code to me it looks like thats not what happens tho
To me it looks like it Loads the bucket, identifies the shard and stops
unrelated but is that content type really necessary when it's a GET request
likely not, force of habit tho
after I spent 3 hours debugging a delphi webserver, I always add User-Agent and Content-Type headers
regardless of whether they're needed at all
yeah, some APIs refuse to respond or errors if you don't set a user agent header
ESPECIALLY GitHub
lmao
learned that the hard way
what agent do u use? Mozilla/5.0?
lmao no way
The shard bucket contains all of the shards that can be connected, with the rate limit key assigned to each of them obtained from shard_id % max_concurrency (shown in the official Discord documentation, the one you linked)
For example, let's say you have 32 shards, the shard bucket would be:
shard_id: 0, rate limit key (0 % 16): 0
shard_id: 1, rate limit key (1 % 16): 1
shard_id: 2, rate limit key (2 % 16): 2
shard_id: 3, rate limit key (3 % 16): 3
shard_id: 4, rate limit key (4 % 16): 4
shard_id: 5, rate limit key (5 % 16): 5
shard_id: 6, rate limit key (6 % 16): 6
shard_id: 7, rate limit key (7 % 16): 7
shard_id: 8, rate limit key (8 % 16): 8
shard_id: 9, rate limit key (9 % 16): 9
shard_id: 10, rate limit key (10 % 16): 10
shard_id: 11, rate limit key (11 % 16): 11
shard_id: 12, rate limit key (12 % 16): 12
shard_id: 13, rate limit key (13 % 16): 13
shard_id: 14, rate limit key (14 % 16): 14
shard_id: 15, rate limit key (15 % 16): 15
shard_id: 16, rate limit key (16 % 16): 0
shard_id: 17, rate limit key (17 % 16): 1
shard_id: 18, rate limit key (18 % 16): 2
shard_id: 19, rate limit key (19 % 16): 3
shard_id: 20, rate limit key (20 % 16): 4
shard_id: 21, rate limit key (21 % 16): 5
shard_id: 22, rate limit key (22 % 16): 6
shard_id: 23, rate limit key (23 % 16): 7
shard_id: 24, rate limit key (24 % 16): 8
shard_id: 25, rate limit key (25 % 16): 9
shard_id: 26, rate limit key (26 % 16): 10
shard_id: 27, rate limit key (27 % 16): 11
shard_id: 28, rate limit key (28 % 16): 12
shard_id: 29, rate limit key (29 % 16): 13
shard_id: 30, rate limit key (30 % 16): 14
shard_id: 31, rate limit key (31 % 16): 15
Now we iterate through all 32 shards and do the following:
- Obtain rate limit key (in this example of 32 shards, if the previous rate limit key was 31, it would go back to 0 with the calculation we do)
- Get the previous time set in shard bucket with the rate limit key
- If the previous time set is less than 5 seconds, not enough time has passed to start connecting the next set of shards, so wait 5 seconds
- Overwrite the previous time set in the shard bucket with the current time we calculated
- Connect the shard
did u really type that on mobile?

Of course
I mean, what do you expect when I maintain Node.js, V8, LLVM, and more on a phone
that one was to bypass CF, it worked
Received Hello. First heartbeat in 27583ms (Interval - 41250ms
Identifying (Shard: 0)
Logged in
Received Hello. First heartbeat in 37942ms (Interval - 41250ms
Identifying (Shard: 2)
Received Hello. First heartbeat in 12313ms (Interval - 41250ms
Identifying (Shard: 1)
Logged in
Logged in
Received Hello. First heartbeat in 32946ms (Interval - 41250ms
Identifying (Shard: 3)
Received Hello. First heartbeat in 619ms (Interval - 41250ms
Identifying (Shard: 4)
Logged in
Sending Heartbeat
C:\Dev\shensuo\src\core\client\socket\Socket.ts:47
if (!(data && data.d && data.op)) return Promise.reject(new Error('INVALID_REQUEST_SENT'));
^
Error: INVALID_REQUEST_SENT
at Socket.#send (C:\Dev\shensuo\src\core\client\socket\Socket.ts:47:59)
at Timeout._onTimeout (C:\Dev\shensuo\src\core\client\socket\Socket.ts:119:16)
at listOnTimeout (node:internal/timers:573:17)
at processTimers (node:internal/timers:514:7)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
it was working till it wasn't

I think I know what happened
It was likely trying to send a heartbeat
I think sending heartbeats while sharding is different
simplify your logic to
if (!data || !data.d || !data.op) ...
wont fix it but got damn do I hate if (!(expression))
Actually I don't think heartbeating with shards is any different
if (!data?.d || !data?.op) ...
Optional chaining isnt in a lot of node distributions. I know someone who still uses v12
I would never
skill issue using eol
if (!Object.keys(data == null || typeof data !== "object" ? {} : data).some(k => ["d", "op"].includes(k))) ...

if data is undefined, that will throw an error pretty sure
there
Null coalescing was added around the same time as optional chaining
bro wtf
my brother in christ
https://paste.gg/p/anonymous/649d58b882db458bb1ea512076408cb2 this is the data that gets sent to the gateway, it seems to error on the last heartbeat, which makes sense cause I don't think discord like d being 0 it has to be null or >1
yet idk why its being set as 0 to begin with
nvm I do

The d for heartbeat has to be your last received s
yea
which if you didn't receive one should be null by default
yet I stupidly made it 0

Hello 
wait what
Maybe that isn't the issue?
yea no its an issue with sending the heartbeat but why
π©
Oh im fucking dumb
!null -> true so ofc its going to error cause it fulfils the condition

Why does this actually work
π©
it looks so weird
Time to use it
because for js everything is a map
fair enough
arrays? map
strings? map
numbers? believe it or not, map
boolean? yep, you get it
why does that make sense
?
oldEyes
Wtf
What Kuu's snippet does is just check if those keys are present in the object
in a very convoluted way
if (
data == null /* compares to both null and undefined */ ||
!('d' in data && 'op' in data)
) { ... }
// or
if (
data == null ||
!('d' in data) ||
!('op' in data)
) { ... }
// though doesn't matter
Sharding is interesting
Should I also add auto sharding which will use discord's recommended shard #?
Alright
https://hastebin.com/share/zinipizajo.typescript what you guys think?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
actually would doing this
for (let id = 0; id < (this.sockets === 'auto' ? shards : this.sockets); id++)
this.socketStore.set(id, new Socket(id, this));
``` be better than doing a if/else?
The second clause of a for loop is evaluated on each iteration so I'd recommend putting that outside the loop, basically assign the value to a variable
Even though it'll most likely be optimized anyway, you should try to put such evaluation outside just in case
I ordered an additional IP address at my vps provider
The server lost its internet connection and I'm connected via VNC
Netplan isn't installed for some reason
Can some1 help me out?
You're welcome Misty
What provider
contabo
Did you get an email from them when they finished setting up your ip?
Okay, did you read the part where they don't auto configure the ip for you so you must do it yourself
I know
I tried to
Netplan isn't installed for some reason
Something happened and now it doesn't have an internet connection
when you were doing these configurations did netplan apply work?
okay, so what did you do during this that caused you to bork your vps
without running netplan apply it won't change anything even if you reboot
- ip/18
yeah
i edited it
rebooted
thats all
since netplan didnt work
Then you did something else
let me list all the commands i did
are you able to show your current netplan file
yes
show it
blurring cuz im a lil monkey
all the commands I did in order, and response if needed
nano /etc/netplan/01-netcfg.yaml
netplan apply
- netplan: command not found
netplan
- netplan: command not found
netplan generate
- netplan: command not found
sudo apt install netplan
- unable to locate package
(cleared out my screen sessions as they were not used, all weren't running anything)
sudo reboot
that's literally it
Simply download the Netplan .deb file on a machine that has internet connection, move it to the VPS using something like SFTP, and run sudo dpkg -i <path/to/.deb/file>
I can't move it over as it isn't connected to the internet
It's a vps
I only have vnc access rn
as long as the vps is on, you should be able to SFTP into it no?
I mean you could try to do a recovery or wipe the vps
but I don't think thats needed
there is probably some other underlying issue here
what does your firewall look like might be you fucked up your config there somehow?
run ufw status
assuming your ssh port is still 22 then yea you should be able to ssh into it
It doesn't have a connection to the internet
The VNC server is on a different machine
Who is just relaying the inputs and ouputs
I just don't get how your vps could not have internet access, I don't think contabo even allows you to fuck up that badly
How certain are you that its a internet issue, what happens if you try installing a package or whatever
or even using curl
What happens when you run the following in order?
$ sudo apt update
$ sudo apt full-upgrade
$ sudo apt install netplan.io
The package may hopefully be cached, try the third command
What is your nameserver in the /etc/resolv.conf file?
checking
127.0.0.53
Try changing that to 8.8.8.8
who told me this was correct like 4 months ago? 
class PassThrough64K extends Duplex {
constructor() {
super({
read() {},
write(chunk: ArrayBuffer) {
let chunkCount = Math.ceil(chunk.byteLength / size(64).kb()), index = 0
while (chunkCount) {
this.push(chunk.slice(index, index + size(64).kb()))
index += size(64).kb()
chunkCount--
}
}
})
}
}```
it seems like its just forgetting some chunks
probably just last or first
Doesn't work, Contabo replied
nvm, something else is broken
ooh
What did they say?
How hard did u mess up? Haha Iβd like to know so I donβt do the same π
Creds
Nothing sensitive on there besides a website or two
Changed it right before
But yeah waiting rn
I will be forwarding your email to our technical department for further investigation. You will receive an answer as quickly as possible, but in the meantime, we kindly ask for your patience.
ok then
How can you DM user who adds bot to the server? Apparently you can only do it via audit log? π€·
Which I don't believe, cos bot would need access to view audit log, which doubt.
you can figure out which user invited a bot
that requires viewing the audit log
so yes, that is not possible without audit log perms
Alternatively, there's the oauth2 flow iirc
you can do a bit of trickery and include a oauth that tells
yeah that
tells your bot when it was invited successfully
Ahh okay, that sounds better, ty
you have docs for this mate? or video or w.e
nah
just look into how oauth on discord works
okay ty π
this just scared the ||SHIT|| out of me
thought I got banned or summin π€£
good lad
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
π€£π€£π€£π€£π€£π€£
One message removed from a suspended account.
you've lot the plot
One message removed from a suspended account.
One message removed from a suspended account.
lmaooo
and if you're already logged in, just sends you to the login page

One message removed from a suspended account.
One message removed from a suspended account.
same
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
π€£ this made me chuckle
cursing is an expression of freedom and also tension release
very healthy
with that said, heres some blyat cyka jobani urod idi nahui pidar cyka :^)
and also some jebo te tri silosa zita zrno po zrno in za vsako zrno tri picke materine
and also some portugal caralho!!
GatewayEvents[data.t!] returns undefined
import { MessageCreateHandler, GuildCreateHandler } from '../';
export const GatewayEvents: Readonly<Record<string, Function>> = Object.freeze({
MESSAGE_CREATE: GuildCreateHandler,
GUILD_CREATE: MessageCreateHandler,
});
Am i misinterpreting how Object.freeze works?
I now know the reason is because of hows it typed ig
but still
export const GatewayEvents = Object.freeze({
MESSAGE_CREATE: GuildCreateHandler,
GUILD_CREATE: MessageCreateHandler,
});
even as this it gives an error that type any cannot be index by type string
freeze makes all properties of a depth of 1 readonly
children of the frozen child can still be edited tho
I dont see how this pertains to my issue of not being able to index the Object once its been frozen via a string because of how stupid typescript's type safety is
TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Readonly<{ MESSAGE_CREATE: (client: Client, data: GatewayGuildCreateDispatchData) => void; GUILD_CREATE: (client: Client, data: GatewayMessageCreateDispatchData) => void; }>'.
This is the error, ig I forgor to post the new one
You can't edit a frozen object
you can cast the key as string
thing[key as keyof typeof thing]
But no matter what its undefined then
Then the key you're using doesn't exist in the Object
alternatively, use Object.getProperty
Have you tried logging what data.t actually is
I mean, I console logged data.t
so yea
I console log it as each event is passed through
READY -> GUILD_CREATE
Have you perhaps considered that you donβt have a READY prop π
I would if not for my switch case already handeling READY so the default doesn't care about that specific event
if READY is logged as an attempted key access, then it's no wonder you'd get undefined
Loosely.
When you go to access the GatewayEvents, I'd just double, nay, triple check what your accessing is valid
If you are referring to this, this is simply the chain that events get logged top level, not inside my switch case. My switch case already handles ready event triggers and default takes care of the rest
Actually it doesn't even seem to be a problem with that
I might just be dumb and trying to do the impossible
wdym
Well I indexed it myself with a key and it still returns undefined despite it 100% existing
so doesn't seem to be an issue with using data.t at all
insane
you forgot a READY: ReadyHandler here 
They insist something else handles ready
Anyways, my values are exported functions which likely aren't allowed to be done this way
this?
oh okay
wdym arent allowed

Yea well then I have no idea why my strange case is happening
despite everything it claims it is undefined so i give up
provide more code and I'll take peek
like where you access the Object
https://github.com/shensuojs/shensuo/blob/master/src/core/client/socket/Socket.ts#L143 this is where I am trying to access it
what does console.log(GatewayEventHandlers) do?
where are you seeing this at
the line you've just showed?
youre seeing wrong
I mean if indexing GUILD_CREATE makes it return undefined then it would just be an object with the values being undefined
such as this
then the constants you define are probably undefined
I don't see how
Unless im not able to reference a function like how I am
since looking from your codebase structure
i can see why you could mistake to things might not exist
hm?
you probably forgot to export/import those handler functions somewhere
if I did that typescript would be erroring even before everything else
is it allowed to join discord servers that your bot is in using the bot to generate the invite link?
Nope
oo
i doubt that the constants are randomly set undefined during runtime
it's most likely undefined from the very beginning
Highly possible, but I don't see how
^
or something related
Again I don't see anywhere im doing such a thing
@sharp geyser can u refer me to where it says this because I can't manage to find it
maybe it's from the ordering of imports here?
since client is imported before socket
since iirc node reads JS files line-by-line, ordering of imports matter, no?
@sharp geyser
yea I think you're right
as importing directly from the handlers file seems to work fine
wait i meant this file https://github.com/shensuojs/shensuo/blob/master/src/core/client/index.ts
@sharp geyser if u got time ^
Its not inherently stated, but it is very much frowned upon. So ig I should rephrase my answer
Shouldnβt matter? JIT doesnβt imply line-by-line execution
Idk why importing from a barrel file causes issues
but directly importing from the folder where those handlers are works fine
This is an issue in production as well if said issue occurs for people when importing things
i meant read line-by-line
or something idk
@earnest phoenix
does reordering the imports fix it?
No
sad 
I think internally I should just import directly from those files until some contributor figures it out 
Cause my dumbass can't tell why doing so from the root folder which exports everything from those folder/subfolders anyway breaks
Anyway
Events work :)
nice
Now to pain stakingly write out the classes that model the data 
good luck on writing your own discord framework, as an ex-discord lib dev, you're in for such a ride

I've done it before but gave up cause I saw no one using it
Its a struggle when you try and do it properly
with a gap of 6 months from coding any proper project

because people would just use discord.js
why would they use any other third party library
because mine isn't as cancer as discord.js ||this is false but dont tell them||
frfr
ugh writing out classes is annoying and I could probably be doing this in a much better way but meh
You'd love Java 
Tbf most of my Java experience was school and minecraft
I've never had an actual teacher teach me any programming
its all self taught, which explains why im so bad at it 
Java is a decent language
I also learnt Javascript & TS fully self taught, and the only programming knowledge I had before that was Scratch (and like hello world python)
same tbh, but i'm actually really good at most of the things i know

self taught >>>
Im not cause I am the kind of person that strives when things are explained to me like im 5 years old

Fucking spoke too soon
Now for some reason im not receiving message content despite having it enabled on the bot page and asking for the intent when identifying
π©
Are you subscribing to the intent?
Yep
I faced this issue before but I don't remember what I did to solve it
32769 is the sum of GUILDS + MESSAGE_CONTENT
thats what is being sent to discord
It's very different to actually using java
It's a whole different experience
Schools usually constrain you to java 8
You shouldnβt be adding
Which is bad
You should be using bitwise OR
Technically it shouldnβt matter if the bits are unique but just to make sure
32769 is correct
Thats for receiving messages no?
You dont need it to fetch or recieve message context menu interactions
Adding bitflags usually works but yeah, don't do it as you might spend hours debugging to know why it isn't working
Heβs asking about message content
U don't receive messages without guild message intent
When did misty ever say about receiving messages
export function parseIntents(intents: Array<GatewayIntentBits>): number {
return intents.reduce((partialSum, a) => partialSum | a, 0);
}
``` I am
Message content allows reading the messages, guild messages enables receiving message events
Enable GuildMessages
why are there so many intents for messages bruh
Assuming youβre trying to get the event here
U might not want to receive message events if ur bot is a dm-only bot for example
thank you guys
Or purely a lurker like topgg bot
π
But you can?
how
GuildMessages only relate to guild events
Guild messages is just for receiving messages
You can still fetch messages without it
DirectMessages is for recieving the message events in dms
MessageContent is simply just giving you the content of the message but you can still receive them
But how will u get the id?
There's tons of ways to get ids
A user can specify it
yeah i know, which is why you should have either enabled too
Yes, but it'd be awkward to have the user write the id every time
Also how would it even work practically?
This is completely irrelevant to whether you need guild messages intent
A bot without guild messages is a blind bot
All HTTP bots don't need any intents, they use http
And somehow they still work
woah
You can replicate http bot behaviour even with gateway, you can simply just don't subscribe to any intents
But you need a bot application for that still...
Second, they don't need message content either, as they always have the content of the command
U dont
U only need an application
All bots are applications, but not all apps are bots
well ok
An example would be a "bot" that you add to the server, without inviting
Those are pure applications
how do you add a bot without inviting
You use the interactions scope without bot
The bot member never gets added
But the commands do appear
Some bots use this, usually mod bots
Or third party service bots
Message {
client: <ref *1> Client {
_events: [Object: null prototype] {
ready: [Function (anonymous)],
messageCreate: [Function (anonymous)],
debug: [Function: log]
},
_eventsCount: 3,
_maxListeners: undefined,
socketManager: SocketManager {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
client: [Circular *1],
socketStore: [Store [Map]],
sockets: 'auto',
[Symbol(kCapture)]: false
},
token: 'goodluck',
options: { intents: [Array], sockets: 'auto' },
[Symbol(kCapture)]: false
},
data: {
type: 0,
tts: false,
timestamp: '2023-08-15T02:53:35.098000+00:00',
referenced_message: null,
pinned: false,
nonce: '1140840675059695616',
mentions: [],
mention_roles: [],
mention_everyone: false,
member: {
roles: [],
premium_since: null,
pending: false,
nick: null,
mute: false,
joined_at: '2022-03-28T05:04:40.163000+00:00',
flags: 0,
deaf: false,
communication_disabled_until: null,
avatar: null
},
id: '1140840684996272178',
flags: 0,
embeds: [],
edited_timestamp: null,
content: 'asdasd',
components: [],
channel_id: '974091097661923448',
author: {
username: 'misty.dev',
public_flags: 64,
id: '957347862314905610',
global_name: 'Misty',
discriminator: '0',
avatar_decoration: null,
avatar: 'b00572d12f19c17564a3f57c783a3e3a'
},
attachments: [],
guild_id: '957867801119449109'
}
}
Look at my totally complete message struct that I definitely wasn't too lazy to split into its own fields and not classify the data under a data prop
oh you solved it?
what'd you do
are you listening to messages
rn I am receiving messages yea
oh yeah then you need guild messages
I know
i thought you meant you were receiving messages as an empty string
π
nah
data: {
type: 0,
tts: false,
timestamp: '2023-08-15T02:53:35.098000+00:00',
referenced_message: null,
pinned: false,
nonce: '1140840675059695616',
mentions: [],
mention_roles: [],
mention_everyone: false,
member: {
roles: [],
premium_since: null,
pending: false,
nick: null,
mute: false,
joined_at: '2022-03-28T05:04:40.163000+00:00',
flags: 0,
deaf: false,
communication_disabled_until: null,
avatar: null
},
id: '1140840684996272178',
flags: 0,
embeds: [],
edited_timestamp: null,
content: 'asdasd',
components: [],
channel_id: '974091097661923448',
author: {
username: 'misty.dev',
public_flags: 64,
id: '957347862314905610',
global_name: 'Misty',
discriminator: '0',
avatar_decoration: null,
avatar: 'b00572d12f19c17564a3f57c783a3e3a'
},
attachments: [],
guild_id: '957867801119449109'
}
look at all this data I have to parse down
is that not just api raw data
yep
so what'd you have to parse lol
Im turning it into my own Message class that way I can better interact with the data
so like djs?
nope
djs has its own classes for every API datatype
yeah
misty is just using the raw data
It's fuckin raw
Im trying to make this as light weight as possible when it comes to this kind of stuff
have you heard of @discordjs/core
I could even build a framework into the lib itself or make a standalone framework that requires the lib idk yet
brody I haven't touched fucking discord.js in years
i do, i made a libless discord bot once that works with just raw api data
idk anything bout it
was really fun
it's fun
but not to the scale im trying to go
where you constantly need that data to be interactive with other parts of the app
it's better to have a class
discordjs/core is basically an api wrapper that returns raw data, but includes gateway + rest unlike discordjs/rest
makes sense
mind you discord.js devs despite their clusterfuck of managing the lib are like 100x smarter than I am so despite how messy their code looks it works
@sharp geyser just steal my old discord library code 
My code is the dumpster trash version of djs 
its absolutely barebones
Mine was barebones until I started adding client stuff and rest api onto it

not to mention volty helped me with the sharding part
:p
thank god he did cause that was going over my head
have you heard of tiny-discord tho
best library
tiny-discord is the most performant barebones lib i've seen ngl
i tried making a discord library in C once

I should make the support server for this lib that will never see anyone's code base one day
Sounds like it went well
keyword: tried
couldn't get OpenSSL's websockets to work

i was basically copying DPP's code lmao
Lmfao
Lmfao
How can I listen for log file and log the line that being added?
watchFile(__dirname + '/log.txt', async (curr, prev) => {
console.log(`the current mtime is: ${curr.mtime}`);
console.log(`the previous mtime was: ${prev.mtime}`);
const logFileContent = await readFileSync(__dirname + "/log.txt", { encoding: "utf8" });
console.log(logFileContent);
})
Tried something like this, but it will just log the whole file everytime
Split by \n and log the last entry
that will still load the whole file every time tho
I figured it out
by comparing the line
everytime there will be a new log line
so I will use console.log(newLog.slice(oldLogLines.length, newLogLines.length))
Order of imports in JavaScript depends on the module resolution you're using, if you're using CommonJS then the order always matters, if you're using ES Modules however, synchronous modules' order is guaranteed but if the module being imported is asynchronous then the order cannot be guaranteed so you'd have to be careful with that (though you rarely have to care about import order)
Note that an asynchronous module is an ES Module that uses features like TLA (Top-Level Await)

ur cool
And you're awesome, nully
has anyone here ever used terraform

love is not allowed in development

Grainger is not allowed in development
how can I make this work using only typescript types?
type Data = {
okay: {
mhhh: 12
ok: 'hi'
e: {
g: 1
}
}
}
type Keys = ???
// 'okay.mhhh' | 'okay.ok' | 'okay.e.g'
type KeyData<Key extends Keys> = ???
// KeyData<'okay.ok'> - 'hi'
I don't think that's possible using dot notation in a string
You can do Data[okay][ok] though
Actually it might be with newer typescript
I am confusion, largely cause im not fully awake yet
Does this work? https://stackoverflow.com/questions/47057649/typescript-string-dot-notation-of-nested-object
Seems you want to use something similar to dot-prop no?
yeee
https://npmjs.com/package/dot-prop might also be an option tho idk your use case here
They were asking for a typescript type
type safe translations
i wouldn't worry too much on it. let them do them
now the question is just how do I reverse it π€
Hello i have question with any npm package i can make vote reward command
Help access denied by cloudflare to discord
what status code do you get
actually lemme read thatthing 
you are being ratelimited
sending too many requsts
Yea but i tried after several hours and it still shows the same
Ok :/
PS C:\Users\darkxx\OneDrive\Darkxxweb\XYRIS BOT> node index.js
>>
C:\Users\darkxx\OneDrive\Darkxxweb\XYRIS BOT\index.js:7
Intents.FLAGS.GUILDS,
^
TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (C:\Users\darkxx\OneDrive\Darkxxweb\XYRIS BOT\index.js:7:13)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Node.js v18.17.1
PS C:\Users\darkxx\OneDrive\Darkxxweb\XYRIS BOT> ```
how am gonna fix this error?
I guess it's discord.js v14 right?
are you importing Intents
What is the difference between extends and implements when using classes. I sort of get that extends basically inherits all that the class is and implements doesn't necessarily do that rather it seems to only take on some stuff (idk)
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
yes
I blame Discord for poor ansi colour handling
bro got neo fetch on his discord bot π
"Dude, how much ram does your bot have?"
Any one here how kn how to convert image to text in python
Knowing python it probably has a built-in OCR package 
close, but no
Hi, do you have any VPS recommendations which has perfect internet speed but not expensive?
cheap ones will always have fair usage
and being limited a bunch
though you can try this out
and just compare the prices with eachother on higher networks etc
is hetzner good?
I'm using a dedicated server from hetzner right now, which costs around 34 Euros
so at least on their dedis they're good
alright ty!
No, this is something different
ah ok
if thats on a vps, then you're likely limited on traffic instead
or this is heavily limited on fair use
Yea, 1tb/month
Yeah
unlikely to reach that though
unless you provide content that might easily exceed that
hmm what is it?
Datalix offers a range of hosting solutions from shared hosting to dedicated servers.
this for example is how much I use on:
- docker containers running several discord bot
- several nginx-related elements
- a VPN running on my server that I have 2 laptops locally connected to
ty
tf happened aug 6 2023
I cant take a site with that name seriously lmao
"elon musk is the most intelligent person on earth" π€ π€ π€ π€ π€ π€ π€ π π π π π
Haha funny 24th letter go brr
One message removed from a suspended account.
what does that even mean
Do simple applications like password generator or the computer makes up a number and you need to guess it
print hello world
mmm I love the fact that I need like 1 gb of dependancies just to make d.js voice work
size on disk i mean not downloaded thank god for compression
I already know the answer, but I'm just triple checking @commands.is_owner is the bot owner, and not server owner, right?
depends on what u mean with "attempt to decrypt"
nah I got it
Encrypt with aes
Get the src string's hash
Attempt to decrypt the encrypted string
Check if its hash matches
where to download ram
can some one please tell me why installing node packages keeps un installing my allready installed ones?
Because they update on install
So if you do node install discord.js for example.. it replaces the old one
thats stupid
It shouldn't do that
all of these where isntalled minutes ago and the bot ran perfectly for once
and now its all fucked
again
Try downloading a previous package
I dont use that command so dont mind if it doesnt load
I did but that was broken from the newer version of node
You downloaded a package made for ts
and ur using js
Yea, that's an issue from canvas
yeah but anyway is there a setting to make node leave my already installed packages alone instead of deleting them?
npm i libsodium-wrappers was the last npm command I entered
did that cuz apparently its a dependancy for discord voice that doesn't install automatically
weird idk
whats the lowest audio quality d.js suports?
bot used to work at the default setting but now my internet seems to be worse
i set it to 32Kb atm and that kinda works but only if i mute myself
mmm I don't think anything is changing set it to 16Kb/s and its still struggling and I know my internet isnt that bad
thatr and it doesn't sound like 16Kb audio either
connection.subscribe(player, { bitrate: 16000 }); is this the correct method?
hmm the source is 16kb and the quality isnt too great
i set it to 8kb and its still droping packets
the hell is happening
is there a global bandwitch setting thats just set to always use a sertain amount of bandwidth?
cuz audio streams used to work fine even on my potato internet
any one have any ideas? I gotta sleep now so if you guys got anything please ping me and I'll get back to you, thanks.
if it's dropping packets, it's likely due to the bandwidth of the host

but why? at 8Kb/s that should work even on modem speeds
it used to work fine did they change the way they stream audio and it uses more data now or something or is this just another "just get better internet you idiot" moment
see my internet is usually half a Mb up so this is better than usual and way more than enough for an 8Kbps stream
I know this speed test is gonna make everyone here cringe lmao
Choose the ones that are the most performant
For example, instead of libsodium-wrappers, use sodium
It's much more performant and efficient
yeah i did the oposite cuz sodium just wouldnt install
How so?
spammed the cli with loads of errors from the install script not running right
I cant remember entirly
You most likely just don't have something installed that's required, try it again and tell us the errors
I will in a bit cant turn the server on right now as I have thing to do in a sec
Ill get back to you in a bit
in js, a forEach is non returnable right?
Like:
array = [1,2,3,4];
let k = array.forEach((el) => {
if(el === 1)
return "el_found"
})
console.log(k)``` -> undefined
oowh damn so that's why we have .find
if you don't need the element itself you can use some
good question regardless
probably not
If you want forEach() to return the value you should use .map()
map() is almost identical to forEach() except that it returns the value you returned in the function
in an array
not exactly
.map returns a new array with every single value replaced by the value returned for each index on each iteration
its like transforming an array into a different array
Yeah and a side effect of that is you get to iterate through the array
which is what forEach does
its not a side effect, its its purpose, its what it was made for
well yes

kurwa
all array methods iterate through the array lmao
if you want to use return at this point just use a classic for (value of array) {}
I dont think they want to return the entire function but rather they want the logic of .map()
or break, in this case
for >>> for of
farofa
de frango
what? the message following that meant that they were looking for something like .some() or .find()
you would rarely want to use a classic for loop unless you also need to access the index number
you would for performance sensitive scenarios
which is rare in js but it does exist
Isnβt for of faster though since it uses iterators?
Damn
me when "p" breaks
xD
at this point just use node-gyp if you want performance sensitive loops 
phone keyboard without autocorrect
js to cpp is very slow, only worth it if youre dealing with something very heavy
to be worth the overhead
i wouldnt really say that its very slow
from a legless rat to orange crab
wdym by just for
For let i guess
the only for loops i know of are for in and for of
for (let i = 0; i < smth; i++) {
...
}
ah
hard to think of any iterating loop that'd be faster
while would be faster, but u cant use it for accessing anything without an iterator
comparing between while and for is pointless
since their speed difference are merely just in microseconds
I thought that for loops internally got transformed into while loops anyways
they are
the difference is that for inherently gets an iterator, while while doesn't, so people might argue it's faster but also considerably less useful (alone) if ur iterating something
Ah, Tim is now a true catgirl then 
yes
now its your turn

for and while loops are not transformed from one to another, because they emit almost identical instructions with just one or two differing labels (but no actual instruction changes)
Ah
I thought most languages transformed for loops to while loops in the AST because itβs easier to just have one structure to represent both of them instead of having another unique statement variant
petition to add goto to javascript

not if i force you 
Btw if you're curious, you can look at these examples:
yeah they're the exact same output with different labels, neat
I'm gonna goto your core labels

Too bad that it's merely a distraction, I attached it somewhere interesting 
i wonder where 
is there something wrong with this ffmpeg command? im converting a 800mb webm to mp4 and its already taking over 15min
800mb is pretty big
One message removed from a suspended account.
One message removed from a suspended account.
I mean its at 20min now
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
also memory and disk
AMD Ryzen 9 5900X
One message removed from a suspended account.
how much memory?
One message removed from a suspended account.
32gb
One message removed from a suspended account.
and disk?
what do you want to know about disk
hdd or ssd, read/write speed
One message removed from a suspended account.
nvme ssd
One message removed from a suspended account.
the slowness come from reading -> decompressing -> decoding -> recoding -> compressing mostly
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
I think im just gonna throw out webm then
One message removed from a suspended account.
is any other format this slow too?
One message removed from a suspended account.
it's not the format, it's just that both sides are heavily compressed
hm
webm is great for web, so it has to be small and fast-loading
I guess ill just add a background job for this then
so the user doesnt have to wait like 30+min
well, you can assign more cores to ffmpeg no?
It almost has all already
u can also use fast mode, which will probably result in poor quality x compression ratio, but it'll be fast
this is the line of errors it spits out theres some more at the botom if this isnt conclusive
thats the other bit
I mean what would be the best for what im making? Its a invite only image / video uploader / sharer
apparently, it's not finding some directory
give the option to the uploader, or simply dont re-encode
I would asume it means this directory
I need to convert to mp4 so that it properly displays on all devices / embeds
make the service only accept mp4s
for a service you'll never have enough processing on a single machine
I mean I have multiple machines
ffmpeg has an option to spread the task over many machines
oh nvm, it depends on other softwares
This is the actual error:
npm ERR! make[1]: g++: No such file or directory
It means you don't have a C++ compiler installed, your system uses G++ as its default C++ compiler
how would I fix that?
Simply install g++: sudo apt install g++
I'd highly recommend installing build-essential, it'll install everything needed for proper compilation
G++ is a C++ compiler (part of the GCC compiler)
I did... well I installed 'development tools' cuz that is fedora and thats the equivilant
Well it seems like the "development tools" group on Fedora doesn't install GCC nor G++
how odd
it might install clang instead or something
Run sudo dnf install gcc gcc-c++
I think I manually installed G++ for something else if I remember correctly but I really don't know, this is a minimal install of fedora server
granted I would think npm would be smart enough to check for that installation
I don't know why the hell the Fedora repository maintainers named G++ as gcc-c++
No other Linux distribution does that
had the same exact thought π
Probably some stupid name conflict with internals or something lmao
"it worked if it ends with ok"
Fedora do be kinda funky sometimes
I used to use centOS but we all know where thats gone
tryed rocky but it didn't like my server
Why not use Ubuntu?
I did for a while but its, eh I dant really articulate it well but its does a bunch of stuff on its own and takes a bit to confugure the way I want
like auto updates where a pain cuz my internet is bad and it would randomply just use it all
I will probably just use debian next time as some of the packages I use are instanely outdated and dont work properly on rehl based systems
u can limit bandwidth on ubuntu
npm uses node-gyp to build/compile stuff, but it doesn't automatically check for all installed C/C++ compilers (most build tools don't either), they basically check for the system default but that can easily be changed using alternative links and symlinks, as well as environment variables that point at the compilers (like CC for the C compiler, and CXX for the C++ compiler)
true but that would be global and a pain in the ass when installing things cuz id have to remove the limit and put it back
I liked centOS cuz it just did what I wanted and just worked
There's no such thing as auto updates on Ubuntu
There are third-party tools that can auto update stuff for you but Ubuntu will never do that on its own
well it started using internet for no reason and I was not sshed into the machine and when i did there where system prosseses using bandwidth conected to ubuntu repositories
I never set it to do that and every time it did I just turned off the machine and turned it back on and it would fix it for a week or so
micht have been something I installed but never worked that one out
That's either your VPS provider doing some unusual stuff or you probably configured something incorrectly that checks in with the Ubuntu repositories for unknown reasons
What was your VPS provider that you tried Ubuntu on anyway?
suppose i make an embed ephemeral, and in click on its button, can i somehow still edit the message?
and what if the embed was already edited
like, interaction.message.editReply() upon buttonclick?
Yes you can edit ephemeral messages, doesn't matter if it was already edited
lol
lmao
Or more specifically 7 here
its not as bad as it looks its got a dual core athlon and 4gb of ram
ddr2 ram
but its good enough fro what i use it for
Holy shit it's the Ubisoft servers
shhhhh Don't tell then its the backup server they wont notice
Maybe will last as a backup server for a minute if we're being generous
I miss using that as my main server but even after powersaving optimisations it still would cost like Β£300 to run yearly
just to add on this, make sure u do it through the hook, not the message itself
How much power does that pc suck?
I dont have anything to mesure it but at idle a rough calculation based on psu inefficiency and components was something like ~50w
that was the "worst case senario" that i went off of
cuz it was closer to 40w
but I have an extra audio card and the psu is only 20 pin and I think predates the 80+ standards
but its made by FSP and its really heavy so its not gonna expload (I hope)
have a fire extinguisher nearby just in case 







