I wanted some help on the rss-parser, So I wanted to make the command send the message to the channel only once, but at a certain time it keeps Re reposting the same thing every time and I am not able to resolve this.
(async function main() {
// Make a new RSS Parser
const parser = new Parser();
// Get all the items in the RSS feed
const feed = await parser.parseURL("https://imaginescan.com.br/feed"); // https://www.reddit.com/.rss
let items = [];
// Clean up the string and replace reserved characters
const fileName = `${feed.title.replace(/\s+/g, "-").replace(/[/\\?%*:|"<>]/g, '').toLowerCase()}.json`;
if (fs.existsSync(fileName)) {
items = require(`./${fileName}`);
}
// Add the items to the items array
await Promise.all(feed.items.map(async (currentItem) => {
// Add a new item if it doesn't already exist
if (items.filter((item) => isEquivalent(item, currentItem)).length <= 0) {
items.push(currentItem);
}
}));
// Save the file
fs.writeFileSync(fileName, JSON.stringify(items));
feed.items.reverse().forEach(async (item) => {
const channel = client.channels.cache.get('980990991865626634');
let embed = new Discord.MessageEmbed()
.setTitle("New Cap")
.setDescription(item.title)
.setColor("PURPLE")
.setImage()
channel.send(embed)
})
})();
function isEquivalent(a, b) {
// Create arrays of property names
let aProps = Object.getOwnPropertyNames(a);
let bProps = Object.getOwnPropertyNames(b);
// if number of properties is different, objects are not equivalent
if (aProps.length != bProps.length) {
return false;
}
for (let i = 0; i < aProps.length; i++) {
let propName = aProps[i];
// if values of same property are not equal, objects are not equivalent
if (a[propName] !== b[propName]) {
return false;
}
}
// if we made it this far, objects are considered equivalent
return true;
}
I'm new to this, so I wanted some help with this problem.