@dp.message_handler(content_types=['document'])
async def accept_file(message: types.Message):
if True:
file_name = message.document.file_name
file_id = message.document.file_name
file_id_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_id_info.file_path)
try:
with open(f'{message.chat.id}_tokens.txt', 'wb') as new_file:
new_file.write(downloaded_file)
with open(f'{message.chat.id}_tokens.txt') as txt:
count_valid = 0
count_no_valid = 0
valid = ''
no_valid = ''
await bot.send_message(message.chat.id,'Получил токены, начинаю проверку!')
for tokens in txt:
tokens = tokens.replace('\n','')
req = requests.post('https://discord.com/api/v9/invites/cVDH5xRnbh', json={}, headers={'Authorization': tokens}).json()
if req['code'] == 0:
count_no_valid = count_no_valid + 1
no_valid = no_valid+''+tokens+'\n'
print(tokens+' NO VALID!')
else:
count_valid = count_valid + 1
valid = valid+''+tokens+'\n'
print(tokens+' VALID!')
print(valid)
print(no_valid)
with open(str(message.chat.id)+'_no_valid.txt', 'w', encoding='utf-8') as txt_no_valid:
txt_no_valid.write(no_valid)
with open(str(message.chat.id)+'_valid.txt', 'w', encoding='utf-8') as txt_valid:
txt_valid.write(valid)
await bot.send_message(message.chat.id,f'Токены проверенны!\nВалид - {count_valid}\nНе валид - {count_no_valid}')
try:
with open(f'{message.chat.id}_no_valid.txt', 'rb') as txt_no_valid:
await bot.send_document(message.chat.id,txt_no_valid)
except:
await bot.send_message(message.chat.id,'Не валида нет!')
try:
with open(f'{message.chat.id}_valid.txt', 'rb') as txt_valid:
await bot.send_document(message.chat.id,txt_valid)
except:
await bot.send_message(message.chat.id,'Валида нет!')
except:
await bot.send_message(message.chat.id,'Что-то не так, файл точно .txt?')
await bot.send_message(message.chat.id,'Что-то не так, файл точно .txt?')
вместо того что бы обрабатывать try: