0
votes

I am creating a Discord bot that sends private welcome messages to users that enter my server.

My Discord bot private message screen

I want to execute some lines of code (I want to add different roles to the users) which differ if the user reacts with those three emojis.
Online I found guides that refer to channel messages only and I don't understand which approach to use with private messages.
Thank you!

1

1 Answers

0
votes

The approach for private messages should be the same as channel messages.

// Create a reaction filter that only will collect those three emojis
const filter = (reaction, user) => ['🇮🇹', '🇬🇧', '🤫'].includes(reaction.emoji.name)

// Create reaction collector (message is the message the bot sent).
// The time is the time in milliseconds that the collector should run for
// (i.e. how long the user has to react).
const collector = message.createReactionCollector(filter, {time: 15000})

// Fired when the user reacts
collector.on('collect', (reaction, user) => {
  switch (reaction.name) {
    case '🇮🇹':
      message.reply('you chose Italian!'(
      break
    case '🇬🇧':
      message.reply('you chose English!')
      break
    case '🤫':
      message.reply('you have a secret code!')
  }
})

For more information see the Discord.js guide (archive). Note: The guide hasn't been fully updated to v12 so it says that the second parameter on the collector's collect event is the collector itself, like it was in v11.