Skip to content

Instantly share code, notes, and snippets.

@lazuee
Created June 27, 2022 14:43
Show Gist options
  • Save lazuee/f8bea4c51c2c418aea1526293916777f to your computer and use it in GitHub Desktop.
Save lazuee/f8bea4c51c2c418aea1526293916777f to your computer and use it in GitHub Desktop.
discord collect messages
const startCollector = async (message, limit) => {
const filter = (m) => m.author.id === message.author.id;
const collector = await message.channel.awaitMessages({
filter,
max: 1,
time: 30000,
});
if (!collector.size)
return {
message: false,
error: "stop",
attachment: false,
};
if (collector.first().content.toLowerCase() === "stop") {
return {
message: collector.first().content,
error: "stop",
attachment: false,
};
}
if (collector.first().content.toLowerCase() === "skip") {
return {
message: collector.first().content,
error: "skip",
attachment: false,
};
}
if (limit && collector.first().content.length > limit)
return {
message: collector.first().content,
error: `Exceeded ${limit} characters`,
};
return {
message: collector.first().content,
error: false,
attachment:
collector.first().attachments.size > 0
? collector.first().attachments.first().url
: false,
};
};
module.exports = { startCollector };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment