I am trying to get my Etherscan Verified Contract Scraper that forwards new Verified Contracts to a specific Discord channel working and have run into issues.
Here is the code--
const Discord = require("discord.js");
const fetch = require("node-fetch");
const config = require("./config.json");
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// Replace CHANNEL_ID with the ID of the channel you want to post in
const channel = client.channels.cache.get('CHANNELID');
// Scrape new verified contracts from Etherscan every minute
setInterval(async () => {
const response = await fetch('https://etherscan.io/contractsVerified');
const html = await response.text();
// Extract the verified contracts from the HTML
const verifiedContracts = html.match(/href="\/address\/[0-9a-fA-F]+"/g)
.map((link) => link.slice(8, -1));
// Send an embedded message to the Discord channel with the verified contracts
const embed = new Discord.MessageEmbed()
.setTitle('Verified Contracts')
.setDescription(verifiedContracts.join('\n'))
.setColor('#00FF00');
channel.send(embed);
}, 60000);
client.login(config.BOT_TOKEN);
Here is the error I'm getting--
TypeError: Cannot read properties of null (reading 'map')
at Timeout._onTimeout (/root/project1/index.js:27:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Any help would be greatly appreciated. Thank you!