Java 如何将图片发送到Discord频道
我需要将图片(截图)发送到Discord频道。我已经成功开发了文本发送到频道,但我不知道如何发送屏幕 以下是我的部分代码:Java 如何将图片发送到Discord频道,java,discord,discord-jda,Java,Discord,Discord Jda,我需要将图片(截图)发送到Discord频道。我已经成功开发了文本发送到频道,但我不知道如何发送屏幕 以下是我的部分代码: // connection to the Channel TextChannel channel = api.getTextChannelById(this.channelId); if (channel != null) { channel.sendMessage(pMessage).queue(); } // c
// connection to the Channel
TextChannel channel = api.getTextChannelById(this.channelId);
if (channel != null) {
channel.sendMessage(pMessage).queue();
}
// capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
// Save as JPEG - not necessary
File file = new File("screencapture.jpg");
ImageIO.write(screencapture, "jpg", file);
// CODE for sendPicture (screencapture to the Channel) HERE!!!
// code here
// code here
知道怎么做吗?根据,要将文件发送到频道,应使用相应的sendFile重新启动操作
您可以使用一系列不同的发送方法,其中一些方法允许您随文件发送消息
例如,要使用文件对象发送文件,请执行以下操作:
channel.sendFile(new File("path/to/file")).queue();
或者,直接使用InputStream(在您的情况下,是为了避免写入磁盘)
根据,要将文件发送到频道,应使用相应的sendFile重新启动操作
您可以使用一系列不同的发送方法,其中一些方法允许您随文件发送消息
例如,要使用文件对象发送文件,请执行以下操作:
channel.sendFile(new File("path/to/file")).queue();
或者,直接使用InputStream(在您的情况下,是为了避免写入磁盘)