The typing for Discord.Channel appears to be missing the .send attribute. The following snippet fails when compiling TypeScript with the following error: "Property 'send' does not exist on type 'Channel'"
When a //@ts-ignore is added before the line, the behaviour works as expected.
this.discord.on('message', (msg: Discord.Message) => {
if (msg.member?.user.tag === this.discord.user?.tag) {
return
}
this.discord.channels.resolve(msg.channel.id ?? '')?.send('test?')
})
(context: this.discord is an initialised and logged in Discord.Client object)
Further details:
Priority this issue should have – please be realistic and elaborate if possible: Low
[ ] I have also tested the issue on latest master, commit hash:
no, the typing is not missing.
<Client>.channels is a manager for all types of channels the client has cached (general type Channel), send is only available on a subset of them (Text- News- and DMChannels), if you are sure what you retrieve is a text based channel you can type assert after retrieving it (as ids are unique this is usually the case).
Gotcha, thanks for the clarification! Closed. 👍
Just a little addition:
You can just use message.channel instead of this.discord.channels.resolve(msg.channel.id ?? ''), and it will already be * implements TextBasedChannel, so the typing would exist anyway.
Most helpful comment
Just a little addition:
You can just use
message.channelinstead ofthis.discord.channels.resolve(msg.channel.id ?? ''), and it will already be* implements TextBasedChannel, so the typing would exist anyway.