I’m trying to check message.content against a JSON and an API link that is fetched and stored to the const data
for a automod bot.
The JSON and API link both contain arrays with 600+ items stored.
The idea is to check against a locally stored JSON, and then an API to prevent links being posted.
The code works fine for 90% of the time, but while testing and sending multiple links in a short space of time, i get this error:
TypeError: data.some is not a function
This is the code:
client.on('messageCreate', async (message) => {
try {
const guild = client.guilds.cache.get(message.guildId);
const member = guild.members.cache.get(message.author.id);
const modLogs = client.channels.cache.get(modLogsChannelID);
const response = await fetch(
definedAPI,
);
const data = await response.json();
if (badLinksJSON.some(letter => message.content.includes(letter))) {
console.log(`${member.user.tag} used a bad link and has been muted.`)
member.roles.add(mutedRoleID).catch(err => console.error);
message.channel.send(`${message.author.toString()} You have been muted for: **Bad Link Usage**`).catch(console.error).then(message.delete()).catch(err => console.error);
} else if (data.some(word => message.content.includes(word))) {
console.log(`${member.user.tag} used a bad link and has been muted.`)
member.roles.add(mutedRoleID).catch(err => console.error);
message.channel.send(`${message.author.toString()} You have been muted for: **Bad Link Usage**`).catch(console.error).then(message.delete()).catch(err => console.error);
}
} catch (error) {
message.channel.send('Oops, there was an error fetching the API');
console.log(error);
}
}
Note: > Multiple variables are defined in the code file above, I have not included them in the code snippet
The try and catch were added to prevent the bot from crashing if this error occured. I am aware it could be done other ways.
Any help is appreciated, TIA.