TypeError argument of type 'Message' is not iterable telebot
import telebot
from telebot import types
token = "?%:?*:%(*"
bot=telebot.TeleBot(token)
@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("?Магазин гемов")
btn2 = types.KeyboardButton("?Открыть бесплатный ящик")
markup.add(btn1, btn2)
bot.send_message(message.chat.id, text="? Привет, это бот с продажей гемов для игры Brawl Stars.\nНо вы так же можете испытать удачу и открыть бесплатный ящик с гемами?".format(message.from_user), reply_markup=markup)
@bot.message_handler(content_types=['text'])
def func(message):
if(message.text == "?Открыть бесплатный ящик"):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
photo = open("C:/Users/miroa/Documents/rght/bot_leon/free_gems.jpg", "rb")
my = types.KeyboardButton("Забрать?")
markup.add(my)
bot.send_photo(message.chat.id, photo, caption='Поздравляем, вы выиграли 550 ?\nЖми кнопку «Забрать»', reply_markup=markup)
elif(message.text == "?Магазин гемов"):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
gem80 = types.KeyboardButton("80?-99₽")
gem170 = types.KeyboardButton("170?-199₽")
gem360 = types.KeyboardButton("360?-379₽")
gem530 = types.KeyboardButton("530?-529₽")
markup.add(gem80, gem170, gem360, gem530)
bot.send_message(message.chat.id, text="Ты попал в наш магазин, выбери товар который хочешь купить ?", reply_markup=markup)
elif(message.text == "Забрать?"):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
photo1 = open("C:/Users/miroa/Documents/rght/bot_leon/teg_bw.jpg", "rb")
global arr
arr=bot.send_photo(message.from_user.id, photo1, caption="Введите тэг своего аккаунта Brawl Stars\nПример: #VLLQ9GOR\nУзнать свой тэг вы можете в профиле игры, пример на фото:", reply_markup=markup)
bot.register_next_step_handler(arr, func1)
@bot.message_handler(content_types=['text'])
def func1(message):
if '#' in arr.text:
bot.send_message(message.chat.id, "Отлично, мы получили ваш тэг, проверьте его ещё раз и подтвердите правильность данных.")
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
true = types.KeyboardButton("✅Тэг правильный")
false = types.KeyboardButton("❌Я ошибся")
markup.add(true, false)
else:
pass
bot.polling(none_stop=True)
Возникло исключение:
TypeError
argument of type 'Message' is not iterable
File "C:\Users\miroa\Documents\rght\ds_bot_token\gem_bw.py", line 40, in func1
if arr != None and '#' in arr:
File "C:\Users\miroa\Documents\rght\ds_bot_token\gem_bw.py", line 49, in <module>
bot.polling(none_stop=True)
Ответы (2 шт):
Автор решения: Dmitry
→ Ссылка
Или уточнить тип данных
if isinstance(arr, str):
if '#' in arr:
# blablabla
Автор решения: oleksandrigo
→ Ссылка
UPD Пробуйте
from telebot import TeleBot, types
#import config
#bot = TeleBot(config.BOT_TOKEN)
token = "?%:?*:%(*"
bot = TeleBot(token)
@bot.message_handler(commands=['start'])
def start(message: types.Message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("?Магазин гемов")
btn2 = types.KeyboardButton("?Открыть бесплатный ящик")
markup.add(btn1, btn2)
bot.send_message(
message.chat.id,
text="? Привет, это бот с продажей гемов для игры Brawl Stars.\n"
"Но вы так же можете испытать удачу и открыть бесплатный ящик с гемами?".format(message.from_user),
reply_markup=markup)
@bot.message_handler(content_types=['text'])
def func(message: types.Message):
if message.text == "?Открыть бесплатный ящик":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
photo = open("C:/Users/miroa/Documents/rght/bot_leon/free_gems.jpg", "rb")
my = types.KeyboardButton("Забрать?")
markup.add(my)
bot.send_photo(message.chat.id, photo,
caption='Поздравляем, вы выиграли 550 ?\nЖми кнопку «Забрать»',
reply_markup=markup)
elif message.text == "?Магазин гемов":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
gem80 = types.KeyboardButton("80?-99₽")
gem170 = types.KeyboardButton("170?-199₽")
gem360 = types.KeyboardButton("360?-379₽")
gem530 = types.KeyboardButton("530?-529₽")
markup.add(gem80, gem170, gem360, gem530)
bot.send_message(message.chat.id,
text="Ты попал в наш магазин, выбери товар который хочешь купить ?",
reply_markup=markup)
elif message.text == "Забрать?":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
photo1 = open("C:/Users/miroa/Documents/rght/bot_leon/teg_bw.jpg", "rb")
bot.send_photo(message.from_user.id, photo1,
caption="Введите тэг своего аккаунта Brawl Stars\n"
"Пример: #VLLQ9GOR\n"
"Узнать свой тэг вы можете в профиле игры, пример на фото:",
reply_markup=markup)
bot.register_next_step_handler(message, func1)
@bot.message_handler(content_types=['text'])
def func1(message: types.Message):
if '#' in message.text:
bot.send_message(message.chat.id,
"Отлично, мы получили ваш тэг, проверьте его ещё раз и подтвердите правильность данных.")
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
true = types.KeyboardButton("✅Тэг правильный")
false = types.KeyboardButton("❌Я ошибся")
markup.add(true, false)
bot.infinity_polling(skip_pending=True)
Замените последнюю функцию
def func1(message: types.Message):
if '#' in message.text:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
true = types.KeyboardButton("✅Тэг правильный")
false = types.KeyboardButton("❌Я ошибся")
markup.add(true, false)
bot.send_message(message.chat.id,
"Отлично, мы получили ваш тэг, проверьте его ещё раз и подтвердите правильность данных.",
reply_markup=markup)