Message collector not working

I'm configuring my bot so that it will respond to the slash command /validate by creating a new thread and asking the user to post their email. This is my the function that is called when the slash command is invoked.
async function threadSetup(interaction) {
const thread = await interaction.channel.threads.create({
name: `Welcome, ${interaction.user.username}!`,
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
type: ChannelType.PrivateThread,
reason: "Welcome to the Server!",
});

await thread.join();
await thread.members.add(interaction.user.id);
await thread.send("Please post your email in this thread.");

interaction.reply("I've created a thread for validation. You can open it from the sidebar!");

const collector = thread.createMessageCollector({ max: 1, time: 3600000 });

collector.on("collect", (m) => {
console.log("For debugging");
const emails = fs.readFileSync(EMAILS_PATH);
if (emails.includes(m.content)) m.reply("Identified");
else m.reply("Not identified");
collector.stop();
});
}
async function threadSetup(interaction) {
const thread = await interaction.channel.threads.create({
name: `Welcome, ${interaction.user.username}!`,
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
type: ChannelType.PrivateThread,
reason: "Welcome to the Server!",
});

await thread.join();
await thread.members.add(interaction.user.id);
await thread.send("Please post your email in this thread.");

interaction.reply("I've created a thread for validation. You can open it from the sidebar!");

const collector = thread.createMessageCollector({ max: 1, time: 3600000 });

collector.on("collect", (m) => {
console.log("For debugging");
const emails = fs.readFileSync(EMAILS_PATH);
if (emails.includes(m.content)) m.reply("Identified");
else m.reply("Not identified");
collector.stop();
});
}
The thread is successfully created, but the message collector just won't work. It doesn't return any errors anything, but it doesn't respond to any messages in the channel. The "For debugging" console.log is not printed. I don't know what I'm doing wrong here, any advice would be appreciated.
7 Replies
d.js toolkit
d.js toolkit4mo 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
treble/luna
treble/luna4mo ago
do you have the Guilds, GuildMessages and MessageContent intent
Liam
LiamOP4mo ago
I just double checked and it does
lupus
lupus4mo ago
Just to make sure, try to create a messageCreate event handler and see if that catches the message.
Liam
LiamOP4mo ago
an event handler for this isn't working either, so I guess it is an issue with it reading messages? I have it added as an administrator, and all the guild intents enabled, so I don't know why it wouldn't be able to read messages For reference this is the event handler I made:
client.on(Events.MessageCreate, (message) => {
// Neither of these work
console.log("HERE!!");
message.channel.send('Hello there!');
});
client.on(Events.MessageCreate, (message) => {
// Neither of these work
console.log("HERE!!");
message.channel.send('Hello there!');
});
No description
No description
treble/luna
treble/luna4mo ago
and where are the intents in your client constructor
Liam
LiamOP4mo ago
this was it, I wasn't listing the intents in the client constructor thank you guys for your help
Want results from more Discord servers?
Add your server