I’m working on my first Discord bot and running into an issue. When someone sends a direct message with !process followed by a URL, my bot keeps responding multiple times instead of just once. The command seems to trigger repeatedly even though the user only sent it once.
client.on('message', message => {
if (message.content.startsWith("!process")) {
var parts = message.content.split(" ");
if (parts[1] != undefined) {
var link = parts[1];
if (link.includes("youtube.com")) {
var execSync = require('child_process').execSync;
var randomNum = Math.floor((Math.random() * 999999999) + 1);
var command = 'youtube-dl ' + link + ' -o ' + randomNum + '.mp4';
var settings = {
encoding: 'utf8'
}
var outputFile = randomNum + '.mp4';
console.log(execSync(command, settings));
message.reply({ files: [outputFile] });
}
}
}
});
Any ideas why this duplicate response issue happens?