向 Discord 频道发送消息(channel.send 不是函数)

Send message to Discord channel (channel.send is not a function)

因此,正如我在 documentation 中看到的那样,我可以调用 tc.send("foo"); 但它在我的代码中不起作用:

    client.on('ready', () => {
       var tc = client.guilds.get('547536528533094401').channels.get('547537490651774987')
       console.log(tc.name) // Squad 1
       tc.send('foo') // tc.send us not a function
    })

在控制台中,我获得了正确的频道名称(小队 1),但我也获得了

TypeError: tc.send is not a function

我想这不是铸造问题,因为

client.guilds.get('547536528533094401').channels.get('547537490651774987').send('foo')

也不行。

当我做的时候console.log(Object.getOwnPropertyNames(client.guilds.get('577240924162359312').channels.get('577240924162359321')))

我得到:

[
  'client',
  'type',
  'deleted',
  'id',
  'name',
  'position',
  'parentID',
  'permissionOverwrites',
  'bitrate',
  'userLimit',
  'guild',
  'members'
]

我正在使用 discord.js@11.5.0

所以,这是一个愚蠢的错误。我正在复制 voice 通用频道 (General) 而不是 text 通用频道 (#general) .

因此,当尝试访问 TextChannel.send() 方法时,它没有找到任何方法,因为它是 VoiceChannel。 (两者都扩展了 GuildChannel,后者又扩展了 Channel)。

我仍然想知道为什么 tc.type 返回对象而不是 GuildChannel,因为我不是很喜欢 javascript 的弱类型,但至少现在它可以工作了。

特别感谢@slothiful