K
Kordā€¢2y ago
matytyma

Responses to messages

3 things I'd like to: 1. Check if the message is a response 2. Get the message this message responds to 3. (Optionally) get the same but from a message that is a response to a MessageContextMenuCommand
65 Replies
matytyma
matytymaOPā€¢2y ago
I have tried to search for interfaces to cast to, but no result...
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
SchlaubiBus
SchlaubiBusā€¢2y ago
ig not sure either tbh
matytyma
matytymaOPā€¢2y ago
Yeah šŸ˜… Thanks! This is exactly what I wanted for the first two, what about the MessageContextMenuCommand? Is it even possible?
SchlaubiBus
SchlaubiBusā€¢2y ago
That should give you the same Message Object
matytyma
matytymaOPā€¢2y ago
Tried it, but the referencedMessage property was null šŸ˜„
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Haven't worked with rest yet šŸ˜„, but will try it!
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Doesn't work with rest either, it's not taken as a reply imo. Also, good to mention, the response was ephemeral
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
ofc Response for message context-menu command:
interaction.respondEphemeral {
embed {
title = "Confirm Report"
description = "Do you really want to report this message for violating the ${Channels.RULES}?"
color = EmbedColor.DANGER
}
actionRow {
interactionButton(ButtonStyle.Danger, "report-confirm") {
emoji(Emojis.warning.toReaction())
label = "Report"
}
}
}
interaction.respondEphemeral {
embed {
title = "Confirm Report"
description = "Do you really want to report this message for violating the ${Channels.RULES}?"
color = EmbedColor.DANGER
}
actionRow {
interactionButton(ButtonStyle.Danger, "report-confirm") {
emoji(Emojis.warning.toReaction())
label = "Report"
}
}
}
report-confirm button
interaction.respondPublic {
embed {
title = "Message Reported"
color = EmbedColor.DANGER
description =
"This message has been reported for violating our ${Channels.RULES}, if you agree click on the button"
field {
name = "Message content"
value = interaction.message.referencedMessage!!.content // Here the NPE occurs :D
}
field {
name = "Times already reported"
value = "5"
}
}
actionRow {
interactionButton(ButtonStyle.Danger, "report-add") {
emoji(Emojis.warning.toReaction())
label = "Report"
}
}
}
interaction.respondPublic {
embed {
title = "Message Reported"
color = EmbedColor.DANGER
description =
"This message has been reported for violating our ${Channels.RULES}, if you agree click on the button"
field {
name = "Message content"
value = interaction.message.referencedMessage!!.content // Here the NPE occurs :D
}
field {
name = "Times already reported"
value = "5"
}
}
actionRow {
interactionButton(ButtonStyle.Danger, "report-add") {
emoji(Emojis.warning.toReaction())
label = "Report"
}
}
}
Tell me if something in the code could be improved, I'm new to Kotlin (coming from Java šŸ¤¢)
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
What's the issue? Message#referencedMessage is always null when getting it from a message that is a response to message context-menu command interaction. I think I should be able to get the interaction interaction data from the message data, but can't figure out how šŸ˜„
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Won't work either šŸ˜„
No description
matytyma
matytymaOPā€¢2y ago
Gotta try with rest in a second
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
ā¬†ļø
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Yea, I have it enabled
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Yeah
matytyma
matytymaOPā€¢2y ago
No description
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Nope, gotta do it in a sec, if you'd like to see more of my code, I can show you ofc
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Error:
[DefaultDispatcher-worker-4] ERROR dev.kord.core.Kord - catching(java.lang.NullPointerException)
java.lang.NullPointerException
at dev.matytyma.nightlybot.component.ReportConfirmButton.execute(ReportConfirmButton.kt:27)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$2.invokeSuspend(Bot.kt:69)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$2.invoke(Bot.kt)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$2.invoke(Bot.kt)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$$inlined$on$default$2$1.invokeSuspend(Kord.kt:631)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
[DefaultDispatcher-worker-4] ERROR dev.kord.core.Kord - catching(java.lang.NullPointerException)
java.lang.NullPointerException
at dev.matytyma.nightlybot.component.ReportConfirmButton.execute(ReportConfirmButton.kt:27)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$2.invokeSuspend(Bot.kt:69)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$2.invoke(Bot.kt)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$2.invoke(Bot.kt)
at dev.matytyma.nightlybot.Bot$Companion$registerComponents$$inlined$on$default$2$1.invokeSuspend(Kord.kt:631)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
line 27 of ReportConfirmButton:
println(interaction.message.withStrategy(EntitySupplyStrategy.rest).messageReference!!)
println(interaction.message.withStrategy(EntitySupplyStrategy.rest).messageReference!!)
matytyma
matytymaOPā€¢2y ago
If you'd like the deepest logging level or a video, tell me
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
println(interaction.message.channel.getMessage(interaction.message.id).withStrategy(EntitySupplyStrategy.rest).data)
println(interaction.message.channel.getMessage(interaction.message.id).withStrategy(EntitySupplyStrategy.rest).data)
results with both messageReference and referencedMessage missing
No description
matytyma
matytymaOPā€¢2y ago
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
I'm not replying to a message? I'm trying to get the message a message context menu action was used on
matytyma
matytymaOPā€¢2y ago
No description
matytyma
matytymaOPā€¢2y ago
Bottom is the response for context menu action used on the top one And I'm trying to access the content of the top one from an interaction on the button from the bottom one (The bottom one is now public, so there won't be any problems with ephemeral if there could be)
matytyma
matytymaOPā€¢2y ago
That number is hunting me XD
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
well, yeah ā¬†ļø
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Heh? šŸ˜„ I'm responding to button interaction with a new message
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
No in my opinion
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
wait a sec
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
matytyma
matytymaOPā€¢2y ago
@Deleted User
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
If it won't be possible, I think I have an easy workaround
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
yeah but the first response should be ephemeral, while the second public (if it's even possible)
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Message#interaction doesn't return an instance of Interaction, but Message.Interaction šŸ«¤ I've already tried using that šŸ˜”
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
np Discovered anything?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
yea
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
Yzp, works well now
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
matytyma
matytymaOPā€¢2y ago
The only bad about this is that that the entries will be stored until cleaned up if the user won't confirm it, right? As if it's not possible to get the message directly from the interactions, I'll most likely store the message already in the first embed šŸ˜„
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server