'Discord.js: MessageCollector, messages doesn't trigger collect event
I'm trying to code a giveaway bot in discord.js, it is the first time that I code in Javascript so if you have any recommendations I would be happy to hear them !
I am trying to launch a giveaway on a specific channel, the channel is usually locked for @everyone, when the giveaway starts, I open the channel and start listening for inputs.
I would like to listen for every messages, check if it is a correct ethereum wallet, if it is, gather it, if it is not, delete the message from the channel.
I wanted to use a createMessageCollector without any filter, and manually check everything. However, messages doesn't trigger the collect event..
Here is the code:
async function launch_giveaway(interaction) {
const giveawayChannel = interaction.options.getChannel("in");
const giveawayName = interaction.options.getString("name");
const numWinner = interaction.options.getInteger("num_winners");
const hours = interaction.options.getInteger("hours");
const minutes = interaction.options.getInteger("minutes");
const channelWinner = interaction.options.getChannel("winner_channel")
let endTime = Math.round(Date.now()/1000) + hours*3600 + minutes*60;
await interaction.reply(`Starting the giveaway of **${giveawayName}** in ${giveawayChannel} for ${hours}:${minutes}, I will put the ${numWinner} winners in ${channelWinner} !`);
await open_giveaway(interaction, giveawayChannel, giveawayName, numWinner, endTime, channelWinner)
await interaction.followUp(`Done ! ${giveawayChannel} is now open and members can send there wallets !`);
setTimeout(close_channel, hours*3600000 + minutes*60000, interaction, giveawayChannel, channelWinner, giveawayName);
let wallets = [];
const filter = m => {return true;};
const collector = giveawayChannel.createMessageCollector({ filter, time: 15000 });
collector.on('collect', m => {
console.log("someone typed in #giveaway");
// check ethereum wallet regex etc
// add to wallets list
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} wallets`);
});
}
I even tested with the default code from this tutorial, but it doesn't log anything on my console.
Thank you very much for your help,
Chronoxx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
