How to send a message to a channel?

I've copied the code from the FAQ verbatim:
const channel = client.channels.cache.get('id');
channel?.send('content');
const channel = client.channels.cache.get('id');
channel?.send('content');
but typescript complains that send doesn't exist on channel (note that I've handled the possible nullish value already). I checked the Channel type and it indeed doesn't have send. What am I doing wrong?
No description
9 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
chewie
chewie12mo ago
Use the proper typeguard
addamsson
addamsson12mo ago
which is?
d.js docs
d.js docs12mo ago
method DMChannel#isTextBased() Indicates whether this channel is TextBasedChannels text-based.
addamsson
addamsson12mo ago
isTextBased?
chewie
chewie12mo ago
yes
addamsson
addamsson12mo ago
damn sorry 😅
chewie
chewie12mo ago
that would narrow down the type to voice, text channels and announcement channels
addamsson
addamsson12mo ago
got it 👍 i've been using guards with Interaction, I dunno why I forgot it with Channel
Want results from more Discord servers?
Add your server