D
D
DTPlayer2020-06-03 15:28:33
Python
DTPlayer, 2020-06-03 15:28:33

'function' object is not iterable, how to solve?

# -*- 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
How to solve?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-06-03
@galaxy

newuser = set ()
...
def newuser(message):

Doesn't he talk about anything?
len(file)- so the file size is not received (and you, apparently, do not need the file size, probably len(file.readlines()))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question