How to send file with message to Discord with JDA?

Viewed 10942

I am using JDA lib to create my discord bot and I encountered a problem: in order to send message with a file, I should use existing message:

RestAction<Message> sendFile(File file, Message message)
RestAction<Message> sendFile(File file, String fileName, Message message)
RestAction<Message> sendFile(InputStream data, String fileName, Message message)

There is no implementation for sending file with simple string message. So when I'm trying to send file and pass a message to it I've got duplicated message.

So the question is: How to create Message with attached file without duplicating the message?

3 Answers

You can send messages with attached files in one go like this:

//channel is a MessageChannel object or similar
channel.sendMessage("message").addFile(new File("path/to/file")).queue();
Related