Discord JS“发送”未定义

时间:2018-07-18 02:26:40

标签: javascript node.js discord discord.js

Discord JavaScript一直存在问题,当您尝试调用“ channels.get”时,导致“发送”变得不确定。下面提供的代码! (代码)

try{
    message.channels.get(`name`, `mod-logs`).send({embed: {
        "color" 4886754,
        "author": {
            "name": "Command Ran",
            "icon_url": message.author.avatarURL
         },
         "fields": [
             {
                "name": `Initiated by user: ${message.author.username}#${message.author.discriminator}`,
                 "value": "**Command Status**: Successful :heavy_check_mark:\n**Mod Status**: Successful :heavy_check_mark:",
                 "inline": true
             },
             {
                 "name": `Uptime:`,
                 "value": `${client.uptime / 1000}`,
                 "inline" true
              }
          ]

(控制台)

TypeError: Cannot read property 'send' of undefined
at Object.exports.run (C:\Users\Warriorfoox\Desktop\DiscordBot\Paralyss\commands\uptime.js:22:51)
at Client.client.on.message (C:\Users\Warriorfoox\Desktop\DiscordBot\Paralyss\index.js:21:19)
at emitOne (events.js:116:13)
at Client.emit (events.js:211:7)
at MessageCreateHandler.handle (C:\Users\Warriorfoox\Desktop\DiscordBot\Paralyss\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketConnection.onPacket (C:\Users\Warriorfoox\Desktop\DiscordBot\Paralyss\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\Warriorfoox\Desktop\DiscordBot\Paralyss\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\Warriorfoox\Desktop\DiscordBot\Paralyss\node_modules\ws\lib\event-target.js:120:16)
at emitOne (events.js:116:13)

2 个答案:

答案 0 :(得分:2)

df1 <- structure(list(county = c("A", "A", "A", "B", "B"), event_start = c(3L, 
12L, 71L, 1L, 19L), event_end = c(6L, 20L, 80L, 3L, 30L)), .Names = c("county", 
"event_start", "event_end"), class = "data.frame", row.names = c(NA, 
-5L))

是错误的。尝试找到公会并找到它。

message.channels.get(`name`, `mod-logs`)

答案 1 :(得分:0)

您的问题出在message.channels.get('name', 'CHANNEL NAME')

您可以使用message.client.channels.get('CHANNEL ID'),也可以使用频道名称message.guild.channels.find('name', 'CHANNEL NAME')来获取它。

如果它是另一个公会中的频道,则可以使用类似 client.user.guilds.get('GUILD ID').channels.find('name', 'CHANNEL NAME');

您可以在discord.js.org

上找到完整的文档。