In this snippet it makes it so if someone pings anyone 5 times it will trigger a message telling them to stop. You can easily replace that with a mute or a warn, whatever you want. Also it wont save your ping count forever, it will be discharged in 120 seconds (2 mins)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let member = context.params.event.author.id;
//The trigger for the endpoint, telling the code if there is a mention to trigger this
if (context.params.event.mentions[0]) {
//Gets the users current ping count
let count = await lib.utils.kv['@0.1.16'].get({
key: `pingedCount_${member}`,
defualtValue: 1,
});
//Tells the code if they have 5 pings to trigger this
if (count === 4) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Hey <@${member}>, please stop pinging people!`,
});
//Resets the count back to 0
await lib.utils.kv['@0.1.16'].clear({
key: `pingedCount_${member}`,
});
//If they have not pinged 5 times it triggers this
} else {
await lib.utils.kv['@0.1.16'].set({
key: `pingedCount_${member}`,
value: count + 1,
//Tells the code to expire in 2 mins
ttl: 120,
});
}
}