"Send" does not exist on type "channel"

Cchpsterz2/18/2023
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".
const channel = client.channels.cache.get('1076251641625456700');
channel.send("Hi");
const channel = client.channels.cache.get('1076251641625456700');
channel.send("Hi");
Any thoughts why?
Solution:
Solution(For Future People trying to solve this issue) ```ts const channel = await client.channels.fetch("1076251641625456700"); if(channel?.isTextBased() ) {...
Jump to solution
BBen2/18/2023
Channel might net be a text based channel. Use channel.isTextBased() to ensure that it is before trying to send a message
Cchpsterz2/18/2023
it is
BBen2/18/2023
You may know that it is but the code doesnt. You still need to preform the check in the code.
Cchpsterz2/18/2023
Cchpsterz2/18/2023
BBen2/18/2023
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.
Cchpsterz2/18/2023
yes so how do I make it not undefined and make it send a message?
BBen2/18/2023
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(...)
Cchpsterz2/18/2023
yes that worked alrighty thank you very much.
BBen2/18/2023
np
Solution
Cchpsterz2/18/2023
Solution(For Future People trying to solve this issue)
const channel = await client.channels.fetch("1076251641625456700");
if(channel?.isTextBased() ) {
channel.send("Hello World!")
}
const channel = await client.channels.fetch("1076251641625456700");
if(channel?.isTextBased() ) {
channel.send("Hello World!")
}
Fetch the channel, make sure it is text based.
FFavna2/18/2023
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)
BBen2/18/2023
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?
KKrish2/18/2023
You can send messages in VC
BBen2/18/2023
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 that
KKrish2/18/2023
Favna could answer
FFavna2/18/2023
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 with
BBen2/18/2023
So 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.
FFavna2/18/2023
stage channels can now have messages and therefore they are text channels because the definition of a text channel is "can have messages"
BBen2/18/2023
Right so then why would you check if a channel is not a stage channel before sending a message to it then?
FFavna2/18/2023
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
if (!isTextChannel(channel) || isStageChannel(channel) {
return;
}

// do other stuff
if (!isTextChannel(channel) || isStageChannel(channel) {
return;
}

// do other stuff
for now
BBen2/18/2023
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.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
How can I create a listener for @discordjs/voice states?Title kinda explains itself lol, but how can I convert things like ```javascript const { VoiceConnecHow to delete interaction buttons?Hello@sapphire/shapeshift (?) crashes bot when trying to send embed with description exceeding 4096 charshi, so I have a message cmd which shows info on a github user in a nice embed. when bot sends the inuninstlling @sapphireHow do i uninstall this so that it stops loading as a dependency. I've run ```npm uninstall @sapphManual task not executingHiya, One of the tasks for a temp ban doesn't seem to execute after the amount of time I specified Registering commands and other pathsHi guys! I'm having some troubles. When I use `sapphire new`, everything works as intended. The comIs it possible to update slash command string options every time the command is ran?This command acquires data from Firebase and use it as string choices. However, data from Firebase its-node giving issues with Sapphire (edit: DO NOT USE TS-NODE)Undefined ?Why i get undefined ```js client.on('ready', () => { console.log(`Logged in as ${client.user.tscheduled jobs randomly stop workingHello! I have three different scheduled jobs at different intervals. 1 minute 10 minutes 2 minutes shardinghey so i want to use discord hybrid sharding i wanted to ask if there will be issues with using it wRegister command in only specific guildsHow do I register a slash command in only the guilds I want specified?port 4000 on clusterso my bot is in more than 8k servers and it requires clustering so when i start the bot i get this How to defer reply with SapphirejsYes I know, Sapphire doesn't have this feature built-in, so I was wondering how to do it without it?How can i add all itents```js const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intenDefault preconditionsI'd like to create a check for **all commands** before they are run, and I'd like an alternative to Commands not responding to defaultPrefixI've setup the `defaultPrefix` to `"!"`: ``` const client: SapphireClient = new SapphireClient({ ts not compiling wellI don't know if it's a discord.js/sapphire issue or just a compiling issue, but when compiling normaHow To Use The Enum Arg?Hello, I'm trying to use the enum arg in order to accept only one of two strings. How does one pass Let's users have custom folders for piecesAs the title states, I think sapphire should let people place commands, listeners and interaction ha