blob: 856dab11e6d15cb7e33d41ddf805d727e0057a5c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package com.pinapelz;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
public class Retriever {
private final JDA jda;
public Retriever(JDA jda) {
this.jda = jda;
}
public String getFileUrl(String channelId, String messageId, String fileName) {
TextChannel channel = jda.getTextChannelById(channelId);
if (channel == null) {
throw new RuntimeException("Channel not found or deleted");
}
System.out.println(channelId + " " + messageId + fileName);
Message message = channel.retrieveMessageById(messageId).complete();
for (Message.Attachment file : message.getAttachments()) {
if (file.getFileName().equals(fileName)) {
return file.getProxyUrl();
}
}
throw new RuntimeException("Matching attachment not found");
}
}
|