zzz
zzz
DIAdiscord.js - Imagine an app
Created by zzz on 8/23/2023 in #djs-questions
Duplicate messages in multiple shards
ws.on('message', async function incoming(data) {
const object = JSON.parse(data);

let channel = await client.channels.fetch(object.message.target.id);
if (channel) {
console.log('Discord socket message:', shardid)
await channel.send(object.message.text)
}
return;

});
ws.on('message', async function incoming(data) {
const object = JSON.parse(data);

let channel = await client.channels.fetch(object.message.target.id);
if (channel) {
console.log('Discord socket message:', shardid)
await channel.send(object.message.text)
}
return;

});
2023-08-23 16:31: Discord socket message: 4
2023-08-23 16:31: Discord socket message: 8
2023-08-23 16:31: Discord socket message: 4
2023-08-23 16:31: Discord socket message: 8
Hello, I have a bot with multiple shards. I attempted to send a Discord message when the bot receives a WebSocket message. However, I'm currently facing an issue. If I use the code mentioned above, sometimes multiple shards will send the same message simultaneously. For instance, shard 4 and shard 8 both have access to the channel, resulting in duplicate messages. Is this behavior normal? How can I ensure that only one shard sends the message?
2 replies