Как продолжить выполнение команды в зависимости от того, ответит ли пользователь «да» или «нет»?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как продолжить выполнение команды в зависимости от того, ответит ли пользователь «да» или «нет»?

Сообщение Anonymous »

Я пытаюсь сделать так, чтобы пользователь запускал команду, бот спрашивал, готов ли пользователь, и если пользователь отвечал «да», бот продолжал выполнять команду.

Код: Выделить всё

@bot.command(name="mission")
async def mission(ctx):
scenarioslist = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 10]
catnamelist = ['Mittens', 'Milo', 'Luna', 'Mochi', 'Tigger', 'Misty']
catcolorlist = ['Siamese', 'Persian', 'hairless', 'tabby', 'munchkin', 'Maine Coon']
catsizelist = ['', 'big', 'massive', 'small', 'tiny']
user = ctx.message.author
guild = ctx.guild.id
table = "PEOPLE_" + str(guild)
passfail1 = random.randint(1, 10)
passfail2 = random.randint(1, 9)
location = random.randint(1, 3)
scenarios = random.choice(scenarioslist)
catname = random.choice(catnamelist)
catcolor = random.choice(catcolorlist)
catsize = random.choice(catsizelist)

try:
connection = mysql.connector.connect(
host="localhost",
port="3306",
user="root",
password="root",
database="naruto_game"
)
cursor = connection.cursor()

sql_select_query = "SELECT * from " + table + " where user like '"+ str(ctx.message.author) +"'"
cursor.execute(sql_select_query)

record = cursor.fetchall()

for row in record:
if row[5] == "Genin" and row [6] < 800:
await ctx.send("You will be embarking on an F-Rank mission. Are you ready?")
msg = await bot.wait_for("message", check=lambda m: m.channel == ctx.channel and m.author == user)

decision = msg.content

if decision == "yes":
if passfail1 < 10:
if location == 1 and scenarios == [6]:
await ctx.send("Mrs. Nishina, one of the village elders, cat has gone missing. You've been assigned to find and return it to her.")
await asyncio.sleep(2)
await ctx.send(f"You go to Mrs. Nishina's home to find out as much information as you can about the cat. She tells you that her missing cat is a {catsize} {catcolor} cat named {catname}.")

elif passfail1 == 10:
if location == 1:
print("")

else:
await ctx.send(f"You didn't say {str('"yes"')}, so I'm ending the mission.")

except mysql.connector.Error as error:
print("Failed to find name: {}".format(error))
finally:
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection has been closed.")
Я не получаю никаких ошибок при запуске кода, но бот не отвечает после того, как пользователь говорит «да». Я просмотрел другие вопросы и не нашел ничего, что помогло бы. Проблема может заключаться за пределами самой части пользовательского ввода.

Подробнее здесь: https://stackoverflow.com/questions/790 ... -yes-or-no
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»