If you open telegram bot FAQ you can see 1 message per second inside particular chat, 30 messages per second inside group chat and less than 20 messages per minute inside group chat.
I have simple telegram bot with simple rate limiter:
it doesn't use group chats;
it sends only 1 message per second inside particular chat;
it sends less than 20 messages per minute inside particular chat;
But i always receive 429 error:
"error_code":429,"description":"Too Many Requests: retry after 236"
I confused since i don't violate telegram limitations. Please, help me to find problem.
Source code here, bot uses this library for interaction with telegram in poll mode. Steps to reproduce:
1) python3 bot.py;
2) /start in bot;
3) click "Спектакли";
4) click very fast on "Трагикомедии" or "Драма";
Your msg_count seems is tracking sended messages for each private chat. But it should be global, beacuse its seems that your current code allows your bot to send a few messages per second to unlimited users. So it would probably exceed the limit.
If you're sending bulk notifications to multiple users, the API will
not allow more than 30 messages per second or so. Consider spreading
out notifications over large intervals of 8—12 hours for best results.
Telegram Bots FAQ
Related
What I'm trying to understand is how Discord.py creates and sends responses from their on_message function.
Take this as an example:
#client.event()
async def on_message(message):
print(message.content)
I'm trying to understand how Discord.py retrieves new messages from Discord without refreshing the channel histories for every single channel in every single server to scan for new messages which would surely hit Discord's rate limit.
Is there a way to scan for new messages with Discord's API using fetch or post requests? I am not trying get a solution on how to scan new messages using an already made library. I want to achieve this using only the requests module in python.
I'm trying to understand how Discord.py retrieves new messages from Discord without refreshing the channel histories for every single channel in every single server to scan for new messages which would surely hit Discord's rate limit.
Discord bots establish a websocket connection with Discord's servers, which is essentially a (secure) two-way tunnel. This means that once the connection is up, Discord can send events to you. Instead of you having to manually fetch every single channel, Discord tells you "Hey, a message was created", and the payload attached will give all the additional info about it.
The Discord (not discord.py) docs have detailed info about how everything works behind the scenes, to help the people creating the Bot libraries for you. For example, this section details which types of events Discord can send to you. To see how something is constructed, click on one of the event types and read up on the data that Discord provides.
Is there a way to scan for new messages with Discord's API using fetch or post requests? I am not trying get a solution on how to scan new messages using an already made library. I want to achieve this using only the requests module in python.
Not really, unless you do in fact send a GET for every single channel, which will get you ratelimited. There's really no reason to ever use only GET/POST requests (other than Webhooks, where you just send a POST with your info to send a message to a channel without a bot).
If you'd like to read up on Discord's API, the docs I linked contain a full spec of everything, so you could try to do whatever your heart desires (... and the API supports).
this Platform is really really helpful. My issue is that is it possible to send 500k promotional messages per day? I have the script ready using the API # and API ID using Telethon. But anytime i try to send Messages, the accounts get banned. Maybe it got banned because i was on the same IP Address while scraping the users and sending messages. But what I really need to know is that is it even Possible to send 500k messages in day, if yes:
How many Accounts are needed(where can I get these number of
accounts from)?
Do I have to manually create accounts and receive
OTP's for each or is there a script ready for that as well that I
can implement?
What should be the duration between each messages and
how many messages from one single account.
How to shuffle between accounts while send messages? Manually or is there again a script
ready for it?
Please guys I really really need help. If not 500k how many can i send per day maximum.
You can send up to 20 messages per second in the same chat on Telegram.
For one of my projects, I need to fetch in real-time the total unread count of telegram messages
As shown under, it's possible to do it in Telegram Desktop client :
https://telegra.ph/file/d58a4c36084d79781f89c.png
it's also possible to show it on other clients
so, I wonder how I can simply do it
maybe through the Telegram API, however I didn't find anything related to this
(we can get unread mentions and unread reactions, but only for a specific chat)
An integration in python would be the best for me, as I don't really master other languages yet
NB : "fetch in real-time", not needed to have it every millisecond, but maybe each 2-3 seconds
I made a telethon program that parses messages from the list of channels into telegram, but the problem is that the parser reacts to the post only when it comes to the account with which I originally logged in. Sometimes posts come with a delay due to the fact that I'm not sitting in the telegram, but you need to make sure that you respond to messages as quickly as possible. How can this be done?
I am making a discord bot and I want to know how I can add a basic implementation of seeing which users are active daily on the server and how long they're active. The definition of active is not accurate but it could be if they sent a message in the group throughout the day. What would be the code to implement something like this in my discord bot? Thanks a lot!
Checking to see who has sent a message is simple enough to do,
You could use the on_message function to see who has sent a message in your server, using this method you could get the user and append them to a list and then delete the list every so often (eg. daily, or you could wait for an admin to call a command within the server).
The positive side of this method is that you can control what counts as active, for example you could also use on_reaction_add and its opposite.
This is a simple example of a bot that checks the users that have sent messages in the server and adds them to a list. Note: This script doesn't delete the list, meaning that members will be permanently in the active list, you should be able to implement this in your code fairly easily.
import discord
client = discord.Client()
activeMembers = [] #We create an empty list to hold the users that have been active
#client.event
async def on_message(message):
if message.author not in activeMembers:
activeMembers.append(message.author)
client.run("YOUR TOKEN HERE")
I've missed out some things that you probably have if you've started your bot already. If you haven't, fear not as there are multiple articles and tutorials on creating a bot.
The problem is that you want to see how long a member is active on your server, so what you could do is log the times they have sent messages, and then calculate the time they've been active on the server by deducting one value for another. This isn't accurate as you've stated, but is the best solution in my mind. The biggest problem here is that someone could send a message early in the morning and then go off about their day and then send a message at night, this would mean that the bot would think they are active for many hours (seeing as their first message was sent much much earlier) when in fact they are not. A simple workaround is to check every users last message time, and use a threshold time (if you will) to see who is no longer active.
For example, if someone sent their last message half an hour ago, they would no longer be seen as active and their total time would be calculated based on their first message and their last message. Their data would then be purged, so that if they send a message much later on, the bot doesn't use their first message of the day to calculate how long they've been on for.
Looking back on this this explanation is a bit shoddy, so Ill try quickly summarise it in a timeline sort of fashion.
A user sends a message in a channel and the bot records their id and the time they sent it -> They send another message five minutes later, the bot records the same data -> The user hasn't sent a message in half an hour (example of a threshold time, you could make yours shorter or longer) and the bot calculates their time and removes their message times. This time is then added to their total time.
This can be done using .create_task() where you pass in a function to run in the background. The function you would pass would regularly check when users sent their last message.
Should you want to define active as things other than reactions or sending messages, visit discord.py to find out the different things you can do.
Best of luck,
Ben