Counting channel through an embed, make sure that your counting channel is set to the same channel that the webhook is in.
//slowmode is recommended
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let message = context.params.event.content;
let current_num = await lib.utils.kv['@0.1.16'].get({
key: `number`,
defaultValue: 1,
});
let webhookid = `Webhook_ID_Here`;
let webhooktoken = `Webhook_Token_Here`;
let Adminrole = 'Role_ID_HERE';
let countingchannel = `Channel_ID_Here`;
if (context.params.event.channel_id == countingchannel) {
//replace with real counting channel id
if (context.params.event.content.startsWith('-reset') && Adminrole) {
await lib.utils.kv['@0.1.16'].set({
key: `number`,
value: 1,
});
} else if (parseInt(message.split(' ')[0]) !== parseInt(current_num)) {
await lib.discord.channels['@0.1.1'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
} else {
await lib.discord.webhooks['@0.1.0'].execute({
webhook_id: webhookid,
webhook_token: webhooktoken,
content: `${message}`,
username: `${context.params.event.author.username}`,
avatar_url: `https://cdn.discordapp.com/avatars/${context.params.event.author.id}/${context.params.event.author.avatar}.png`,
});
await lib.discord.channels['@0.3.1'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${context.params.event.channel_id}`,
});
await lib.utils.kv['@0.1.16'].set({
key: `number`,
value: parseInt(message.split(' ')[0]) + 1,
});
}
}