• XSS.stack #1 – первый литературный журнал от юзеров форума

Discord bot and telegram bot

Пожалуйста, обратите внимание, что пользователь заблокирован
Here is an example of a bot that sending messages to users in a telegram with phyton


Python:
import telegram

bot = telegram.Bot(token='YOUR_TOKEN')
user_ids = ['123456', '7891011', '12131415']

for user_id in user_ids:
    try:
        bot.send_message(chat_id=user_id, text="Hello, I'm your bot!")
        print(f"Message sent to user {user_id}")
    except Exception as e:
        print(f"Error sending message to user {user_id}: {e}")
 
As another solution you can use something like TDLib to make a robotic client.
I prefer Kotlin, so made a small example with this lib https://github.com/KurenaiRyu/tdlight-sdk (This is just for example of using similar clients, not my recommendation)


Код:
import io.github.kurenairyu.tdlight.Client
import io.github.kurenairyu.tdlight.exception.ClientException
import io.github.kurenairyu.tdlight.handler.UpdateHandler
import io.github.kurenairyu.tdlight.util.ResultHandler
import io.github.kurenairyu.tdlight.util.TelegramObject
import io.github.kurenairyu.tdlight.util.TdApi
 
class Bot(token: String = "YOUR_TOKEN") {
 
    private val client = Client.create(token)
 
    fun init() {
        client.start()
    }
 
    fun sendDirectMessagesToFriends(message: String) {
        client.send(TdApi.GetContacts(), object : ResultHandler {
            override fun onResult(obj: TelegramObject) {
                if (obj is TdApi.Users) {
                    obj.users.filterIsInstance<TdApi.User>().forEach { user ->
                            if (user.type.constructor == TdApi.UserTypeBot.CONSTRUCTOR) {
                                //Ignore bots
                                return@forEach
                            }
                            client.send(TdApi.SendMessage(user.id, 0, false, false, null, TdApi.InputMessageText(TdApi.FormattedText(message, null), false, true)))
                    }
                }
            }
        })
    }
}
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх