26
26
/**
27
27
* Represents the connection used for direct messaging.
28
28
*
29
+ * <p>This channel may communicate with different users in interactions triggered by user-installed apps:
30
+ * <ul>
31
+ * <li>In bot DMs, this channel will send messages to {@link net.dv8tion.jda.api.JDA#getSelfUser() this bot}.</li>
32
+ * <li>In friend DMs, this channel will send messages to that friend,
33
+ * from the bot itself, this is different from where the interaction was executed.
34
+ * <br>Note: As friend DMs are detached channels, you will need to {@linkplain #retrieveOpenPrivateChannel() retrieve an open channel first}.
35
+ * </li>
36
+ * </ul>
37
+ *
29
38
* @see User#openPrivateChannel()
39
+ * @see #retrieveOpenPrivateChannel()
30
40
*/
31
41
public interface PrivateChannel extends MessageChannel
32
42
{
@@ -40,7 +50,6 @@ public interface PrivateChannel extends MessageChannel
40
50
* <li>A message is deleted</li>
41
51
* <li>This account sends a message to a user from another shard (not shard 0)</li>
42
52
* <li>This account receives an interaction response, happens when using an user-installed interaction</li>
43
- * <li>This channel represents a DM channel between friends, happens when using an user-installed interaction</li>
44
53
* </ul>
45
54
* The consequence of this is that for any message this bot receives from a guild or from other users, the user will not be null.
46
55
*
@@ -64,6 +73,27 @@ public interface PrivateChannel extends MessageChannel
64
73
@ CheckReturnValue
65
74
RestAction <User > retrieveUser ();
66
75
76
+ /**
77
+ * Retrieves a {@link PrivateChannel} that is guaranteed to be open.
78
+ * <br>For detached {@link PrivateChannel PrivateChannels},
79
+ * it essentially transforms this into an attached {@link PrivateChannel}.
80
+ *
81
+ * <p>This is only useful for interactions started in Friend DMs (with user-installed apps),
82
+ * as this will return a valid channel to communicate between your bot and the friend,
83
+ * not between the interaction's caller and the friend.
84
+ *
85
+ * <p><b>Note:</b> Open private channels does not imply you can successfully send messages to the recipient.
86
+ *
87
+ * @throws net.dv8tion.jda.api.exceptions.DetachedEntityException
88
+ * If this channel is detached and {@link #getUser()} returns {@code null},
89
+ * this only happens if Discord does not send us the recipient, which should not happen.
90
+ *
91
+ * @return A {@link RestAction} to retrieve an open {@link PrivateChannel}.
92
+ */
93
+ @ Nonnull
94
+ @ CheckReturnValue
95
+ RestAction <PrivateChannel > retrieveOpenPrivateChannel ();
96
+
67
97
/**
68
98
* The human-readable name of this channel.
69
99
*
0 commit comments