Discord button interaction handler that updates the original message if the clicker has administrator permissions, otherwise sends a warning message that automatically deletes in 5 seconds. You must change the "custom_id" in the event trigger to match your button.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const sleep = async (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms || 0);
});
};
if (!context.params.event.member.permission_names.includes('ADMINISTRATOR')) {
let createdMessage = await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ' ',
tts: false,
embed: {
type: 'rich',
title: 'For Moderators only!',
description: '',
color: 0xff0000,
},
});
await sleep(5000);
await lib.discord.channels['@0.1.2'].messages.destroy({
message_id: `${createdMessage.id}`,
channel_id: `${createdMessage.channel_id}`,
});
} else {
await lib.discord.channels['@0.1.2'].messages.update({
message_id: `${context.params.event.message.id}`,
channel_id: `${context.params.event.message.channel_id}`,
content: `You are an admin! You have edited this message!`,
embed: {},
components: [],
});
}