Created
June 27, 2022 14:43
-
-
Save lazuee/f8bea4c51c2c418aea1526293916777f to your computer and use it in GitHub Desktop.
discord collect messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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