Message.channel type does not seem to have send and sendTyping in v14
My particular bot build is a typescipt build. The transpiler (and my edtior) indicate that the channel object in the Message type no longer has send and sendTyping. How are they meant to be used now? Is there a type to replace Message or something?
I have tried to find any relevant info on this in the version to version migration guides and other posts here, but all I can figure out is the functions still seem to exist on the object and should work, but obviously typescript wont compile it if types dont allow it.
My flow:
- MessageCreate event callback calls messageHandler
- message handler function has a parameter called message with type Message (imported from djs obviously)
- handler does message.channel.sendTyping, does whatever data fetches for the message action and then message.channel.send the result
node v22.3.0
djs 14.16.3
11 Replies
- 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!A) the Message class never had those methods, they're on channels
B) use the isSendable guard to narrow the channel types
I did mention it previously worked. So I'm not sure if we talking about the same Message class in terms of what it did or didnt have. I will lok into this sendle thing tho.
I mean, your message suggests you're using message.channel.send and such, I just want to clarify that the channel is different than the message
Because things like message.reply do exist to send a message as a reply
Is that implying you cant send a message to the source channel of the Message event anymore?
That's not what I said
There is a difference between message.send (which doesn't exist) and message.channel.send (which does exist)
My compile errors show im using the one that exists. Typescript says that one doesnt.
That's why I told you to use the guard
Use the isSendable()
type guard. Messages can originate from partial group DM channels because of user-installable applications and you can't send messages there, hence the need for the type guard
the guard the a boolean function right? And somehow a boolean can resolve a variable type for ts to comple in this instance?
its a typeguard
it narrows the type
Thanks. I got it working. Never done these before, legit thought it was a djs concept cause I dont do much advanced typescript techniues