admin管理员组

文章数量:1300110

I need to check if the account is new when interacting with the bot.

I was able to get information about the time the user joined the guild, but this information is not enough.

member.getJoinTime();

I tried to get the user object, but I didn't find any suitable methods.

I need to check if the account is new when interacting with the bot.

I was able to get information about the time the user joined the guild, but this information is not enough.

member.getJoinTime();

I tried to get the user object, but I didn't find any suitable methods.

Share Improve this question asked Feb 11 at 14:38 Евгений ШабарчинЕвгений Шабарчин 131 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

in discord every ID ( like for users, messages, etc.) has a unique number that stores the exact time it was created. in Discord4J, you can get that timestamp like this::

Member member = ...; 
Snowflake id = member.getId(); 
Instant creationTime = id.getTimestamp(); 
OffsetDateTime readableTime = creationTime.atOffset(ZoneOffset.UTC); 

Done! This will show you when the user's account was created,

like: 2023-10-01T12:34:56Z.

Discord uses snowflakes for IDs that contain information about the timestamp meaning the timestamp of the ID can be extracted from anything that has an ID.

In Discord4j, you can use User#getId to get the ID from the member as a Snowflake object. You can then use the Snowflake#getTimestamp method to convert it to an Instant representing the timestamp.

Member member = ...;
Instant accountCreationTimestamp = member.getId().getTimestamp();
OffsetDateTime accountCreationDateTime = accountCreationTimestamp.atOffset(ZoneOffset.UTC);

本文标签: javaHow to get member account creation dateStack Overflow