0

When I running the Telegram bot, issues this error:

    TgCrypto is missing! Pyrogram will work the same, but at a much slower speed. More        info: https://docs.pyrogram.org/topics/speedups
    Traceback (most recent call last):
    File "C:\Users\Acer\Desktop\bott\bot test.py", line 52, in <module>
    startfunc()
    File "C:\Users\Acer\Desktop\bott\bot test.py", line 16, in startfunc
    st = random.random() + random.randint(2, 4)
         ^^^^^^^^^^^^^
    AttributeError: 'builtin_function_or_method' object has no attribute 'random'

    Process finished with exit code 1

The plan is to make a bot that, when launched, will automatically write to another Telegram bot on my behalf during the day. His messages will be sent regularly. All the code is made for the in-game item farm, but that's not important. The important thing is that no matter what I do, I always get a single error. So I can't even check if this code is logically correct. Please help me to fix this error

here is my code:

from random import random
from time import sleep
from pyrogram import Client, filters
    
api_id = 211623999
api_hash = '64df55d4b35v660cb64034ea5d79d559'
    
app = Client("tymofii", api_id, api_hash)
    
def startfunc():
    id = "@WorldDogs_bot"
    planesamount = 5
    i = 0
    
    while i < planesamount:
        st = random.random() + random.randint(2, 4)
        app.send_message(id, "/start")
        sleep(st)
        app.send_message(id, " Ферма")
    
        st = random.random() + random.randint(2, 4)
        if st < 2.8:
            st = 3.14
        sleep(st)
        m = app.iter_history("@WorldDogs_bot", 1)
        print("Чекаем грибъ")
        m[0].click(i)
    
        st = random.random() + random.randint(2, 4)
        if st < 2.8:
            st = 3.14
        sleep(st)
        m = app.iter_history("@WorldDogs_bot", 1)
    
        grno = " Смертоносный Мухомор \n\nПлохой уход за этим грибочком приведёт к быстрой смерти смельчака, попытавшегося съесть даже маленький кусочек.\n\n"
        grno += "⏳ Поливать каждые 30 мин\n Каждая стадия роста длится 36 мин\n    Умирает через 1 ч  в сухом состоянии"
    
        if (m[0] != grno):
            if len(m[0].text) > 110:
                m[0].click(1)
                st = random.random() + random.randint(2, 3)
                sleep(st)
                m = app.iter_history(id, 1)
                m[0].click(0)
    
        st = random.random() + random.randint(2, 4)
        if st < 2.8:
            st = 3.14
        sleep(st)
        i = i + 1
    
startfunc()
app.connect()
app.disconnect()
app.send_message("me", "userbot started!!")

1 Answers1

0

I don't know if the code works, but the import should be import random instead of from random import random, you also need to start the client before sending any message

import random
from time import sleep
from pyrogram import Client

api_id = 211623999
api_hash = '64df55d4b35v660cb64034ea5d79d559'

app = Client("user", api_id, api_hash)
app.start()

def startfunc():
    id = "@WorldDogs_bot"
    planesamount = 5
    i = 0

    while i < planesamount:
        st = random.random() + random.randint(2, 4)
        app.send_message(id, "/start")
        sleep(st)
        app.send_message(id, " Ферма")

        st = random.random() + random.randint(2, 4)
        if st < 2.8:
            st = 3.14
        sleep(st)
        m = app.iter_history("@WorldDogs_bot", 1)
        print("Чекаем грибъ")
        m[0].click(i)

        st = random.random() + random.randint(2, 4)
        if st < 2.8:
            st = 3.14
        sleep(st)
        m = app.iter_history("@WorldDogs_bot", 1)

        grno = " Смертоносный Мухомор \n\nПлохой уход за этим грибочком приведёт к быстрой смерти смельчака, попытавшегося съесть даже маленький кусочек.\n\n"
        grno += "⏳ Поливать каждые 30 мин\n Каждая стадия роста длится 36 мин\n    Умирает через 1 ч  в сухом состоянии"

        if (m[0] != grno):
            if len(m[0].text) > 110:
                m[0].click(1)
                st = random.random() + random.randint(2, 3)
                sleep(st)
                m = app.iter_history(id, 1)
                m[0].click(0)

        st = random.random() + random.randint(2, 4)
        if st < 2.8:
            st = 3.14
        sleep(st)
        i = i + 1


app.send_message("me", "userbot started!!")
startfunc()
GHOST
  • 159
  • 1
  • 9
  • Thanks for your help, `from random import random` it's really not correct. I looked into this problem in internet and found a solution!! The problem is that when incorrect codes are frequently launched, Telegram blocks my request. Therefore, to solve the problem, it was necessary to delete the code file and create a new, identical file. As for launching the client before sending the message, I'll fix that right away, thanks!! – Тимофій Таранович Jan 25 '23 at 14:21