fix: Closes #3011 guide fixes

This commit is contained in:
Skillz
2023-05-08 13:36:33 -05:00
parent 5edfbb7efb
commit a1b2b3fb2c
3 changed files with 6 additions and 5 deletions
+2 -2
View File
@@ -64,8 +64,8 @@ app.all('/*', async (req, res) => {
try {
const result = await REST.makeRequest(
req.method,
`${REST.baseUrl}${req.url}`,
req.body
req.url.substring(4),
{ body: req.method !== 'DELETE' && req.method !== 'GET' ? {} : req.body }
)
if (result) {
+3 -2
View File
@@ -58,7 +58,7 @@ export const GATEWAY = createGatewayManager({
connection: await REST.getSessionInfo(),
})
// More code to be added here but first you need to understand this part.
GATEWAY.spawnShards()
```
Now let's break it down.
@@ -149,6 +149,7 @@ GATEWAY.tellWorkerToIdentify = async function (workerId, shardId, bucketId) {
method: 'POST',
headers: {
authorization: process.env.AUTHORIZATION,
"Content-type": "application/json",
},
body: JSON.stringify({ type: 'IDENTIFY_SHARD', shardId }),
})
@@ -156,7 +157,7 @@ GATEWAY.tellWorkerToIdentify = async function (workerId, shardId, bucketId) {
.catch(logger.error)
}
// More code to be added here but first you need to understand this part.
GATEWAY.spawnShards()
```
Here, we are overriding the built in method on the gateway manager called `tellWorkerToIdentify`. Internally, this function just simply starts a new shard as by default the lib supports small bots. For our case, we are going to make it get the server url from a `.env` file
+1 -1
View File
@@ -114,7 +114,7 @@ try {
// OPTIONAL: Runs the raw event handler if you need it
bot.events.raw(bot, req.body.payload, req.body.shardId);
// Runs the event handler if available
if (message.t) bot.events.[snakeToCamelCase(message.t)]?.(req.body.payload, req.body.shardId);
if (message.t) bot.events.[snakeToCamelCase(message.t.toLowerCase())]?.(req.body.payload, req.body.shardId);
res.status(200).json({ success: true })
}