How do I subtract the immediate value from Python and compare it to a fixed value of 120?

Asked 2 years ago, Updated 2 years ago, 14 views

if sheet["A" + str(i)].value == a1.name:
rn = random.randint(1,100)
percent = sheet["B" + str(i)].value
level = sheet["C" + str(i)].value
cooltime = sheet["D" + str(i)].value
If datetime.datetime.now()-cooltime >= 120: # <- This is line 52.

The error appears as invalid syntax(,line 52)pylint(syntax-error). Can you solve it? Due to this error, we have not been able to develop the bot for several days. For your information, I'm done with the import. I'm done installing the module.

Add information:

import discord
from discord.ext import commands
import openpyxl
import random
import datetime
import os

bot = commands.Bot(command_prefix = '/')
global filename
filename = 'Enhanced.xlsx'

@bot.event
async def on_ready():
    print('The reinforcement bot has been activated.')

#Handle options to receive messages
@bot.command(pass_context=True)
async def hardening (ctx):
    a1 = ctx.message.author

    # Check the location of the executable file to ensure that the file location is the same as that of the executable file
    BASE_PATH = os.path.dirname(os.path.abspath(__file__))+"\\"
    # Create the first time if the file does not exist
    if os.path.isfile(BASE_PATH+filename) == False:
        newbook = openpyxl.Workbook()
        newbook.save(BASE_PATH+filename)
        newbook.close()
        newbook = None
        #Printing that you made the file
        print ("create reinforced file")

    print("File location:"+os.path.abspath(BASE_PATH+filename))

    book = openpyxl.load_workbook(BASE_PATH+filename)
    sheet = book.worksheets[0]
    i = 1
    # Variables to determine if you want to continue looking for Excel
    needLoop = True
    while needLoop:
        print ("Row No."+str(i)+"Checking...")
        print("User number: "+str(a1)")
        print("Excel User Number: %s"%sheet["A" + str(i).value)
        print("Excel probability: %s"%sheet["B" + str(i).value)
        print("Excel level: %s"%sheet["C" + str(i).value)
        print("Excel Last Time: %s"%sheet["D" + str(i).value)
        if sheet["A" + str(i)].value == a1.name:
            rn = random.randint(1,100)
            percent = sheet["B" + str(i)].value
            level = sheet["C" + str(i)].value
            cooltime = sheet["D" + str(i)].value
            dt = datetime.datetime.now()
            if dt - cooltime >= 120:
                if rn >= percent:
                    level = sheet["C" + str(i)].value + 1
                    percent = sheet["B" + str(i)].value / 3
                    sheet["C" + str(i)] = level
                    sheet["B" + str(i)] = percent
                    cooltime = datetime.datetime.now()
                    sheet["D" + str(i)].value = cooltime
                    book.save(filename)
                    ctx.sent(a1+" raised it to level"+str(level)+". Probability after hardening:"+str(percent))
                else:
                    level = sheet["C" + str(i)].value - 1
                    percent = sheet["B" + str(i)].value * 3
                    sheet["C" + str(i)] = level
                    sheet["B" + str(i)] = percent
                    cooltime = datetime.datetime.now()
                    sheet["D" + str(i)].value = cooltime
                    book.save(filename)
                    ctx.send(a1+" has gone down to"+str(level)+" level. Probability after hardening:"+str(percent))
            else:
                ctx.Send(a1+"nim"+str(cooltime)+" has a cool time left.")
        elif (sheet["A" + str(i)].value == None):
            #If there is no information in the excel, end it and add the current user's initial value
            sheet["A" + str(i)] = a1.name
            sheet["B" + str(i)] = 100
            sheet["C" + str(i)] = 1
            sheet["D" + str(i)] = datetime.datetime.now()
            i = i + 1
            print ("User Data Generation Completed")
    needLoop = False
    i = i + 1
    print ("End of execution of reinforcement")
    book.save(BASE_PATH+filename)
    # When it is possible to save, it is out of the 을
    book.close()
    ctx.send('User data generated successfully. Please reinforce it again.')

bot.run('bot_token') # <- It's actually a discode bot token. The bot token should not be leaked, so I kept it private like this. Please ignore me.

python

2022-09-22 08:08

2 Answers

datetime.datetime.now() is the return type datetime.datetime.


2022-09-22 08:08

We recommend that you check the value of the cooltime variable to get the value of the Excel.
If the code you put up in the question is the full code
We have no choice but to judge that it is a problem caused by the entry of string type data with parentheses in the corresponding value.


2022-09-22 08:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.