#I have 3 replicas that all respond to the same thing

1 messages · Page 1 of 1 (latest)

wise slate

Yo! I have a bot that sends a message when a thread is created, but Im running 3 replicas, so the problem is that they all send the messge at the same time. I tried to resolve this by just checking if the last message was by the bot, but since they all check at once its false for all of them, and all of them end up sending. Any idea how I can resolve this without creating a database / api or creating extra overhead beyond the function itself?

client.on(Events.ThreadCreate, async (thread: ThreadChannel) => {
    if (thread.parent?.name === 'whatever') {
        const lastMessage = (await thread.messages.fetch({ limit: 1 })).first();

        // Checks if the bot has already sent this message
        if (lastMessage && lastMessage?.author.id === thread.guild.members.me?.id) {
            return
        }

        return thread.send({
            content: "whatever"
        })
    }
})