Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
test logging roles added/removed from users
Browse files
app.py
CHANGED
@@ -243,6 +243,48 @@ async def on_member_update(before, after):
|
|
243 |
embed.add_field(name="New", value=after.nick, inline=True)
|
244 |
embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
|
245 |
await bot.log_channel.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
except Exception as e:
|
248 |
print(f"on_member_update Error: {e}")
|
|
|
243 |
embed.add_field(name="New", value=after.nick, inline=True)
|
244 |
embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
|
245 |
await bot.log_channel.send(embed=embed)
|
246 |
+
|
247 |
+
# roles being added/removed
|
248 |
+
before_roles = set(before.roles)
|
249 |
+
after_roles = set(after.roles)
|
250 |
+
|
251 |
+
# added
|
252 |
+
added_roles = after_roles - before_roles
|
253 |
+
for role in added_roles:
|
254 |
+
async for entry in after.guild.audit_logs(action=discord.AuditLogAction.member_role_update, limit=5):
|
255 |
+
if entry.target == after and role in entry.changes.after.roles:
|
256 |
+
moderator = entry.user
|
257 |
+
break
|
258 |
+
else:
|
259 |
+
moderator = "Unknown"
|
260 |
+
|
261 |
+
embed = Embed(color=Color.green())
|
262 |
+
embed.set_author(name=f"{after} ID: {after.id}", icon_url=after.avatar.url if after.avatar else bot.user.avatar.url)
|
263 |
+
embed.title = "Role Added"
|
264 |
+
embed.add_field(name="User", value=after.mention, inline=True)
|
265 |
+
embed.add_field(name="Role", value=role.name, inline=True)
|
266 |
+
embed.add_field(name="Added By", value=moderator.mention if isinstance(moderator, discord.Member) else "Unknown", inline=True)
|
267 |
+
embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
|
268 |
+
await bot.log_channel.send(embed=embed)
|
269 |
+
|
270 |
+
# removed
|
271 |
+
removed_roles = before_roles - after_roles
|
272 |
+
for role in removed_roles:
|
273 |
+
async for entry in after.guild.audit_logs(action=discord.AuditLogAction.member_role_update, limit=5):
|
274 |
+
if entry.target == after and role in entry.changes.before.roles:
|
275 |
+
moderator = entry.user
|
276 |
+
break
|
277 |
+
else:
|
278 |
+
moderator = "Unknown"
|
279 |
+
|
280 |
+
embed = Embed(color=Color.red())
|
281 |
+
embed.set_author(name=f"{after} ID: {after.id}", icon_url=after.avatar.url if after.avatar else bot.user.avatar.url)
|
282 |
+
embed.title = "Role Removed"
|
283 |
+
embed.add_field(name="User", value=after.mention, inline=True)
|
284 |
+
embed.add_field(name="Role", value=role.name, inline=True)
|
285 |
+
embed.add_field(name="Removed By", value=moderator.mention if isinstance(moderator, discord.Member) else "Unknown", inline=True)
|
286 |
+
embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
|
287 |
+
await bot.log_channel.send(embed=embed)
|
288 |
|
289 |
except Exception as e:
|
290 |
print(f"on_member_update Error: {e}")
|