Discord.js: 'send' missing from Discord.Channel typing

Created on 14 Jun 2020  ·  3Comments  ·  Source: discordjs/discord.js

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:

  • discord.js version: 12.2.0
  • Node.js version: 12.13.0
  • Operating system: Windows 10 Home x64 (WSL Ubuntu 18.04.2 LTS)
  • Priority this issue should have – please be realistic and elaborate if possible: Low

  • [ ] I have also tested the issue on latest master, commit hash:

unverified bug

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dmitry221060 picture Dmitry221060  ·  3Comments

Acaretia picture Acaretia  ·  3Comments

shukriadams picture shukriadams  ·  3Comments

BrandonCookeDev picture BrandonCookeDev  ·  3Comments

Blumlaut picture Blumlaut  ·  3Comments