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 toolkit15mo 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
chewie15mo ago
Use the proper typeguard
addamsson
addamssonOP15mo ago
which is?
d.js docs
d.js docs15mo ago
method DMChannel#isTextBased() Indicates whether this channel is TextBasedChannels text-based.
addamsson
addamssonOP15mo ago
isTextBased?
chewie
chewie15mo ago
yes
addamsson
addamssonOP15mo ago
damn sorry 😅
chewie
chewie15mo ago
that would narrow down the type to voice, text channels and announcement channels
addamsson
addamssonOP15mo 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