ANTICHAT

ANTICHAT (https://forum.antichat.xyz/index.php)
-   Общие вопросы программирования (https://forum.antichat.xyz/forumdisplay.php?f=206)
-   -   Ошибка в коде (https://forum.antichat.xyz/showthread.php?t=1427356)

fukuzaca 29.03.2022 14:55

Я недавно начал пробывать себя в сфере ботов телеге.

При запуске выдает ошибку и говорит что эта фигня виновата (ниже)

bot = telebot.TeleBot("**********************")

код ошибки:





Код:

Traceback (most recent call last):
  File "D:\Python\bot.py", line 2, in
    from telebot import types
  File "C:\Users\Gavrik\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\types.py", line 12, in
    from telebot import util
  File "C:\Users\Gavrik\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 322, in
    def user_link(user: types.User, include_id: bool=False) -> str:
AttributeError: partially initialized module 'telebot.types' has no attribute 'User' (most likely due to a circular import)



Цитата:


сам код:





Код:

import telebot
from telebot import types

bot = telebot.TeleBot("******************)", parse_mode=None)

@bot.message_handler(commands=["start"])
def start (message):
    channel_link = "https://t.me/aogirilifestyle"
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    keyboard = types.KeyboardButton(text="Confirm")
    markup.add(keyboard)
    chat_id = message.chat.id
    user = message.chat.first_name
    bot.send_message(chat_id, f"Hi {user} if u want to use bot you must subscribe to the channel/n"
        f"{channel_link}", reply_markup=markup)

@bot.message_handler(content_types=["text"])
def text(message):
    user = message.chat.first_name
    if message.chat.type == 'private':
        if message.text == 'Confirm':
            status = ['creator', 'administrator', 'member']
            for stat in status:
                if stat == bot.get_chat_member(char_id="@aogirilifestyle", user_id=message.from_user.id).status:
                    bot.send_message(message.chat.id, f"Open {user}")
                    break

                else:
                    bot.send_message(message.chat.id, "Sub to the channel!")

    bot.polling(none_stop=True)



https://forum.antichat.xyz/attachmen...37d7572ef8.png

Что делать? :((((

Ошибку сверху исправил

появилась новая

https://forum.antichat.xyz/attachmen...082b4fe8d8.png

Stewie2IQ 31.03.2022 09:17

Полагаю, установлен сам TeleBot...

Удаляем его:

pip3 uninstall telebot

И ставим на его место:

pip3 install pytelegrambotapi -U

laiser 01.04.2022 01:14

Попробуй aiogram, а не telebot

munnniisss 01.04.2022 16:02

тебе дело говорит человек выше, приучайся сразу к хорошему, рассматривай aiogram


Время: 14:25