2

I'm trying to do a bot to verify members on a special guild. They need to send "verify" into a specific channel, then they have to answer several questions. However, the collector doesn't seem to work properly. Nothing shows in console.

client.on('messageCreate', async message => {
    if(message.author.id === botId) return;

    if(message.channel.type != "dm") {
        if(message.channelId == verifyChannelId && message.content == "verify") {
            let appChannel = (await message.author.send('Hello, I\'m gonna asking you a few questions..')).channel;

            appChannel.send('Are you on european server? (Yes/No)');
        
            const filter = m => (appChannel.type === "dm");
            const collector = appChannel.createMessageCollector({ filter, time: 15000 });
        
            collector.on('collect', m => {
                console.log(`Collected ${m.content}`);
            });
        
            collector.on('end', collected => {
                console.log(`Collected ${collected.size} items`);
            });

            message.delete({ timeout: 1000 });
        } else {
            message.delete({ timeout: 1000 });
        }
    }
});
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
Dushy
  • 37
  • 7
  • 2
    Does this answer your question? [Checking if a message was sent from a DM not working. (Discord.js v12)](https://stackoverflow.com/questions/70002410/checking-if-a-message-was-sent-from-a-dm-not-working-discord-js-v12) – MrMythical Nov 21 '21 at 22:46
  • @MrMythical still not sadly – Dushy Nov 21 '21 at 22:52
  • 1
    Is the `DIRECT_MESSAGES` intent present in your `` instantiation? – Viriato Nov 22 '21 at 11:34

1 Answers1

2

There are a couple of errors with this. First, you're using v13 of discord.js and as MrMythical mentioned in their comment, channel types are now uppercase, so checking if(message.channel.type != "dm") won't do much as it will always return true. Checking if (appChannel.type === "dm") won't work either as it will always returns false. And I'm not even sure why you'd check if the appChannel's type is DM anyway, it can't be anything else. Your filter should probably check if the answer is yes or no.

Another error is that you haven't enabled the DIRECT_MESSAGES intents. Without it, your createMessageCollector won't work in DM channels. Check out the working code below:

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.DIRECT_MESSAGES,
  ],
});

// ...

client.on('messageCreate', async (message) => {
  // it could be if (message.author.bot) return;
  if (message.author.id === botId) return;
  if (message.channel.type === 'DM') return;
  if (message.channelId !== verifyChannelId) return;

  if (message.content.toLowerCase() === 'verify') {
    let sentMessage = await message.author.send(
      "Hello, I'm gonna asking you a few questions..",
    );
    let dmChannel = sentMessage.channel;

    dmChannel.send('Are you on a European server? (Yes/No)');

    const filter = (m) => ['yes', 'no'].includes(m.content.toLowerCase());
    const collector = dmChannel.createMessageCollector({
      filter,
      // max: 1,
      time: 15000,
    });

    collector.on('collect', (m) => {
      console.log(`Collected ${m.content}`);
    });

    collector.on('end', (collected) => {
      console.log(`Collected ${collected.size} items`);
    });
  }

  // delete the message even if it wasn't "verify"
  message.delete({ timeout: 1000 });
});
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57