@DTPlayer

'function' object is not iterable, как решить?

# -*- coding: utf-8 -*-
import sett
import telebot
from telebot import types
import time

bot = telebot.TeleBot(sett.token)

file = open('C:/users.txt', 'r')
newuser = set ()
for line in file:
    newuser.add(line.strip())
file.close()

@bot.message_handler(commands=['start'])
def newuser(message):
    try:
        if not str(message.chat.id) in newuser:
            file = open('C:/users.txt', 'a')
            file.write(str(message.chat.id) + '\n')
    except Exception as e:
        print(e)
        bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')

@bot.message_handler(commands=['spam'])
def spam(message):
    try:
        if message.chat.id == sett.admin_id:
            for user in newuser:
                bot.send_message(user, message.text[message.text.find(' '):])
    except Exception as e:
        print(e)
        bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')

@bot.message_handler(commands=['stats'])
def stats(message):
    try:
        if message.chat.id == sett.admin_id:
            file = open('C:/users.txt', 'r')
            bot.send_message(sett.admin_id, 'Пользователей: '+len(file)+'\nАдмин: '+str(sett.admin)+'\nQIWI кошелек: '+str(sett.qiwi)+'\nBTC кошелек: '+str(sett.btc)+'\nОписание\n/начало описания/\n'+str(sett.info)+'/конец описания/')
            file.close
    except Exception as e:
        print(e)
        bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')




while True:
    try:
        bot.polling(none_stop=True)

    except Exception as e:
            print(e)
            time.sleep(50)


'function' object is not iterable - /start
'function' object is not iterable - /spam
object of type '_io.TextIOWrapper' has no len() - /stats
Как решить?
  • Вопрос задан
  • 668 просмотров
Пригласить эксперта
Ответы на вопрос 1
@galaxy
newuser = set ()
...
def newuser(message):

Ни о чем не говорит?

len(file) - так размер файла не получают (да и вам, судя по всему, не размер файла нужен, наверно len(file.readlines()))
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы