Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.72k stars 459 forks source link

oldest_first=True in the audit logs returns newest_first #2304

Closed champymarty closed 3 months ago

champymarty commented 9 months ago

Summary

When trying to get oldest_first, it returns newest firsts

Reproduction Steps

I am trying to get the oldest_first in the audit logs:

                async for entry in guild.audit_logs(limit=None, after=object_id,
                                                    oldest_first=True, action=discord.AuditLogAction.member_role_update):
                    print(f'{entry.created_at}')

But it is returning the most recent first ...

2023-12-28 19:49:21.731000+00:00
2023-12-28 19:49:18.526000+00:00
2023-12-28 19:49:14.620000+00:00
2023-12-28 19:49:11.040000+00:00

Minimal Reproducible Code

async for entry in guild.audit_logs(limit=None, after=object_id,
                                                    oldest_first=True, action=discord.AuditLogAction.member_role_update):
                    print(f'{entry.created_at}')

Expected Results

2023-12-28 19:49:11.040000+00:00
2023-12-28 19:49:14.620000+00:00
2023-12-28 19:49:18.526000+00:00
2023-12-28 19:49:21.731000+00:00

Actual Results

2023-12-28 19:49:21.731000+00:00
2023-12-28 19:49:18.526000+00:00
2023-12-28 19:49:14.620000+00:00
2023-12-28 19:49:11.040000+00:00

Intents

moderation, members, guilds

System Information

Checklist

Additional Context

No response

champymarty commented 9 months ago

In the mean time I just did:

entries = await guild.audit_logs(limit=None, after=object_id,
                                    oldest_first=True, action=discord.AuditLogAction.member_role_update).flatten()
entries.sort(key=lambda val: val.created_at)
NeloBlivion commented 8 months ago

Might be a breaking change because oldest_first doesn't exist on the API, will follow spec instead

Lulalaby commented 8 months ago

Approved, do it

champymarty commented 7 months ago

There is also a problem where the audit_log will fetch so much more logs than required. This is cause when there is more than 100 logs to fetch, the iterator does not execute the logs in the right orders. It can only appear when more than 100 logs, becuase the iterator fetch logs in batch of max 100. For exemple there is 134 logs to fetch but it will fetch 3600 logs... That can be a big problem for performance and rate limits.

I put more details when I prosented the problem in the help server: https://discord.com/channels/881207955029110855/1132206148309749830/1208967662663897108