繁体   English   中英

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

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

所以,正如我在文档中看到的,我可以调用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
    })

在控制台中,我得到了正确的频道名称(Squad 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

所以,这是一个愚蠢的错误。 我正在复制语音通用频道( General )的ID而不是文本通用频道( #general )。

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

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

特别感谢@slothiful

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM