Answer the question
In order to leave comments, you need to log in
Error in writing Telegram bot - Python (aiogram)?
I am writing a telegram bot in python, I decided to check it in action and an error pops up
config.py:
TOKEN = "token"
GROUP_ID = 1876350406
bot.py:
import config
import logging
from aiogram import Bot, Dispatcher, executor, types
from filters import IsAdminFilter
#log level
logging.basicConfig(level=logging.INFO)
#bot init
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
#filters
dp.filters_factory.bind(IsAdminFilter)
#ban
@dp.message_handler(is_admin=True, commands=["ban"], commands_prefix="!/")
async def cmd_ban(message: types.Message):
if not message.reply_to_message:
await message.reply("Эта команда должна быть ответом на сообщение, йоу нига!")
return
await message.bot.delete_message(chat_id=config.GROUP_ID, message.message_id)
await message.bot.kick_chat_member(chat_id=config.GROUP_ID, user_id=message.reply_to_message.from_user.id)
await message.reply_to_message.reply("Этот нига забанен!!!")
#мат
@dp.message_handler()
async def filter_messages(message: types.Message):
if "бл8ть" in message.text:
await message.reply("Не ругайся матом!")
await message.delete()
# run long-polling
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
filters.py:
from aiogram import types
from aiogram.dispatcher.filters import BoundFilter
class IsAdminFilter(BoundFilter):
key = "is_admin"
def __init__(self, is_admin):
self.is_admin = is_admin
async def check(self, message: types.Message):
member = await message.bot.get_chat_member(message.chat.id, message.from_user.id)
return member.is_chat_admin()
И вылезает такая ошибка:
> python bot.py
File "bot.py", line 25
await message.bot.delete_message(chat_id=config.GROUP_ID, message.message_id)
^
SyntaxError: positional argument follows keyword argument
Answer the question
In order to leave comments, you need to log in
Well, you can translate the description of the error, everything is written there.
message_id is a named argument. Try like this:
await message.bot.delete_message(chat_id=config.GROUP_ID, message_id=message.message_id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question