Liam
Liam
DIAdiscord.js - Imagine an app
Created by Liam on 9/9/2024 in #djs-questions
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.
9 replies