Skip to content

Auto reply when receiving a DM #46

Answered by rigwild
Fluffaro asked this question in Q&A
Discussion options

You must be logged in to vote
{
  // AFK message
  const afkMessage = 'Hi, I am currently AFK. I will reply to your message as soon as I am back.'

  // Init - Store all recent DMs IDs
  const seenDMs = new Set()
  let DMs = await api.getDMs()
  DMs.forEach(DM => seenDMs.add(DM.last_message_id))

  // Check every 10 seconds for new DMs
  var loop = true
  while (loop) {
    DMs = await api.getDMs()
    DMs = DMs.filter(DM => !seenDMs.has(DM.last_message_id))
    // Reply to each new DMs, wait 1s between each
    for (const DM of DMs) {
      seenDMs.add(DM.last_message_id)
      console.log(`New DM from ${DM.recipients[0].username}#${DM.recipients[0].discriminator} (${DM.recipients[0].id})`)
      const sentMessage = a…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Fluffaro
Comment options

@DeadLyBro
Comment options

Comment options

You must be logged in to vote
1 reply
@Fluffaro
Comment options

Answer selected by Fluffaro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants