Issue
Hi so let's get straight to the point. Last time i decided to make config file per server to my bot. I also wanted to add command that sends a message to specific channel when bot gets update but i know that not everyone wants to get this message or want to make a special channel for this so i added option to config to change it. That's how config file look for now:
{
"update": [
{
"wlaczone": true,
"kanal": 757971193205882900
}
]
}
And that's how command looks like:
@bot.command()
@commands.check(user_is_me)
async def update(ctx):
print('1')
for server in bot.guilds:
print('2')
with open(f'serverSetting/{server.id}.json', 'r', encoding='utf-8') as a:
print('3')
d = json.load(a)
print(d)
print('4')
print(d["update"]["wlaczone"])
for w in d["update"]["wlaczone"]:
print(w)
print('5')
if w == True:
print('6.1')
c = d['update']['kanal']
print('7')
channel = discord.utils.get(bot.get_all_channels(), id=c)
print('8')
try:
print('9')
await channel.send("@everyone Bot dostał właśnie update! Sprawdź |changelog \nsory za ping xD\n~nitolar play")
print('10')
except Exception:
continue
else:
break
elif w == False:
print('6.2')
pass
And command stops working after printing number 4. I don't know why it happens because something like this never happened to me but when i remove ["wlaczone"]
it works and print this {'wlaczone': True, 'kanal': 757971193205882900}
. It would be awesome if someone could help me with that. Thanks for help!
Solution
d["update"]
is a list, try d["update"][0]["wlaczone"]
.
Pay attention to the exception the code raise.
Answered By - N0I0C0K
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.