TypeError:无法读取未定义的不和谐机器人的属性'发送'

问题描述 投票:1回答:1

有人知道如何解决此问题吗?

    client.channels.get(config.logChannel).send(embed)
                                          ^

TypeError: Cannot read property 'send' of undefined
    at Client.client.once (/home/fynn/DiscordTickets/server.js:119:43)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at Client.emit (events.js:208:7)
    at WebSocketConnection.triggerReady (/home/fynn/DiscordTickets/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:128:17)
    at WebSocketConnection.checkIfReady (/home/fynn/DiscordTickets/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:144:61)
    at ReadyHandler.handle (/home/fynn/DiscordTickets/node_modules/discord.js/src/client/websocket/packets/handlers/Ready.js:80:8)
    at WebSocketPacketManager.handle (/home/fynn/DiscordTickets/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:108:65)
    at WebSocketConnection.onPacket (/home/fynn/DiscordTickets/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:336:35)
    at WebSocketConnection.onMessage (/home/fynn/DiscordTickets/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:299:17)

公共源代码:https://github.com/eartharoid/DiscordTickets

      .setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
      .setColor("#2ECC71")
      .setDescription(":white_check_mark: **Started succesfully**")
      .setFooter(`DiscordTickets by Eartharoid`);
    client.channels.get(config.logChannel).send(embed)
  } else {
    client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
  } ```
javascript typeerror discord send
1个回答
0
投票

您确定漫游器可以访问该频道吗?这是因为,如果客户端看不到频道,它将为您提供未定义的返回

您确定配置中通道的ID是字符串吗?discord.js在Snowflake方法中需要一个ChannelManager.get()

也许尝试用它代替.get()

client.channels.fetch(config.logChannel)

这是ChannelManager附带的一种方法,据我所知,它基本上与Discord集合上的.get()方法完全相同。

对不起,我的英语不太好,我竭尽所能地回答您的问题并提供一些解释! 😅

© www.soinside.com 2019 - 2024. All rights reserved.