ANTICHAT

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

лимаров 21.04.2024 14:10

https://forum.antichat.xyz/attachmen...899fa3aa25.png

помогите по братски, vsc выдает ошибку "message не определено"

Python:





Код:

bot
.
send_message
(
message
.
chat
.
id
,
text
=
"Привет, {0.first_name}! Я бот помощник"
.
format
(
message
.
from_user
)
,
reply_markup
=
markup
)


nelit.dev 21.04.2024 14:15

Цитата:

Сообщение от лимаров

помогите по братски, 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

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
)


nelit.dev 21.04.2024 14:17

Цитата:

Сообщение от лимаров

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 строка ты вызываешь метод сенд месседж класса бот и передаешь в него объект месседж. при этом не получил его.

#SameLine 21.04.2024 14:20

Цитата:

Сообщение от лимаров

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 бота, так как ты его сейчас всему форуму показал, с ним можно провернуть делишки, поэтому лучше конфеденциально его используй


Время: 22:52