// The channel ID you want to monitor
const pollChannelId = '1292516925494267954';
// Check if the message is a poll ending message (adjust based on your poll ending format)
function isPollEndMessage(message) {
return message.content.includes("has closed"); // Customize this if necessary
}
client.on('messageCreate', async (message) => {
// Ignore messages from bots
if (message.author.bot) return;
// Only check messages from the specified channel
if (message.channel.id === pollChannelId) {
// If it's a poll, process as normal
if (message.poll) {
// Check if the poll has more than 5 options
if (message.poll.answers && message.poll.answers.size > 4) {
try {
// Delete the poll
await message.delete();
// Notify the user via DM
await message.author.send(`Your poll was deleted because it exceeded the limit of 4 answers.`);
} catch (error) {
console.error(`Error deleting poll or sending DM: ${error}`);
}
}
return; // End execution if the message is a valid poll
}
// If the message is the poll ending message, don't delete it
if (isPollEndMessage(message)) {
return; // Do nothing if it's the poll end message
}
// If it's not a poll or an ending message, delete the message
try {
await message.delete();
await message.author.send(`Your message was deleted because ${message.channel} is for polls only.`);
} catch (error) {
console.error(`Error deleting message or sending DM: ${error}`);
}
}
});
// The channel ID you want to monitor
const pollChannelId = '1292516925494267954';
// Check if the message is a poll ending message (adjust based on your poll ending format)
function isPollEndMessage(message) {
return message.content.includes("has closed"); // Customize this if necessary
}
client.on('messageCreate', async (message) => {
// Ignore messages from bots
if (message.author.bot) return;
// Only check messages from the specified channel
if (message.channel.id === pollChannelId) {
// If it's a poll, process as normal
if (message.poll) {
// Check if the poll has more than 5 options
if (message.poll.answers && message.poll.answers.size > 4) {
try {
// Delete the poll
await message.delete();
// Notify the user via DM
await message.author.send(`Your poll was deleted because it exceeded the limit of 4 answers.`);
} catch (error) {
console.error(`Error deleting poll or sending DM: ${error}`);
}
}
return; // End execution if the message is a valid poll
}
// If the message is the poll ending message, don't delete it
if (isPollEndMessage(message)) {
return; // Do nothing if it's the poll end message
}
// If it's not a poll or an ending message, delete the message
try {
await message.delete();
await message.author.send(`Your message was deleted because ${message.channel} is for polls only.`);
} catch (error) {
console.error(`Error deleting message or sending DM: ${error}`);
}
}
});