Telebot,如何将来自用户的消息保存到变量中?

时间:2019-01-16 19:53:07

标签: python telegram-bot python-telegram-bot

我正在制作一个电报机器人,询问用户不同的问题,我需要将他们的答案保存到变量中。

@bot.message_handler(commands=['addproduct'])
def handle_text(message):
    bot.send_message(message.chat.id, "Price =")

然后,用户回答,程序应将答案保存为可变价格。

如何将来自用户的消息保存到变量中?

1 个答案:

答案 0 :(得分:0)

Public Sub Workbook_Open()

Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim copyFrom As Range
Dim lRow As Long
Dim strSearch As String
Dim vrtSelectedItem As Variant

Set wb1 = Application.Workbooks.Open("C:\Users\myfolder\Desktop\Excel Master Test\ROLE BASED TRACKER DRAFT.xlsx")
Set ws1 = wb1.Worksheets("Master")

Set wb2 = ThisWorkbook
Set ws2 = wb2.Worksheets("Sheet1")

'~~> Specifies which resources info. you are retrieving
strSearch = "117"
ws2.Cells.Clear

'~~> Copying the header information and formatting.
ws1.Range("1:1").Copy
ws2.Range("1:1").PasteSpecial

With ws1

    '~~> Remove any filters
    .AutoFilterMode = False

    lRow = .Range("A" & .Rows.Count).End(xlUp).Row

    If ws1.Range("AD1:AD" & lRow) <> ws1.Range("L1:L" & lRow) Then

        With .Range("AD1:AD" & lRow)
            .AutoFilter Field:=1, Criteria1:=strSearch
            Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
        End With

        .AutoFilterMode = False

    End If

End With

'~~> Destination File

With ws2
    If Application.WorksheetFunction.CountA(.Rows) <> 0 Then
        lRow = .Cells.Find(What:="*", _
                      After:=.Range("A1"), _
                      Lookat:=xlPart, _
                      LookIn:=xlFormulas, _
                      SearchOrder:=xlByRows, _
                      SearchDirection:=xlPrevious, _
                      MatchCase:=False).Row + 1
    Else
        lRow = .Range("A" & Rows.Count).End(xlUp).Row
    End If
    copyFrom.Copy .Rows(lRow)
End With

With ws1

    '~~> Remove any filters
    .AutoFilterMode = False

    lRow = .Range("A" & .Rows.Count).End(xlUp).Row

    If ws1.Range("AD1:AD" & lRow) = ws1.Range("L1:L" & lRow) Then

        With .Range("L1:L" & lRow)
            .AutoFilter Field:=1, Criteria1:=strSearch
            Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
        End With

        .AutoFilterMode = False

    End If

End With

'~~> Destination File

With ws2
    If Application.WorksheetFunction.CountA(.Rows) <> 0 Then
        lRow = .Cells.Find(What:="*", _
                      After:=.Range("A1"), _
                      Lookat:=xlPart, _
                      LookIn:=xlFormulas, _
                      SearchOrder:=xlByRows, _
                      SearchDirection:=xlPrevious, _
                      MatchCase:=False).Row + 1
    Else
        lRow = .Range("A" & Rows.Count).End(xlUp).Row
    End If
    copyFrom.Copy .Rows(lRow)
End With


With ws2.Sort
    .SetRange Range("A2:A12000")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With

wb1.Save
wb1.Close
' wb2.Save

End Sub

您可以将“ userPrice”变量保存在数据库或json / txt文件中,然后获得安全变量。