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.");
}
}
};
18 Replies
d.js toolkit
d.js toolkit2mo 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! - Marked as resolved by OP
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
[email protected] v22.8.0
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
😢 thank you
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction],
});
So im assuming this should now work
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
Hmm, still nothing, even with the intents and partials update 🤔 ive moved them over to my veriy.js also.. but im not passing client anywhere in the file... guessing thats my issue ?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
hmm, im confused to why this isnt working then the collector starts and ends without issue, but doesnt actually collect
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
got a few other commands using it;
No description
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
command handler is using the message partal;
// Command handler
client.on('messageCreate', message => {
if (!message.content.startsWith(cfg.prefix) || message.author.bot) return;

const args = message.content.slice(cfg.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();

const command = commands.get(commandName);
if (!command) return;

command.execute(message, args);
});
// Command handler
client.on('messageCreate', message => {
if (!message.content.startsWith(cfg.prefix) || message.author.bot) return;

const args = message.content.slice(cfg.prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();

const command = commands.get(commandName);
if (!command) return;

command.execute(message, args);
});
code is saved and console is logging collector started and collected ended, but nothing in between
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
yep... you are correct, ive deleted that partial and collectors are now working ive been sat here for 2 hours with this lol T_T
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Ben
BenOP2mo ago
thank you so much
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server