Answer the question
In order to leave comments, you need to log in
TypeError: set_metawallet() takes 2 positional arguments but 3 were given. What to do?
main code:
import logging
from aiogram import Bot, Dispatcher, executor, types
import markups as nav
from db import Database
TOKEN = "5103821559:AAGL20hGYw8wUvBdu7u_vNeUQlhVxjmQIQs"
logging.basicConfig(level=logging.INFO)
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
db = Database('database.db')
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
if(not db.user_exists(message.from_user.id)):
db.add_user(message.from_user.id)
await bot.send_message(message.from_user.id, "Укажите имя пользователя твиттера")
else:
await bot.send_message(message.from_user.id, "Вы уже зарегистрированы!", reply_markup=nav.mainMenu)
@dp.message_handler()
async def bot_message(message: types.Message):
if message.chat.type == 'private':
if message.text == 'ПРОФИЛЬ':
user_nickname = "Ваш ник: " + db.get_nickname(message.from_user.id)
await bot.send_message(message.from_user.id, user_nickname)
elif message.text == 'НАСТРОЙКИ':
await bot.send_message(message.from_user.id, "НАСТРОЙКИ")
else:
if db.get_signup(message.from_user.id) == "setnickname":
if not '@' in message.text:
await bot.send_message(message.from_user.id, 'Введите имя пользователя начиная с "@"')
elif(len(message.text) > 51):
await bot.send_message(message.from_user.id, "Никнейм не должен превышать 50 символов")
else:
db.set_metawallet(message.from_user.id, message.text)
db.set_signup(message.from_user.id, "done")
await bot.send_message(message.from_user.id, "Регистрация прошла успешно! Нажмите на кнопку 'НАСТРОЙКИ', чтобы закончить регистрацию", reply_markup=nav.mainMenu)
else:
await bot.send_message(message.from_user.id, "Не понял")
@dp.message_handler(commands=['wallet'])
async def start(message: types.Message):
if db.get_metawallet(message.from_user.id) == "0":
db.set_metawallet(message.from_user.id, message.text)
await bot.send_message(message.from_user.id,"Регистрация прошла успешно! Нажмите на кнопку 'НАСТРОЙКИ', чтобы закончить регистрацию")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates = True)
import sqlite3
class Database:
def __init__(self, db_file):
self.connection = sqlite3.connect(db_file)
self.cursor = self.connection.cursor()
def add_user(self, user_id):
with self.connection:
return self.cursor.execute("INSERT INTO `users` (`user_id`) VALUES (?)", (user_id,))
def user_exists(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT * FROM `users` WHERE `user_id` = ?", (user_id,)).fetchall()
return bool(len(result))
def set_nickname(self, user_id, nickname):
with self.connection:
return self.cursor.execute("UPDATE `users` SET `nickname` = ? WHERE `user_id` = ?", (nickname, user_id,))
def get_signup(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT `signup` FROM `users` WHERE `user_id` = ?", (user_id,)).fetchall()
for row in result:
signup = str(row[0])
return signup
def set_signup(self, user_id, signup):
with self.connection:
return self.cursor.execute("UPDATE `users` SET `signup` = ? WHERE `user_id` = ?", (signup, user_id,))
def get_nickname(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT `nickname` FROM `users` WHERE `user_id` = ?", (user_id,)).fetchall()
for row in result:
nickname = str(row[0])
return nickname
def set_metawallet(self, user_id):
with self.connection:
return self.cursor.execute("UPDATE `users` SET `wallet` = ? WHERE `user_id` = ?", (wallet, user_id, ))
def get_metawallet(self, user_id):
with self.connection:
result = self.cursor.execute("SELECT `wallet` FROM `users` WHERE `user_id` = ?", (user_id,)).fetchall()
for row in result:
wallet = str(row[0])
return wallet
Answer the question
In order to leave comments, you need to log in
I sort of figured it out, fixed it in db.py in the set_metawallet function:
def set_metawallet(self, wallet, user_id):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question