Ошибка в проверке данных python Discord Bot
Я делаю проверку если в json файле есть этот текст будет то будет печататься текст а если его нету то будет печататься другой текст, но у меня такая фигня то что этого текста нету и он выдаёт ошибку
responses = open('quotes.txt').read().splitlines()
random.seed(a=None)
response = random.choice(responses)
intents = discord.Intents().all()
bot = commands.Bot(command_prefix="!", intents = intents)
bot.remove_command('help')
#---Id Member----#
@bot.command()
async def name(ctx, arg):
async with aiohttp.ClientSession() as session:
request = await session.get(f'http://all-roblox-parody.kchessub.beget.tech/accounts/{arg}ach.json') # Make a request
request2 = await session.get(f'http://all-roblox-parody.kchessub.beget.tech/accounts/{arg}.json')
dogjson = await request.json() # Convert it to a JSON dictionary
with open("prefix.json", "r") as f:
prefix44 = json.load(f)
prefix44[str(arg)] = f"{response}"
with open("prefix.json", "w") as f:
json.dump(prefix44, f, indent=4)
author = ctx.message.author
user_name = author.id
await ctx.reply(f"""Вставь этот текст в описание чтобы подтсвердить свой аккаунт {arg} текст: **{response}**""")
@bot.command()
async def myprofile_parody(ctx):
with open("prefix2.json", "r") as read_file:
author = ctx.message.author
YourId = author.id
FixBag = f'{YourId}'
data33 = json.load(read_file)
data_length33 = len(data33)
async with aiohttp.ClientSession() as session:
request1112 = await session.get(f'http://all-roblox-parody.kchessub.beget.tech/accounts/{data33[FixBag]}ach.json') # Make a request
dogjson1112 = await request1112.json() # Convert it to a JSON dictionary
await ctx.send(f"{dogjson1112[data33[FixBag]]['Money']}")
@bot.command()
async def verify(ctx, arg):
with open("verify.json", "r") as read_file:
verify12 = json.load(read_file)
verify1 = len(verify12)
with open("prefix.json", "r") as read_file:
data = json.load(read_file)
data_length = len(data)
author = ctx.message.author
user_name = author.id
FixBag = f'{user_name}'
with open("prefix2.json", "r") as f:
prefix445 = json.load(f)
async with aiohttp.ClientSession() as session:
request111 = await session.get(f'http://all-roblox-parody.kchessub.beget.tech/accounts/{arg}.json') # Make a request
dogjson111 = await request111.json() # Convert it to a JSON dictionary
if verify12[arg] == "":
print(f"Аккаунт {arg} уже используют")
await ctx.reply(f"Аккаунт {arg} уже используют")
else:
if prefix445 == '':
with open("prefix2.json", "r") as f:
prefix445 = json.load(f)
prefix445[str(user_name)] = f"{arg}"
with open("prefix2.json", "w") as f:
json.dump(prefix445, f, indent=4)
with open("prefix.json", "r") as read_file:
data = json.load(read_file)
data_length = len(data)
async with aiohttp.ClientSession() as session:
request111 = await session.get(f'http://all-roblox-parody.kchessub.beget.tech/accounts/{arg}.json') # Make a request
dogjson111 = await request111.json() # Convert it to a JSON dictionary
author = ctx.message.author
user_name = author.id
if data[arg] == dogjson111[arg]['Description']:
with open("prefix2.json", "r") as f:
prefix445 = json.load(f)
prefix445[str(user_name)] = f"{arg}"
with open("prefix2.json", "w") as f:
json.dump(prefix445, f, indent=4)
with open("verify.json", "r") as f:
ver2 = json.load(f)
ver2[str(arg)] = arg
with open("verify.json", "w") as f:
json.dump(ver2, f, indent=4)
await ctx.send("Проверка пройдена!")
else:
await ctx.reply("Пожалуйста введи правельный текст!!!!")
Если я ввожу !verify и ник который есть в файле verify.json то он говорит что такой файл найден, а если там нету этого ника то просто ошибка.
А должно быть так то что если его нету то должны добавляться файлы в сам verify.json
verify.json
{
"TVOFFicial1": ""
}
В prefix.json находится находятся проверка с помощью фраз
{
"TVCorparation": "You Dead Gun",
"TVOFFicial1": "I love Roblox",
"TVC": "You Dead Gun"
}
сама ошибка
2022-11-26 08:04:03 ERROR discord.ext.commands.bot Ignoring exception in command verify
Traceback (most recent call last):
File "/home/runner/GrowlingClientsideMp3/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 229, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/GrowlingClientsideMp3/main.py", line 83, in verify
if verify12[arg] == "":
KeyError: 'TVC'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/GrowlingClientsideMp3/venv/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1349, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/GrowlingClientsideMp3/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1023, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "/home/runner/GrowlingClientsideMp3/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 238, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'TVC'