#Channel does not have send method.

8 messages · Page 1 of 1 (latest)

royal dome
#

Trying to just get my bot to send a message in a channel but .send is not a method on my channel variable.
Code (using DiscordX so thats whats up with the decorators) :

@Discord()
export class Send {
  @Slash({ name: 'send', description: 'send' })
  send(interaction: CommandInteraction): void {
    const channel = interaction.client.channels.cache.get(
      '1054999990310805586'
    );

    if (channel) channel.send('test 123');
//                         ^
//                         Property 'send' does not exist on type 'Channel'.
//                         Property 'send' does not exist on type 'CategoryChannel'.
  }
}
molten pewter
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

royal dome
#

i do know interaction.channel?.send() is a thing, but im wanting to get the channel id from an option later down the line

fathom river
#

You need to type it as a text channel

royal dome
#

ahh that makes sense. and then a branch off question since im not replying to the command is there a way to not have this happen?

fathom river
#

Reply

pine igloo
#

That's because Discord cann't assume that the channel is a textchannel. You should cast it to a text based channel.
If you take the channel that the interaction was sent in, it is a TextBasedChannel type https://discord.js.org/#/docs/discord.js/main/class/CommandInteraction?scrollTo=channel
You might want to take const channel = interaction.channel if that's your intention. If you take a fixed channel by ID (as you're currently doing), you need to cast it to a TextBasedChannel such as DMChannel or GuildTextBasedChannel.

fathom river
#

You have to acknowledge an interaction one way or a other