Bot不发送标签| Discord.js

时间:2020-10-30 11:43:35

标签: javascript discord.js embed message

嘿,我制作了一个监听频道的机器人,当该频道中发送了一条消息时,该机器人用嵌入了该消息内容的消息替换了该消息,但是当有人试图给某人标记该机器人时,我遇到了一些问题打印此

(node:16552) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.image.url: Could not interpret "[]" as string.
    at RequestHandler.execute
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

当我添加附件时,它仅发送测试!最后,我想将作者图像设置为与发送消息的用户相同...

这是我的代码:

bot.on('message', message=>{
    
    if (message.author.bot) return;
    if(message.channel.id == "771695635598278677") {
        message.delete()
        const user = message.mentions.users.first() || message.author;
        //let messageAttachment = message.attachments.size > 0 ? message.attachments.array()[0].url : null
        const dark = new Discord.MessageEmbed()
        .setColor('#000000')
        .setDescription(`${message.content}\n`)
        .addField('\n')
        .setAuthor("Twitter")
        .setImage(message.attachments)
        .setFooter('twitter', 'https://cdn.discordapp.com/attachments/564032243836780558/771614643159433226/Anonymous_emblem.svg.png')
        if(isNaN(message.content)) {
            message.channel.send(twitter)
        }
    }
});

如果有人可以帮助我,请告诉我...谢谢!

1 个答案:

答案 0 :(得分:0)

Message.attachments返回附件的 Collection ,而MessageEmbed.setImage()需要一个字符串(URL)。我相信您正在寻找的是Collection.prototype.first(),它将返回集合中的第一个MessageAttachment。从那里,您可以访问url属性。

-- Searching for ICU 58.2
CMake Warning (dev) at deps/meta-cmake/FindOrBuildICU.cmake:31 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable ICU_ROOT is set to:

    /usr/local/opt/icu4c

  For compatibility, CMake is ignoring the variable.
Call Stack (most recent call first):
  CMakeLists.txt:55 (FindOrBuildICU)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found ICU: /usr/local/opt/icu4c/lib/libicudata.dylib;/usr/local/opt/icu4c/lib/libicui18n.dylib;/usr/local/opt/icu4c/lib/libicuuc.dylib (Required is at least version "58.2") 
-- ICU version found is 67.1.0, expected 58.2; attempting to build ICU from scratch...
-- ICU include dirs: /Users/yuenfannie/meta/build/deps/icu-58.2/include
-- ICU libraries: icui18n;icuuc;icudata
-- Locating libc++...
-- Located libc++: /usr/lib/libc++.dylib
-- Located libc++ include path: /Library/Developer/CommandLineTools/usr/include/c++/v1/
--     Locating libc++'s abi...
--     Found libc++abi: /usr/lib/libc++abi.dylib
-- Using jemalloc: /usr/local/lib/libjemalloc.dylib
CMake Error at deps/meta-cmake/kludges/AlignedAlloc.cmake:54 (message):
  Failed to find a suitable aligned allocation routine
Call Stack (most recent call first):
  deps/meta-cmake/CompilerKludges.cmake:18 (include)
  CMakeLists.txt:120 (CompilerKludges)


-- Configuring incomplete, errors occurred!
See also "/Users/yuenfannie/meta/build/CMakeFiles/CMakeOutput.log".
See also "/Users/yuenfannie/meta/build/CMakeFiles/CMakeError.log".