problema bot di telegram che parte solo su un dispositivo

andreap90

Nuovo Utente
2
0
salve, come si può intuire dal titolo del posto, ho un problema con un bot, questo funziona solo sul telefono che lo avvia per primo, gli altri non ricevono nulla, allego il codice per contestualizzare, in poche parole il bot segna un allarme quando sul database legge un valore più alto della soglia, funziona bene unico problema una volta chiamato con /start dal primo dispositivo, sugli altri non va.

#!/usr/bin/env python

import pymysql
import telepot
import time

#TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'

#bot = telepot.Bot(TOKEN)



def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
while True:
db = pymysql.connect("localhost","root","root","pippo")
cursor = db.cursor()
cursor.execute("select count(*) from prova where eta > 18")
((data,),) = cursor.fetchall()
if data > 0:
print("allarme ci sono {} maggiorenni".format(data))
bot.sendMessage(chat_id, 'allarme')
time.sleep(5)


db.close()

TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'

bot = telepot.Bot(TOKEN)
bot.message_loop(on_chat_message)

print ('Listening ...')

import time
while 1:
time.sleep(10)
 

Giacomo Furlan

Utente Attivo
351
87
CPU
AMD Ryzen 5900x
Dissipatore
BeQuiet! SilentLoop 2 360mm
Scheda Madre
Gigabyte X470 AORUS Gaming 7 WIFI AMD X470
HDD
Crucial P5 Plus 2 TB PCIe M.2 2280SS
RAM
Patriot Viper Steel RAM DDR4 3600 Mhz 64GB (2x32GB) C18
GPU
MSI GeForce RTX 2080 Gaming X Trio
Audio
SteelSeries Arctis 9
Monitor
Alienware AW3423DWF
PSU
EVGA SuperNOVA 650 G3, 80 Plus GOLD 650W
Case
Sharkoon TG5
OS
Windows 11, Fedora 36
Ti conviene rimuovere il token asap...
 

andreap90

Nuovo Utente
2
0
si si il token è vecchio.
Post unito automaticamente:

certo quel codice scritto in quel modo non penso che sia molto leggibile, ma non so come allegarlo in modo migliore
Post unito automaticamente:

forse così è meglio

Codice:
#!/usr/bin/env python

import pymysql
import telepot
import time

#TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'

#bot = telepot.Bot(TOKEN)



def on_chat_message(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    while True:
        db = pymysql.connect("localhost","root","root","pippo")
        cursor = db.cursor()
        cursor.execute("select count(*) from prova where eta > 18")
        ((data,),) = cursor.fetchall()
        if data > 0:
            print("allarme ci sono {} maggiorenni".format(data))
            bot.sendMessage(chat_id, 'allarme')
            time.sleep(5)
        
            
    db.close()

TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'

bot = telepot.Bot(TOKEN)
bot.message_loop(on_chat_message)

print ('Listening ...')

import time
while 1:
    time.sleep(10)
 
Ultima modifica:

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!