I’ve been following CodeLyon’s tutorial on how to make an economy system for a discord bot and usually have managed to get things working. However, the MessageCollector has been giving me issues and I don’t know what exactly the error means. Am I missing something before the createMessageCollector?
const profileModel = require("../models/profileSchema");
module.exports = {
name: "search",
aliases: [],
permissions: [],
description: "Search for some coin!",
async execute(message, args, cmd, client, discord, profileData) {
const locations = [
"car",
"bathroom",
"park",
"truck",
"pocket",
"computer"
];
const chosenLocations = locations.sort(() => Math.random() - Math.random()).slice(0, 3);
const filter = ({ author, content }) => message.author == author && chosenLocations.some((location) => location.toLowerCase() == content.toLowerCase());
const collector = message.channel.createMessageCollector({ filter, time: 15000 });
const earnings = Math.floor(Math.random() * (1000 - 100 + 1)) + 100;
collector.on('collect', async (m) => {
message.channel.send(`You found ${earnings} coins!`);
await profileModel.findOneAndUpdate(
{
userID: message.author.id,
},
{
$inc: {
reputation: earnings,
},
}
);
});
collector.on('end', (collected, reason) => {
if (reason == "time") {
message.channel.send('You ran out of time!');
}
});
message.channel.send(`<@${message.author.id}> Which location would you like to search?n Type the location in this channeln `${chosenLocations.join('` `')}``);
}
}
I’m going to be honest, I’m not very familiar with Javascript. This bot is mostly for fun.