discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.33k stars 736 forks source link

event.getTarget().getMember() returns null in onMessageContextInteraction #2615

Closed AveCard1nal closed 8 months ago

AveCard1nal commented 8 months ago

General Troubleshooting

Version of JDA

5.0.0-beta.20

Expected Behaviour

Hello. Encountered an error in the onMessageContextInteraction event. When attempting to retrieve the author of the message (event.getTarget().getMember()), it returns null (called for a message in the Guild). However, the method works correctly if the author of the message is the same user that triggers the onMessageContextInteraction event.

Code Example for Reproduction Steps

@Override
    public void onMessageContextInteraction(MessageContextInteractionEvent event) {
        System.out.println(event.getTarget().getMember()); //null
    }

Code for JDABuilder or DefaultShardManagerBuilder used

this.jda = JDABuilder.createDefault(BOT_TOKEN).enableIntents(GatewayIntent.GUILD_MEMBERS).build();

Exception or Error

No response

freya022 commented 8 months ago

On messages from context message commands, Message#getMember is not null if the member is cached.

You can either enable the cache with MemberCachePolicy and ChunkingFilter, or, retrieve the member with Guild#retrieveMember and passing Message#getAuthor to it

AveCard1nal commented 8 months ago

Guild#retrieveMember has worked. Thank you!