R
R
Reifaren2021-03-22 22:01:27
Python
Reifaren, 2021-03-22 22:01:27

Error in programming telegram bot?

import telebot
import config

bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(content_types=['text'])
def lalala(message):
  bot.send_message(message.chat.id, message.text)

# RUN
bot.polling(none_stop=True)

Mistake
Traceback (most recent call last):
  File "C:\Users\Артем\Desktop\testbot.py", line 4, in <module>
    bot = telebot.TeleBot(config.TOKEN)
AttributeError: module 'config' has no attribute 'TOKEN'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SashaN69, 2021-03-22
@SashaN69

from config import TOKEN

S
Sergey Karbivnichy, 2021-03-22
@hottabxp

Remove this:
import config
And replace config.TOKEN with your own token.
Better yet, read a book.
PS:
1) This question is simple;
2) This question has nothing to do with bots or telegrams.

E
Evgeniy _, 2021-03-22
@GeneD88

In this case, apparently config is its own file, in which TOKEN is stored. You either create a config.py file with a token, or specify it directly in the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question