@Nyxoy123

При попытке написать /start ошибка, в чем дело?

TELEBOT
PYTHON 3.8.0

import telebot
import config
import sounddevice as sd
from scipy.io.wavfile import write

bot = telebot.TeleBot(config.TOKEN)

fs = 44100  # Частота дискретизации
seconds = 15  # Продолжительность записи
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)

sd.wait()  # Дождитесь окончания записи
print("ОКОНЧЕННО")
write('minecraft.mp3', fs, myrecording)  # Сохранить как WAV файл

keyboard = telebot.types.ReplyKeyboardMarkup(True, False)
keyboard.row("ПОЛУЧИТЬ")


@bot.message_handler(commands=["start"])
def start_message(message):
    chatId = message.chat.chatId
    text = message.text.lower

    bot.send_message(chatId, "Hi", reply_markup=keyboard)

@bot.message_handler(content_types=["text"])
def send_nessage(message):
    chatId = message.chat.Id
    text.message.text.lower()
    print(text)
    if text == "ПОЛУЧИТЬ":
        bot.send_nessage(chatId, "FILE")
        bot.send_audio(chatId, open("minecraft.wav", "rb"))
    elif text == "пока":
        bot.send_message(chatId, "nokall O")

bot.polling()


pip install pyTelegramBotAPI делал, pip uninstall telebot


C:\Users\ilbaa\OneDrive\Рабочий стол\ПРОСЛУШКА>python main.py
ОКОНЧЕННО
Traceback (most recent call last):
  File "main.py", line 38, in <module>
    bot.polling()
  File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 1043, in polling
    self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
  File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 1118, in __threaded_polling
    raise e
  File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 1074, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 156, in raise_exceptions
    raise self.exception_info
  File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 100, in run
    task(*args, **kwargs)
  File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 6395, in _run_middlewares_and_handler
    result = handler['function'](message)
  File "main.py", line 22, in start_message
    chatId = message.chat.chatId
AttributeError: 'Chat' object has no attribute 'chatId'
  • Вопрос задан
  • 127 просмотров
Решения вопроса 2
@igor6130
Видать из-за этого
chatId = message.chat.Id
id в message должно быть с маленькой буквы.

А в самой функции start_message у вас должно быть
message.chat.id
вместо
message.chat.chatId

Использованы неверные атрибуты. Собственно, об этом и ошибка.
Ответ написан
@bituke
это переписанный код, но толку от того что ты сейчас его получил - ноль)
import telebot
import config
import sounddevice as sd
from scipy.io.wavfile import write

bot = telebot.TeleBot(config.TOKEN)

fs = 44100  # Sample rate
seconds = 15  # Recording duration
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)

sd.wait()  # Wait for recording to finish
print("Recording finished")
write('minecraft.wav', fs, myrecording)  # Save as WAV file

keyboard = telebot.types.ReplyKeyboardMarkup(True, False)
keyboard.row("GET")

@bot.message_handler(commands=["start"])
def start_message(message):
    chat_id = message.chat.id
    text = message.text.lower()

    bot.send_message(chat_id, "Hi", reply_markup=keyboard)

@bot.message_handler(content_types=["text"])
def send_message(message):
    chat_id = message.chat.id
    text = message.text.lower()
    print(text)
    if text == "get":
        bot.send_message(chat_id, "FILE")
        bot.send_audio(chat_id, open("minecraft.wav", "rb"))
    elif text == "bye":
        bot.send_message(chat_id, "Bye!")

bot.polling()
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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