Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting error in Message methods for permission checks #1921

Closed
3 tasks done
MinnDevelopment opened this issue Nov 30, 2021 · 1 comment
Closed
3 tasks done

Casting error in Message methods for permission checks #1921

MinnDevelopment opened this issue Nov 30, 2021 · 1 comment
Labels
bug level: novice is doable as a java/jda novice status: completed has been completed but is not yet released

Comments

@MinnDevelopment
Copy link
Member

General Troubleshooting

  • I have checked for similar issues.
  • I have updated to the latest JDA version.
  • I have checked the branches or the maintainers' PRs for upcoming bug fixes.

Bug Report

Calling Message#delete on a message in a thread, causes a casting error.

Expected Behavior

No error.

Code Example or Reproduction Steps

public void onMessageReceived(MessageReceivedEvent event) {
  if (event.getChannelType().isThread()) {
    event.getMessage().delete(); // throws 
  }
}

Code for JDABuilder or DefaultShardManagerBuilder Used

N/A

Exception or Error

java.lang.ClassCastException: class net.dv8tion.jda.internal.entities.ThreadChannelImpl cannot be cast to class net.dv8tion.jda.api.entities.IPermissionContainer (net.dv8tion.jda.internal.entities.ThreadChannelImpl and net.dv8tion.jda.api.entities.IPermissionContainer are in unnamed module of loader 'app')
	at net.dv8tion.jda.internal.entities.ReceivedMessage.delete(ReceivedMessage.java:922)
	at FooKt$main$$inlined$listener$1.onEvent(events.kt:348)
	at dev.minn.jda.ktx.CoroutineEventManager$handle$1.invokeSuspend(CoroutineEventManager.kt:41)
@Codixer
Copy link

Codixer commented Dec 1, 2021

I can confirm this bug in my own bot.
https://gitlab.com/pinewood-builders/discord/xeus/-/blob/feature/jda-5/src/main/java/com/pinewoodbuilders/handlers/adapter/MessageEventAdapter.java#L304

When trying to delete a message from a thread, it can't. And throws an error missing that casting. Maybe use the IPermissionContainer from the channel the thread is from?

@MinnDevelopment MinnDevelopment added level: novice is doable as a java/jda novice up for grabs labels Dec 1, 2021
@DV8FromTheWorld DV8FromTheWorld added the status: in progress already in the process of being implemented label Dec 2, 2021
@MinnDevelopment MinnDevelopment added status: completed has been completed but is not yet released and removed status: in progress already in the process of being implemented labels Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug level: novice is doable as a java/jda novice status: completed has been completed but is not yet released
Projects
None yet
Development

No branches or pull requests

3 participants