【问题标题】:How to attach the file url?如何附加文件网址?
【发布时间】:2018-11-30 02:06:28
【问题描述】:

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

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 (internal/process/next_tick.js:188:7) 名称:'DiscordAPIError', message: '不能发送空消息', 路径:'/api/v7/channels/447351755043373056/messages', 代码:50006 }

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    尝试将其设为新的 Discord 附件。

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

    Example of it working

    【讨论】:

    • request(options, (error, response, body) => { client.channels.get("447351755043373056").send(This weeks's brawl is, { file: https://raw.githubusercontent.com/idaspin/DiscordAmITojpsBot/master/api/brawl.png }); })这段代码也有效,但我试图把 ${body} 变量。这是我的结果:Screenshot
    • Discord 无法获取原始 JSON/XML 文件,尝试 console.log(body) 并查看它是否是 JSON/XML 对象,如果是,则从中获取所需数据并发送.抱歉,我误解了您原来的问题。
    • 正文等于“http://..../brawl.jpg”screenshot
    猜你喜欢
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多