how to speed up receiving posts from telegram channels - python

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?

Related

Using Discord's API to Register New Messages

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).

Is it possible to use aiogram to send messages without handlers?

Recently I've been writing bot which parses site and sends message to users, whenever new information appears. Is it possible to make it on aiogram? Thank you for your answer in advance
Yes. it is.
But you have to store user_id of your users, then when "information appears" you take from your storage user_ids and send message to each user. Also it is unreal to send message for all users in one time due to telegram limits (see here).

How to use a user account to fetch/get messages (discord.py)

I have 2 discord client instances a bot and a user account. I have already figured out how to copy messages from one channel to another channel, basically a on_message event. However, I want to know if there is a way I can use the user account to fetch the messages, I've tried fetching messages in different guilds but they didn't work because the bot was not in the server and the bot is fetching messages. I've tried using the user account instance to do it but it didn't really work.
The comments were there as a guide for myself because I'm not that familiar with Python it's fairly new to me. If anyone knows how I can use the user account to get or fetch the messages I'd appreciate the help...
PS: I know that some of the code isn't needed, I haven't removed anything that isn't needed. I wanted to actually finish the project before inspecting it.
I just wanted to know that I have tried this myself and it is not possible. Because from discord.py's Docs. Which you can find down below, does not allow users (user account) to transfer data to a bot since you would need to request from discord API which leads to user getting banned (Very quickly) theere are some work arrounds but I would suggest not doing so since self botting is against the TOS of discord
https://discordpy.readthedocs.io/en/stable/
EDIT: Another thing is that discord API blocks users from fetching or getting anything using a user account with discord.py

Set slowmode delay to a DM of a bot

I'm having a bot that accepts DM from users (There should be at least one mutual server).
Now is it possible for the users to perform a DDOS or any similar type of attack. Or simply can they spam the bot and make it unavailable for normal users?
How can I tackle this as I couldn't find any slow-mode delay for a dm_channel and is only available for text channels. I have used discord.py.
Is there a way to make something similar to slow mode delay in a DM? I mean users shouldn't be able to send multiple messages at once to the bot as DM, and should wait for the specified amount of time (or any decent amount of time).
DDOS can happen anywhere, but it will happen to discord first before the bots can "chat-command-spam" your bot. Which you don't really have to worry about getting DDOS'ed by a few spammers (even with a few gaming computers, spamming your bot commands in discord dm at the same time without getting noticed by discord, it won't affect your bot that much). There are cases like if you have a really expensive command in your bot, and people are frequently calling the command, then you can put a cooldown in your code for the expensive command.

Fetch all the messages sent by the bot

I want to fetch all the messages sent by my bot in Discord.py .. I've tried a lot but I only found ways to do that for the last message.
Is it a function available in Discord.py?
There is no internally-kept list with information about the messages sent by your bot -- as such, you have two methods to find all the messages sent by it:
Create your own system to track and save messages or message IDs that are sent out, or
Iterate through the history of the guilds' channels that your bot posts in. Note that if any of these channels have a long history, iterating through all of it could be extraordinarily slow, especially if you have a public bot in multiple servers. If you choose to do this way, you can use the TextChannel.history method.

Categories