"Send" does not exist on type "channel"
Hi.
Trying to make a discord bot that will send a message to a specific channel on startup. I try the method of caching the channel and then sending the message. An error is thrown saying "Send" does not exist on type "channel".
Any thoughts why?
Solution:Jump to solution
Solution(For Future People trying to solve this issue)
```ts
const channel = await client.channels.fetch("1076251641625456700");
if(channel?.isTextBased() ) {...
22 Replies
Channel might net be a text based channel. Use channel.isTextBased() to ensure that it is before trying to send a message
it is
You may know that it is but the code doesnt. You still need to preform the check in the code.
Two things. First, remove the casting to a
TextChannel
because you cant be sure its a text channel. Second, channel
is not a TextChannel
, its undefined
.yes
so how do I make it not undefined
and make it send a message?
Well, are you sure that the id your using is correct? If so, it probably is not cached so you will need to fetch it with
client.channels.fetch(...)
yes that worked
alrighty
thank you very much.
np
Solution
Solution(For Future People trying to solve this issue)
Fetch the channel, make sure it is text based.
Wrong solution, see <#769862166131245066> in the DiscordJS server. Use
isStageChannel
function from @sapphire/discord.js-utilities and update to the latest sapphire framework as announced in #Announcements
Specifically !isStageChannel(channel)
oop. I didn't see the djs anouncment. But why would you use
isStageChannel
instead of isTextBased
? Wouldnt !isStageChannel(channel)
return true for categries & voice channels?You can send messages in VC
Right I forgot they had text channels now. But you still cant send messages in a category channel
Also I dont think
.send
exists on forum channels but I could be wrong about thatFavna could answer
because stage channels are also text channels so
isTextChannel
doesn't exclude stage channel
stage channels can have messages now
as of like last week or so
which is why the change was made to discord-api-types to begin withSo stage channels can now have text channels once djs updates to support it but checking
!isStageChannel
still assumes that you can send a message to a category which I'm pretty sure you cant.stage channels can now have messages and therefore they are text channels because the definition of a text channel is "can have messages"
Right so then why would you check if a channel is not a stage channel before sending a message to it then?
because at least for now DJS doesnt support sending a message to a stage channel
until an update rolls out
anyway yes you should do
for now
Right so you would need to do that check in addition to the isTextBased. If you just did the stage check then you could end up sending to a category
Yep
I thought you were saying to just do the stage check, not both.