KevinWho
KevinWho
DIAdiscord.js - Imagine an app
Created by KevinWho on 8/18/2023 in #djs-questions
Trying to detect if a shard goes offline
I am trying to make it so on shardcreate it gets the client.ws.ping or client.ws.status. The issue is that when I disconnect my wifi it still returns 0 for the status (same as when its on and connected), and the ping remains frozen at the last value (Not switching to -1 like I would expect) Here Is the code(I am using express to send a thing based on if its running or not): Also again client.ws.status cant be compared to WebSocket.OPEN since its always 0
manager.on("shardCreate", (shard: Shard) => {
console.log(`Shard ${shard.id} launched`);

shard.once("ready", async () => {
app.get(`/ping${shard.id}`, async (req, res) => {
// if ((await shard.eval(`this.ws.status`)) == WebSocket.OPEN)
res.status(200).send(`Ok ${(await shard.eval(`this.ws.status`))}`).end();
});
});
});
manager.on("shardCreate", (shard: Shard) => {
console.log(`Shard ${shard.id} launched`);

shard.once("ready", async () => {
app.get(`/ping${shard.id}`, async (req, res) => {
// if ((await shard.eval(`this.ws.status`)) == WebSocket.OPEN)
res.status(200).send(`Ok ${(await shard.eval(`this.ws.status`))}`).end();
});
});
});
This whole setup is so that I can monitor the bot by pinging it eventually but I cant detect if its on like this, how would I do this?
2 replies
DIAdiscord.js - Imagine an app
Created by KevinWho on 6/30/2023 in #djs-questions
Bot cannot edit its own messages
With my bot I am trying to make it so that when you press a button it becomes disabled. This fails so I simplified it to just trying to edit it to some basic text to see if I somehow did something wrong but it also doesnt work. On button press I am getting interaction.message and then calling .edit on it, however that fails. Basically when pressing the button im trying to run
interaction.message.edit("test")
interaction.message.edit("test")
and it fails
Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
What am I doing wrong? Im doing this in a dm, but ive been able to edit messages in dms from the bot in the past. Any ideas?
15 replies
DIAdiscord.js - Imagine an app
Created by KevinWho on 6/28/2023 in #djs-questions
ShardingManager doesnt work with .ts files
I am trying to make a discord bot with typescript that uses shards, however the sharding manager crashes when I pass in a ts file like so:
const manager = new ShardingManager("./src/bot.ts", {
totalShards: "auto",
token,
});
const manager = new ShardingManager("./src/bot.ts", {
totalShards: "auto",
token,
});
here is my tsconfig:
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"importHelpers": true
},
"include": ["src", "environment.d.ts"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"outDir": "dist",
"sourceMap": false,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"importHelpers": true
},
"include": ["src", "environment.d.ts"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Is there any way to get this to work?
12 replies
DIAdiscord.js - Imagine an app
Created by KevinWho on 10/22/2022 in #djs-questions
How can I grab bot sent messages in a users dm with the bot if I dont have message intent?
I am making a bot that lets you communicate through it. 1 user can run a command and the other user will get the message in their dms. Same thing the other way around. I want to make it so messages can be reacted on, deleted, ect. For this I can store the message ID in a database and grab it. The issue is I dont know how. How do I grab a message from a users dm by id? The other option I have is to somehow store the raw message object in my database, the issue is I cant without serializing it or something. Every time I try to deserialize it the bot crashes. I have also tried to manually reconstruct it by passing in a json into a new Message(). I would like some help on solving this. I dont care what way gets it to work, im just trying to get it to work. If there is no way to do it then how would I do is assuming I did get message intent?
14 replies