Ben
Ben
DIAdiscord.js - Imagine an app
Created by Ben on 9/28/2024 in #djs-questions
Message Collector help
Hey all, Im having some issues with message collectors in DM's.. i cant get the bot to actually collect anything at all when the user replies to the bot's dm? is it a code error or something else?
module.exports = {
name: 'verify',
description: 'Verify your order using your OrderID and email.',
adminOnly: false,
usage: 'verify',
cooldown: 60000,
async execute(message) {
// Create a DM channel
const dm = await message.author.createDM();

try {
// Send initial message in DM
await dm.send("Please say something!");

// Define a filter to only collect messages from the user
const filter = response => response.author.id === message.author.id;

// Create a message collector to listen for replies in DM
const collector = dm.createMessageCollector({ filter, max: 1, time: 60000 }); // Adjusted time to 60000 (1 minute)

console.log("Message collector started in DMs");

collector.on('collect', async (msg) => {
console.log(`Received message: ${msg.content}`); // Log received message
await dm.send(`You said: **${msg.content}**`);
});

collector.on('end', collected => {
if (collected.size === 0) {
console.log("No messages collected"); // Log if no messages were collected
dm.send("You didn't respond in time!");
} else {
console.log(`Collected ${collected.size} message(s)`); // Log number of collected messages
}
});
} catch (error) {
console.error("Error sending DM:", error);
await message.channel.send("I couldn't send you a DM. Please check your DM settings.");
}
}
};
module.exports = {
name: 'verify',
description: 'Verify your order using your OrderID and email.',
adminOnly: false,
usage: 'verify',
cooldown: 60000,
async execute(message) {
// Create a DM channel
const dm = await message.author.createDM();

try {
// Send initial message in DM
await dm.send("Please say something!");

// Define a filter to only collect messages from the user
const filter = response => response.author.id === message.author.id;

// Create a message collector to listen for replies in DM
const collector = dm.createMessageCollector({ filter, max: 1, time: 60000 }); // Adjusted time to 60000 (1 minute)

console.log("Message collector started in DMs");

collector.on('collect', async (msg) => {
console.log(`Received message: ${msg.content}`); // Log received message
await dm.send(`You said: **${msg.content}**`);
});

collector.on('end', collected => {
if (collected.size === 0) {
console.log("No messages collected"); // Log if no messages were collected
dm.send("You didn't respond in time!");
} else {
console.log(`Collected ${collected.size} message(s)`); // Log number of collected messages
}
});
} catch (error) {
console.error("Error sending DM:", error);
await message.channel.send("I couldn't send you a DM. Please check your DM settings.");
}
}
};
30 replies