discord4j.rest.entity.RestMessage Maven / Gradle / Ivy
/*
* This file is part of Discord4J.
*
* Discord4J is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Discord4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Discord4J. If not, see .
*/
package discord4j.rest.entity;
import discord4j.common.annotations.Experimental;
import discord4j.discordjson.json.MessageData;
import discord4j.discordjson.json.MessageEditRequest;
import discord4j.rest.RestClient;
import discord4j.rest.util.Snowflake;
import reactor.core.publisher.Mono;
import reactor.util.annotation.Nullable;
/**
* Represents a message within Discord.
*/
public class RestMessage {
private final RestClient restClient;
private final long channelId;
private final long id;
private RestMessage(RestClient restClient, long channelId, long id) {
this.restClient = restClient;
this.channelId = channelId;
this.id = id;
}
/**
* Create a {@link RestMessage} with the given parameters.
*
* @param restClient REST API resources
* @param channelId the ID of the channel this messages belongs to
* @param id the ID of this message
*/
public static RestMessage create(RestClient restClient, Snowflake channelId, Snowflake id) {
return new RestMessage(restClient, channelId.asLong(), id.asLong());
}
/**
* Create a {@link RestMessage} with the given parameters.
*
* @param restClient REST API resources
* @param channelId the ID of the channel this messages belongs to
* @param id the ID of this message
*/
public static RestMessage create(RestClient restClient, long channelId, long id) {
return new RestMessage(restClient, channelId, id);
}
public RestChannel channel() {
return RestChannel.create(restClient, channelId);
}
/**
* Retrieve this messages' data upon subscription.
*
* @return a {@link Mono} where, upon successful completion, emits the {@link MessageData} belonging to this
* channel. If an error is received, it is emitted through the {@code Mono}.
* @see Get Message
*/
public Mono getData() {
return restClient.getChannelService().getMessage(channelId, id);
}
/**
* Requests to add a reaction on this message.
*
* @param emoji The reaction to add on this message. emoji takes the form of name:id for custom guild emoji, or
* Unicode characters.
* @return A {@link Mono} where, upon successful completion, emits nothing; indicating the reaction was added on
* this message. If an error is received, it is emitted through the {@code Mono}.
* @see Create Reaction
*/
public Mono createReaction(String emoji) {
return restClient.getChannelService().createReaction(channelId, id, emoji);
}
/**
* Requests to remove a reaction from the current user on this message.
*
* @param emoji The reaction to remove on this message.
* @return A {@link Mono} where, upon successful completion, emits nothing; indicating the reaction from the current
* user was removed on this message. If an error is received, it is emitted through the {@code Mono}.
* @see
* Delete Own Reaction
*/
public Mono deleteOwnReaction(String emoji) {
return restClient.getChannelService().deleteOwnReaction(channelId, id, emoji);
}
/**
* Requests to remove a reaction from a specified user on this message.
*
* @param emoji The reaction to remove on this message.
* @param userId The user to remove the reaction on this message.
* @return A {@link Mono} where, upon successful completion, emits nothing; indicating the reaction from the
* specified user was removed on this message. If an error is received, it is emitted through the {@code Mono}.
* @see
* Delete User Reaction
*/
public Mono deleteUserReaction(String emoji, long userId) {
return restClient.getChannelService().deleteReaction(channelId, id, emoji, userId);
}
/**
* Requests to remove all the reactions on this message.
*
* @return A {@link Mono} where, upon successful completion, emits nothing; indicating all the reactions on this
* message were removed. If an error is received, it is emitted through the {@code Mono}.
* @see
* Delete All Reactions
*/
public Mono deleteAllReactions() {
return restClient.getChannelService().deleteAllReactions(channelId, id);
}
// TODO: add Delete All Reactions for Emoji route/restService/rest method/core method
/**
* Requests to edit this message.
*
* @param request The request body used to create a new message.
* @return A {@link Mono} where, upon successful completion, emits the edited {@link MessageData}. If an error is
* received, it is emitted through the {@code Mono}.
* @see Edit Message
*/
public Mono edit(MessageEditRequest request) {
return restClient.getChannelService().editMessage(channelId, id, request);
}
/**
* Requests to delete this message while optionally specifying a reason.
*
* @param reason The reason, if present.
* @return A {@link Mono} where, upon successful completion, emits nothing; indicating the message has been deleted.
* If an error is received, it is emitted through the {@code Mono}.
* @see Delete Message
*/
public Mono delete(@Nullable String reason) {
return restClient.getChannelService().deleteMessage(channelId, id, reason);
}
/**
* Requests to publish (crosspost) this message if the {@code channel} is of type 'news'.
*
* @return A {@link Mono} where, upon successful completion, emits nothing; indicating the message was published
* (crossposted) in the guilds. If an error is received, it is emitted through the {@code Mono}.
*/
@Experimental
public Mono publish() {
return restClient.getChannelService().publishMessage(channelId, id);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy