Как сделать чтобы он прочитывал txt документ и выводил строку с нужными аргументами?
Мне нужно чтобы он выводил строку с определенными аргументами, то есть, я пишу !giftkey vip 30d, он прочитывает документ keys.txt в котором лежат ключи то есть:
sa76gs9d78g57ds9gds60sgd06gds | vip | 90d
afsashkfasdf707gh94sgf7h4hg8s | vip | 30d
sdgoia6sd987as59f6asgfasyr9fa | premium | LF
fglg98hdhgfh677dg8h95f9h657hd | vip | LF
sdfuigsdugifgsu123ib123g12kl3 | premium | 90d
Код который у меня есть:
@bot.command(name="giftkey", brief="Выдача ключа", usage="giftkey")
async def giftkey(ctx, arg1, arg2):
with open("key.txt", encoding='utf-8') as file:
lines = file.readlines()
lines_to_choice = ["vip"]
lines_to_choise = ["premium"]
lines_to_choice1 = ["30d"]
lines_to_choise2 = ["90d"]
for line in lines:
if arg1 and arg2 in line:
lines_to_choice.append(line)
lines_to_choice1.append(line)
elif arg1 and arg2 in line:
lines_tochoise.append(line)
lines_to_choise2.append(line)
random_line = random.choice(lines_to_choice).strip()
await ctx.send(random_line)
Источник: Stack Overflow на русском