 |

21.04.2024, 14:10
|
|
Участник форума
Регистрация: 09.01.2022
Сообщений: 105
С нами:
2286618
Репутация:
23
|
|
помогите по братски, vsc выдает ошибку "message не определено"
Python:
Код:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)
|
|
|

21.04.2024, 14:15
|
|
Познающий
Регистрация: 03.03.2024
Сообщений: 61
С нами:
1158033
Репутация:
18
|
|
Сообщение от лимаров
помогите по братски, vsc выдает ошибку "message не определено"
Python:
Код:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)
значит объект месседж не передал в функцию
|
|
|

21.04.2024, 14:15
|
|
Участник форума
Регистрация: 09.01.2022
Сообщений: 105
С нами:
2286618
Репутация:
23
|
|
123:
Код:
import
telebot
import
webbrowser
import
types
bot
=
telebot
.
TeleBot
(
'6874714175:AAFQKXXXXXXXXXXXXUelTp_bZcGgpyHUPUl0'
)
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
btn2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
btn1
,
btn2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)
@bot.message_handler
(
content_types
=
[
'text'
]
)
def
func
(
message
)
:
if
(
message
.
text
==
"👋 Поздороваться"
)
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привеет.. Спасибо что читаешь статью!)"
)
elif
(
message
.
text
==
"❓ Задать вопрос"
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"Как меня зовут?"
)
btn2
=
types
.
KeyboardButton
(
"Что я могу?"
)
back
=
types
.
KeyboardButton
(
"Вернуться в главное меню"
)
markup
.
add
(
btn1
,
btn2
,
back
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Задай мне вопрос"
,
reply_markup
=
markup
)
elif
(
message
.
text
==
"Как меня зовут?"
)
:
bot
.
send_message
(
message
.
chat
.
id
,
"У меня нет имени.."
)
elif
message
.
text
==
"Что я могу?"
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Поздороваться с читателями"
)
elif
(
message
.
text
==
"Вернуться в главное меню"
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
button1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
button2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
button1
,
button2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Вы вернулись в главное меню"
,
reply_markup
=
markup
)
else
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"На такую комманду я не запрограммировал.."
)
bot
.
polling
(
none_stop
=
True
)
|
|
|

21.04.2024, 14:17
|
|
Познающий
Регистрация: 03.03.2024
Сообщений: 61
С нами:
1158033
Репутация:
18
|
|
Сообщение от лимаров
123:
Код:
import
telebot
import
webbrowser
import
types
bot
=
telebot
.
TeleBot
(
'6874714175:AAFQKXXXXXXXXXXXXUelTp_bZcGgpyHUPUl0'
)
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
btn2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
btn1
,
btn2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)
@bot.message_handler
(
content_types
=
[
'text'
]
)
def
func
(
message
)
:
if
(
message
.
text
==
"👋 Поздороваться"
)
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привеет.. Спасибо что читаешь статью!)"
)
elif
(
message
.
text
==
"❓ Задать вопрос"
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"Как меня зовут?"
)
btn2
=
types
.
KeyboardButton
(
"Что я могу?"
)
back
=
types
.
KeyboardButton
(
"Вернуться в главное меню"
)
markup
.
add
(
btn1
,
btn2
,
back
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Задай мне вопрос"
,
reply_markup
=
markup
)
elif
(
message
.
text
==
"Как меня зовут?"
)
:
bot
.
send_message
(
message
.
chat
.
id
,
"У меня нет имени.."
)
elif
message
.
text
==
"Что я могу?"
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Поздороваться с читателями"
)
elif
(
message
.
text
==
"Вернуться в главное меню"
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
button1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
button2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
button1
,
button2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Вы вернулись в главное меню"
,
reply_markup
=
markup
)
else
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"На такую комманду я не запрограммировал.."
)
bot
.
polling
(
none_stop
=
True
)
11 строка ты вызываешь метод сенд месседж класса бот и передаешь в него объект месседж. при этом не получил его.
|
|
|

21.04.2024, 14:20
|
|
Постоянный
Регистрация: 30.04.2021
Сообщений: 422
С нами:
2652924
Репутация:
33
|
|
Сообщение от лимаров
123:
Код:
import
telebot
import
webbrowser
import
types
bot
=
telebot
.
TeleBot
(
'6874714175:AAFQKXXXXXXXXXXXXUelTp_bZcGgpyHUPUl0'
)
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
btn2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
btn1
,
btn2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)
@bot.message_handler
(
content_types
=
[
'text'
]
)
def
func
(
message
)
:
if
(
message
.
text
==
"👋 Поздороваться"
)
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привеет.. Спасибо что читаешь статью!)"
)
elif
(
message
.
text
==
"❓ Задать вопрос"
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"Как меня зовут?"
)
btn2
=
types
.
KeyboardButton
(
"Что я могу?"
)
back
=
types
.
KeyboardButton
(
"Вернуться в главное меню"
)
markup
.
add
(
btn1
,
btn2
,
back
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Задай мне вопрос"
,
reply_markup
=
markup
)
elif
(
message
.
text
==
"Как меня зовут?"
)
:
bot
.
send_message
(
message
.
chat
.
id
,
"У меня нет имени.."
)
elif
message
.
text
==
"Что я могу?"
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Поздороваться с читателями"
)
elif
(
message
.
text
==
"Вернуться в главное меню"
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
button1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
button2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
button1
,
button2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Вы вернулись в главное меню"
,
reply_markup
=
markup
)
else
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"На такую комманду я не запрограммировал.."
)
bot
.
polling
(
none_stop
=
True
)
Python:
Код:
import
telebot
import
webbrowser
import
types
bot
=
telebot
.
TeleBot
(
'6874714175:AAFQKXXXXXXXXXXXXUelTp_bZcGgpyHUPUl0'
)
@bot.message_handler
(
content_types
=
[
'text'
]
)
def
func
(
message
)
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
btn2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
btn1
,
btn2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)
if
message
.
text
==
"👋 Поздороваться"
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет.. Спасибо что читаешь статью!)"
)
elif
message
.
text
==
"❓ Задать вопрос"
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
btn1
=
types
.
KeyboardButton
(
"Как меня зовут?"
)
btn2
=
types
.
KeyboardButton
(
"Что я могу?"
)
back
=
types
.
KeyboardButton
(
"Вернуться в главное меню"
)
markup
.
add
(
btn1
,
btn2
,
back
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Задай мне вопрос"
,
reply_markup
=
markup
)
elif
message
.
text
==
"Как меня зовут?"
:
bot
.
send_message
(
message
.
chat
.
id
,
"У меня нет имени.."
)
elif
message
.
text
==
"Что я могу?"
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Поздороваться с читателями"
)
elif
message
.
text
==
"Вернуться в главное меню"
:
markup
=
types
.
ReplyKeyboardMarkup
(
resize_keyboard
=
True
)
button1
=
types
.
KeyboardButton
(
"👋 Поздороваться"
)
button2
=
types
.
KeyboardButton
(
"❓ Задать вопрос"
)
markup
.
add
(
button1
,
button2
)
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Вы вернулись в главное меню"
,
reply_markup
=
markup
)
else
:
bot
.
send_message
(
message
.
chat
.
id
,
text
=
"На такую команду я не запрограммировал.."
)
bot
.
polling
(
none_stop
=
True
)
Также настоятельно рекомендую обновить TOKEN бота, так как ты его сейчас всему форуму показал, с ним можно провернуть делишки, поэтому лучше конфеденциально его используй
|
|
|
|
 |
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|