is there a good way to respond to user dm once
Say a user dms my bot. I would like to respond to the user a specified message, if met the conditions:
If the specified message is different from the last message
If the last message does not exist
15 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!Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
I see.
What if the message content has like new lines and other special characters. Would such still be comparable well?
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
Ah okay.
Wait but.
If I need to filter for the first message from the bot, how would I do that?
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
Ah
is this proper
ima test rq
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
The new specified message
Oops
That was a string
Don't I need firstMessage.content
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
You don't need the MessageContent intents (here)
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
thanks, i got it to work
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
You could use a MessageCollector which has the capability to filter events (for example certain userId or certain value) and limit the amount of messages that will be captured to one for example.
I think you have to listen on the "messageCreate" Event beforehand and create a MessageCollector after you received a message.
You have to limit the lifespan of the MessageCollectorby supplying one of the option keys:
- time: Amount of time in milliseconds the collector should run for
- max: Number of messages to successfully pass the filter
- maxProcessed: Number of messages encountered (no matter the filter result)
Just as an Idea (might be bad practice :D)
If you wanna know more about MessageCollectors read the Guide:
https://discordjs.guide/popular-topics/collectors.html#basic-message-collector
You can find a good list on when to use which Interaction Handling here:
https://discordjs.guide/message-components/interactions.html#component-interactions