如何附加文件网址?

时间:2018-06-20 20:40:01

标签: javascript discord.js

我正在尝试发送图像从网络获取的图像

var now = new Date();
if (now.getDay() == 3 && now.getUTCHours() == 20) {
    var options = {
        method: "GET",
        url: `https://raw.githubusercontent.com/idaspin/DiscordAmITojpsBot/master/api/brawl_lnk.txt`,
        headers: {
            'User-Agent': 'nodejs request',
            'X-Key': "9qpRc8M55pFb8qDN94jH"
        }
    }
    client.channels.get("447351755043373056").send("", {
        file: "https://raw.githubusercontent.com/idaspin/DiscordAmITojpsBot/master/api/brawl.png" 
    }).then(() => {
        request(options, (error, response, body) => { // body equals "http://.../brawl.png" here
            if (!error && response.statusCode == 200) {
                client.channels.get("447351755043373056").send(`This weeks's brawl is`, {
                    file: `${body}`
                }).catch((err) => console.log(err));
            }
        })
    });
}

但是它(文件:${body})没有发送任何内容。当我将带有url的字符串放入文件变量中时:

    file: `https://something.../brawl.png`

有效。 作为错误,我收到此消息:

  

{DiscordAPIError:无法发送空消息       在item.request.gen.end(C:\ Users \ aspan \ Documents \ AmITojps \ node_modules \ discord.js \ src \ client \ rest \ RequestHandlers \ Sequential.js:71:65)       那时(C:\ Users \ aspan \ Documents \ AmITojps \ node_modules \ snekfetch \ src \ index.js:215:21)       在       在process._tickCallback(内部/进程/next_tick.js:188:7)     名称:“ DiscordAPIError”,     消息:“无法发送空消息”,     路径:'/ api / v7 / channels / 447351755043373056 / messages',     代码:50006}

1 个答案:

答案 0 :(得分:0)

尝试将其添加为新的Discord附件。

<channel>.send(new Discord.Attachment("https://raw.githubusercontent.com/idaspin/DiscordAmITojpsBot/master/api/brawl.png"));

Example of it working