Search code examples
javascriptdiscord.jspm2

Discord bot responds multiple times when clustered with pm2


I recently made a discord bot using discord.js. It has been running continuously on my raspberry pi using pm2. Recently, I switched from pm2's fork mode into cluster mode which utilises all cores. However, when I now send a command, the bot replies 4 times and I don't know how to make it act like one thread. Does someone know how to set it up so clustered apps respond once?


Solution

  • Clustering with PM2 can only be done with stateless applications. The Discord client represents a statefull session connected to the discord servers (this is not dissimilar to a websocket). Don't use cluster mode.