I have my own Discord BOT based on JDA. I need to send a text message to the specific channel. I know how to send the message as onEvent response, but in my situation I do n
You need only one thing to make this happen, that is an instance of JDA. This can be retrieved from most entities like User/Guild/Channel and every Event instance. With that you can use JDA.getTextChannelById to retrieve the TextChannel instance for sending your message.
class MyClass {
private final JDA api;
private final long channelId;
private final String content;
public MyClass(JDA api) {
this.api = api;
}
public void doThing() {
TextChannel channel = api.getTextChannelById(this.channelId);
if (channel != null) {
channel.sendMessage(this.content).queue();
}
}
}
If you don't have a JDA instance you would have to manually do an HTTP request to send the message, for this lookup the discord documentation or jda source code. The JDA source code might be a little too complicated to take as an example as its more abstract to allow using any endpoint.