Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将图片发送到Discord频道_Java_Discord_Discord Jda - Fatal编程技术网

Java 如何将图片发送到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

我需要将图片(截图)发送到Discord频道。我已经成功开发了文本发送到频道,但我不知道如何发送屏幕

以下是我的部分代码:

// 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(在您的情况下,是为了避免写入磁盘)