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
d.js toolkit
d.js toolkitβ€’13mo 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!
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
flxckn
flxcknβ€’13mo ago
I see. What if the message content has like new lines and other special characters. Would such still be comparable well?
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
flxckn
flxcknβ€’13mo ago
Ah okay. Wait but. If I need to filter for the first message from the bot, how would I do that?
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
flxckn
flxcknβ€’13mo ago
Ah
const messages = await message.channel.messages.fetch({ limit: 100 })
const firstMessage = messages.filter(message => message.author.id == NewClient.user.id).first()

if (firstMessage === data.DMMessage) return;
const messages = await message.channel.messages.fetch({ limit: 100 })
const firstMessage = messages.filter(message => message.author.id == NewClient.user.id).first()

if (firstMessage === data.DMMessage) return;
is this proper ima test rq
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
flxckn
flxcknβ€’13mo ago
The new specified message Oops That was a string Don't I need firstMessage.content
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
πŸŒΊπŸ‡«πŸ‡· Shigu :3 🌺
You don't need the MessageContent intents (here)
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
flxckn
flxcknβ€’13mo ago
thanks, i got it to work
Unknown User
Unknown Userβ€’13mo ago
Message Not Public
Sign In & Join Server To View
Sim3Xx
Sim3Xxβ€’13mo ago
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
Want results from more Discord servers?
Add your server