我如何计算我的电报机器人单击 /启动的用户?

发布于 2025-02-06 20:37:30 字数 72 浏览 0 评论 0原文

我需要一个Python代码来检查电报机器人的单击 /启动多少用户。我该如何使机器人回复? 用户:23 我需要知道单击 /开始的人数

I need a Python code to check how many users clicked /start on my telegram bot. How can I make the bot reply like this?
users: 23
I need to know the number of people that have clicked /start

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这是一种非常基本的方法:

#1

  1. 如果尚未将机器人连接到数据库。
  2. 制作一个整数值(最初设置为0),例如“ usercount”。
  3. 转到编写对/start命令的响应的代码部分。
  4. 添加代码以通过1中的数据库中的值增加值。 (代码可能取决于不同的数据库类型)

#2

此值代表NO。时间/start命令已执行。但是,单个用户可以无限期地执行/start命令。

因此,为了使其特定于用户并防止单个用户被算作多个用户,您可以扩展代码功能。一种方法是:

  • 在数据库中创建另一个值。 (一个可以存储多个值的值,例如数组)
  • 获取聊天ID,如果该数组中尚未存在,请将其存储在数组中,并增量USERCOUNT by 1代码>
  • 如果已经存在,请忽略增量部分,然后仅继续使用该系统的其余部分,

现在

您已经设置了系统,最后一步是为了告诉您有多少用户已执行> /start命令。

  1. 制作一个新的命令
  2. 添加代码以获取USERCOUNT
  3. 输出值

注意,这只是一种基本方法,可能存在漏洞,并且可能有更好的方法。

Here is a very basic approach:

#1

  1. Connect your bot to a database if you haven't already.
  2. Make an integer value (initially set to 0), say "usercount".
  3. Go to the section of your code where you have written the response to the /start command.
  4. Add code to increment the value in the database by 1. (Code may vary depending on different database types)

#2

This value would represent the no. of times the /start command has been executed. However, a single user may simply execute /start command indefinitely.

So, to make it user-specific and prevent a single user from being counted as multiple users, you can extend the code functionality. One way to do that is:

  • Create another value in your database. (One that can store multiple values, like an array)
  • Get the chat ID, if that isn't already present in the array, store it in the array and increment usercount by 1
  • If it is already present, ignore the increment part and simply continue with rest of your code

#3

Now that you have set up the system, the last step is making a new command for telling you how many users have executed /start command.

  1. Make a new command
  2. Add code to fetch usercount
  3. Output the value

Note that this is only a basic approach, there might be loopholes, and there might be better ones out there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文