Skip to content

Commit e006a1c

Browse files
authored
Merge pull request #162 from PyBotDevs/afksystem.fix-error-if-guild-has-no-afk-statuses
Fix AFK system returning an error if the message guild isn't already indexed in the `user_presence` database
2 parents 3abf4b2 + b4ae7ee commit e006a1c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ async def on_message(ctx):
9595
else: items[str(ctx.author.id)][str(z)] = 0
9696
save()
9797
uList = list()
98-
for x in user_presence[str(ctx.guild.id)].keys(): uList.append(x)
98+
if str(ctx.guild.id) in user_presence:
99+
for x in user_presence[str(ctx.guild.id)].keys(): uList.append(x)
100+
else: pass
99101
for i in uList:
100102
if i in ctx.content and not ctx.author.bot:
101103
fetch_user = client.get_user(id(i))
102104
await ctx.channel.send(f"{fetch_user.display_name} went AFK <t:{math.floor(user_presence[str(ctx.guild.id)][str(i)]['time'])}:R>: {user_presence[str(ctx.guild.id)][str(i)]['response']}")
103-
if str(ctx.author.id) in user_presence[str(ctx.guild.id)]:
105+
if str(ctx.guild.id) in user_presence and str(ctx.author.id) in user_presence[str(ctx.guild.id)]:
104106
del user_presence[str(ctx.guild.id)][str(ctx.author.id)]
105107
save()
106108
m1 = await ctx.channel.send(f"Welcome back {ctx.author.mention}. Your AFK has been removed.")

0 commit comments

Comments
 (0)