So I am coding a Discord bot using Python that gets the data from Roblox's API to check if a user is in a allied group. So I made a loop to find if the user is in the same group but it does not work as intended. When I was testing it, it would say I was not in the group even though I was. I received no errors when running this code:
for x in data:
num = data.index(x)
if data[num]["Name"] == "ΒΕ ? British Empire":
print("its bigs squad")
print(data[num]["Role"])
bruh = str(data[num]["Role"])
dat = requests.get("https://api.roblox.com/groups/8616457/allies")
date = dat.json()['Groups']
groups = list(date)
for f in groups:
e = groups.index(f)
print(e)
if data[num]['Name'] == groups[e]['Name']:
print("in group")
member = ctx.author
role = discord.utils.get(member.guild.roles, name=bruh)
await member.add_roles(role)
await ctx.send(f"Gave the **{bruh}** role!") #fix
else:
print("not in group")```
###JSON data I am comparing
{"Groups":[{"Name":"ΒΕ ? Administration","Id":8664914,"Owner":{"Name":"EA6Y","Id":100403322},"EmblemUrl":"http://www.roblox.com/asset/?id=6109292568","Description":"?????????????????????? & ????????????????????????????
???????????
The Development & Administration team include developers, administrators, and moderators that keep the group running smoothly, in-game, and in the communication servers."```
###Also comparing this one
[{"Name":"Roblox","Id":7,"EmblemUrl":"http://www.roblox.com/asset/?id=607941191","EmblemId":607941191,"Rank":255,"Role":"Owner","IsPrimary":false,"IsInClan":false},{"Name":"Roblox Wiki","Id":127081,"EmblemUrl":"http://www.roblox.com/asset/?id=607954721","EmblemId":607954721,"Rank":254,"Role":"Wiki System Operator","IsPrimary":false,"IsInClan":false}]
question from:
https://stackoverflow.com/questions/65863318/how-would-i-be-able-to-compare-2-sets-of-json-data-and-check-if-one-is-in-the-ot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…