Skip to content

Commit

Permalink
Add overloads for message reference
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Oct 4, 2024
1 parent c436937 commit 3104809
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/dv8tion/jda/api/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ default MessageCreateAction forwardTo(@Nonnull MessageChannel channel)
if (channel instanceof MessageChannelMixin)
((MessageChannelMixin<?>) channel).checkCanSendMessage();
return new MessageCreateActionImpl(channel)
.setMessageReference(MessageReference.MessageReferenceType.FORWARD, getGuildId(), getChannelId(), getId());
.setMessageReference(MessageReference.MessageReferenceType.FORWARD, this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,112 @@ static void setDefaultFailOnInvalidReply(boolean fail)
* @param type
* The type of message reference
* @param guildId
* The guild id the forwarded message comes from
* The guild id the forwarded message comes from, or null if it is not from a guild
* @param channelId
* The channel id the forwarded message comes from
* @param messageId
* The target message id
*
* @throws IllegalArgumentException
* If null or an invalid snowflake is passed
* If null or an invalid snowflake is passed or the reference type is {@link MessageReferenceType#UNKNOWN}
*
* @return The same instance for chaining
*/
@Nonnull
MessageCreateAction setMessageReference(@Nonnull MessageReferenceType type, @Nullable String guildId, @Nonnull String channelId, @Nonnull String messageId);

/**
* Message reference used for a reply or forwarded message.
*
* <p><b>{@link MessageReferenceType#DEFAULT Default Type}</b>
*
* <p>You can only reply to messages from the same channel.
* By default, this will mention the author of the target message, this can be disabled using {@link #mentionRepliedUser(boolean)}.
*
* <p>This also requires {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY} in the channel.
* If this permission is missing, you receive {@link net.dv8tion.jda.api.requests.ErrorResponse#REPLY_FAILED_MISSING_MESSAGE_HISTORY_PERM ErrorResponse.REPLY_FAILED_MISSING_MESSAGE_HISTORY_PERM}.
*
* <p>If the target message does not exist, this will result in {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE ErrorResponse.UNKNOWN_MESSAGE}.
* You can use {@link #failOnInvalidReply(boolean)} to allow unknown or deleted messages.
*
* <p><b>{@link MessageReferenceType#FORWARD Forward Type}</b>
*
* <p>Creates a snapshot of the referenced message at the current time and sends it in this channel.
*
* <p>You cannot forward messages from channels you do not have access to.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} from forwarding include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#REFERENCED_MESSSAGE_NOT_FOUND REFERENCED_MESSSAGE_NOT_FOUND}
* <br>If the provided reference cannot be resolved to a message</li>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#FORWARD_CANNOT_HAVE_CONTENT FORWARD_CANNOT_HAVE_CONTENT}
* <br>If additional content is sent alongside a forwarded message</li>
* </ul>
*
* @param type
* The type of message reference
* @param guildId
* The guild id the forwarded message comes from, or 0 if it is not from a guild
* @param channelId
* The channel id the forwarded message comes from
* @param messageId
* The target message id
*
* @throws IllegalArgumentException
* If the reference type is null or {@link MessageReferenceType#UNKNOWN}
*
* @return The same instance for chaining
*/
@Nonnull
default MessageCreateAction setMessageReference(@Nonnull MessageReferenceType type, long guildId, long channelId, long messageId)
{
return setMessageReference(type, Long.toUnsignedString(guildId), Long.toUnsignedString(channelId), Long.toUnsignedString(messageId));
}

/**
* Message reference used for a reply or forwarded message.
*
* <p><b>{@link MessageReferenceType#DEFAULT Default Type}</b>
*
* <p>You can only reply to messages from the same channel.
* By default, this will mention the author of the target message, this can be disabled using {@link #mentionRepliedUser(boolean)}.
*
* <p>This also requires {@link net.dv8tion.jda.api.Permission#MESSAGE_HISTORY Permission.MESSAGE_HISTORY} in the channel.
* If this permission is missing, you receive {@link net.dv8tion.jda.api.requests.ErrorResponse#REPLY_FAILED_MISSING_MESSAGE_HISTORY_PERM ErrorResponse.REPLY_FAILED_MISSING_MESSAGE_HISTORY_PERM}.
*
* <p>If the target message does not exist, this will result in {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE ErrorResponse.UNKNOWN_MESSAGE}.
* You can use {@link #failOnInvalidReply(boolean)} to allow unknown or deleted messages.
*
* <p><b>{@link MessageReferenceType#FORWARD Forward Type}</b>
*
* <p>Creates a snapshot of the referenced message at the current time and sends it in this channel.
*
* <p>You cannot forward messages from channels you do not have access to.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} from forwarding include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#REFERENCED_MESSSAGE_NOT_FOUND REFERENCED_MESSSAGE_NOT_FOUND}
* <br>If the provided reference cannot be resolved to a message</li>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#FORWARD_CANNOT_HAVE_CONTENT FORWARD_CANNOT_HAVE_CONTENT}
* <br>If additional content is sent alongside a forwarded message</li>
* </ul>
*
* @param type
* The type of message reference
* @param message
* The target message
*
* @throws IllegalArgumentException
* If null is provided or the reference type is {@link MessageReferenceType#UNKNOWN}
*
* @return The same instance for chaining
*/
@Nonnull
default MessageCreateAction setMessageReference(@Nonnull MessageReferenceType type, @Nonnull Message message)
{
return setMessageReference(type, message.getGuildId(), message.getChannel().getId(), message.getId());
}

/**
* Message reference used for a reply.
* <br>The client will show this message as a reply to the target message.
Expand Down

0 comments on commit 3104809

Please sign in to comment.