Virtus
Virtus
Explore posts from servers
PPrisma
Created by Virtus on 7/5/2024 in #help-and-questions
ID needed in delete()?
No description
4 replies
DIAdiscord.js - Imagine an app
Created by Virtus on 6/21/2023 in #djs-questions
How does RequestManager work?
I was looking at the source for @discordjs/rest to see if I should stop the sweepers (since I only use REST, trying to keep it stateless) when I noticed sweepers that look like they handle sweeping RequestManager. I was wondering why this was needed, and looked further and found handling related to bucketing for rate-limiting (I think). I was wondering if someone could either explain, correct me, or confirm my understanding of how this system works? First of all there's not one giant RequestManager that deal with all the requests, but rather smaller units? In order to deal with Discord having endpoints it considers being "different" and those having different rate limits and groupings (buckets), the Request manager will try to create some sort of hash from the input route. We use this hash to get a small request handler unit, and if not found, we create one and cache it. The request is then queued into this handler. Each smaller handler deals with one bucket, in order to keep tracking of rate limits easily manageable. After a certain interval, sweepers will go through the cache of these smaller handlers and remove any inactive ones, or ones that are too old?
5 replies
DIAdiscord.js - Imagine an app
Created by Virtus on 3/6/2023 in #djs-questions
No `Ready` event dispatached
I am using @discordjs/ws version 0.6.0, and @discord/rest version 1.5.0. It seems like I am not receiving the ready event. I do receive a bunch of GUILD_CREATE on startup, as well as other events, like messages, guild members, etc.. File: index.js
import {WebSocketManager} from "@discordjs/ws";
import {REST} from "@discordjs/rest";
import {botConfig,} from "#config";

const rest = new REST().setToken(botConfig.token);
const gateway = new WebSocketManager({
token: botConfig.token,
intents: botConfig.intents,
rest,
});
export default gateway;
import {WebSocketManager} from "@discordjs/ws";
import {REST} from "@discordjs/rest";
import {botConfig,} from "#config";

const rest = new REST().setToken(botConfig.token);
const gateway = new WebSocketManager({
token: botConfig.token,
intents: botConfig.intents,
rest,
});
export default gateway;
File: controller.js
import * as handlers from "./handlers.js";
import gateway from "./index.js";
import {GatewayDispatchEvents} from "discord-api-types/v10";

await gateway.connect();
gateway.on("dispatch", ({data}) => {
switch(data.t) {
case GatewayDispatchEvents.Ready:
return console.log(data.d);
}
});
import * as handlers from "./handlers.js";
import gateway from "./index.js";
import {GatewayDispatchEvents} from "discord-api-types/v10";

await gateway.connect();
gateway.on("dispatch", ({data}) => {
switch(data.t) {
case GatewayDispatchEvents.Ready:
return console.log(data.d);
}
});
3 replies