Discord bot 在与 pm2 集群时响应多次 [英] Discord bot responds multiple times when clustered with pm2

查看:67
本文介绍了Discord bot 在与 pm2 集群时响应多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用 discord.js 制作了一个 discord 机器人.它使用 pm2 在我的树莓派上持续运行.最近,我从 pm2 的 fork 模式切换到利用所有内核的集群模式.但是,当我现在发送命令时,机器人回复了 4 次,我不知道如何让它像一个线程一样工作.有人知道如何设置它以便集群应用响应一次吗?

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?

推荐答案

使用 PM2 进行集群只能通过无状态应用程序完成.Discord 客户端代表一个连接到 Discord 服务器的有状态会话(这与 websocket 没有什么不同).不要使用集群模式.

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.

这篇关于Discord bot 在与 pm2 集群时响应多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆