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

canTalk returns true for private thread without permission #2602

Closed Alf-Melmac closed 9 months ago

Alf-Melmac commented 10 months ago

General Troubleshooting

Version of JDA

5.0.0-beta.19

Expected Behaviour

JDA should check if the bot is member of a private thread.

I'm consuming a slash command interaction from a private thread that the bot is not a member of. Before sending a (non ephemeral) message i check the permission with event.getChannel().canTalk(). The ThreadChannelImpl only checks in the parent channel if the bot member has the permission to view the channel and can send messages but doesn't check if the member is allowed to send messages in this specific thread.

Code Example for Reproduction Steps

Discord setup: Create a private thread in a public channel.

public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
    System.out.println(event.getChannel().canTalk()); // This returns true for private threads, but should be false
}

Code for JDABuilder or DefaultShardManagerBuilder used

JDABuilder.createDefault("token").addEventListeners(new InteractionListener()).build();

Exception or Error

No response

MinnDevelopment commented 10 months ago

If you use the interaction hook, you can send messages without permissions. The right way to handle interactions is to send all your messages through that hook instead.

Alf-Melmac commented 10 months ago

Thanks for the hint and the fix :). This isn't my production setup, but it is the easiest way to reproduce the problem. I'll keep that in mind.