R
R
r1dddy4sv2020-12-04 19:39:58
Python
r1dddy4sv, 2020-12-04 19:39:58

Module 'dbworker' has no attribute 'get_md'?

import config
import telebot
import random
import time
import dbworker
import requests
from telebot import types

Token='token'
bot=telebot.TeleBot(Token)
photo='url photo'
def menu(message):
    m=dbworker.get_md(message.chat.id)
    bot.send_message(message.chat.id,'Ниже представлен каталог товаров!',reply_markup=menu_back)
    m1=bot.send_message(message.chat.id,'Ниже представлен каталог товаров!',reply_markup=menu_back).message_id
    bot.send_photo(message.chat.id,photo,caption='товар №1\nописание',reply_markup=size1)
    m2=bot.send_photo(message.chat.id,photo,caption='товар №1\nописание',reply_markup=size1).message_id
    bot.send_photo(message.chat.id,photo,caption='товар №2\nописание',reply_markup=size2)
    m3=bot.send_photo(message.chat.id,photo,caption='товар №2\nописание',reply_markup=size2).message_id
    bot.send_photo(message.chat.id,photo,caption='товар №3\nописание',reply_markup=size3)
    m4=bot.send_photo(message.chat.id,photo,caption='товар №3\nописание',reply_markup=size3).message_id
    md=[]
    md.append(m1,m2,m3,m4)
    if md.append(m)>10:
        md=md.append(m)
        md=md.pop(0,1,2,3)
        dbworker.set_md(message.chat.id, md)
    else:
        dbworker.set_md(message.chat.id, md.append(m))

@bot.message_handler(commands=['start'])
def welcome(message):
    dbworker.set_state(message.chat.id, config.States.S_GL.value)
    gl(message)
@bot.message_handler(func=lambda message: dbworker.get_current_state(message.chat.id) == config.States.S_GL.value)
def otv(message):
    if message.chat.type=='private':
        if message.text=='Сделать Заказ Онлайн!':
            dbworker.set_state(message.chat.id, config.States.S_MENU.value)
            menu(message)  
if __name__ == "__main__":
    bot.infinity_polling()


dbworker:
from vedis import Vedis
import config

def get_md(user_id):
    with Vedis(config.db_file4) as db4:
        try:
            return db4[user_id].decode()  
        except KeyError: 
            return   
        
def set_md(user_id, value):
    with Vedis(config.db_file4) as db4:
        try:
            db4[user_id] = value
            return True
        except:
            
            return False
        
def get_current_state(user_id):
    with Vedis(config.db_file) as db:
        try:
            return db[user_id].decode() 
        except KeyError: 
            return config.States.S_GL.value  

def set_state(user_id, value):
    with Vedis(config.db_file) as db:
        try:
            db[user_id] = value
            return True
        except:
            return False

config:
from enum import Enum
Token='1419935533:AAG5blXisxySbyZHgYWcSwIC8P_9iehCOHY'
db_file = "database.vdb"
db_file2 = "database2.vdb"
class States(Enum):
    S_INFO= "0"  
    S_MENU = "1"
    S_GL= "2"
    S_AMOUNT='3'
    S_OPLATI='4'


error:
module 'dbworker' has no attribute 'get_md'

in the menu function, I save the id of the messages sent by the bot to the database in order to delete these messages later.

config and dbworker are in the same folder with the main code

(I did not present all the code, but I think this is enough to see the problem, if you need to add something, write)

I ask you for help
thanks!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question