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