M
M
Machoser2021-11-24 05:53:30
Python
Machoser, 2021-11-24 05:53:30

Error when writing a telegram bot on aiogram?

import aiogram
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from config import token

bot = Bot(token=TOKEN)
dp = Dispatcher(bot)

@dp.message_handler(commands=['start'] )
async def process_start_command(message: types.Message):
await message.reply("Hello!\nWrite me something!")

@dp.message_handler(commands=['help'])
async def process_help_command(message: types. Message):
await message.reply("Write me something and I'll send this text back to you!")

@dp.message_handler(commands=['test'])
async def cmd_image(message: types.Message):
await message.answer_video(file_id)

if __name__ == '__main__':
executor.start_polling(dp)
Error : Traceback (most recent call last):
File "/data/user/0/en.iiec.pydroid3/files/accomp_files/ iiec_run/iiec_run.py", line 31, in
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec( open(mainpyfile).read(), __main__.__dict__)
File "", line 5, in
ImportError: cannot import name 'token' from 'config' (/storage/emulated/0/Download/python/config.py)

[ Program finished]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
usiting, 2021-11-24
@usiting

cannot import name 'token' from 'config' (
/storage/emulated/0/Download/python/config.py )
bot = telebot.TeleBot('сюда токен своего бота')

I
inworkl, 2021-11-24
@inworkl

Just take into account how your variable is specified in the config file
bot = Bot(token=TOKEN)
And then I see you specify the TOKEN variable in upper case, and import it in lower case. And it's like different things...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question