Use Airtable to manage scheduled announcements in your Discord server!
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let recordsToPublish = await lib.airtable.query['@1.0.0'].select({
table: `Scheduled Announcements`,
where: [
{
Ready__is_true: true,
Published__is_false: true,
'Schedule Date__lte': `${new Date().toISOString()}`,
},
],
});
if (recordsToPublish.rows.length) {
for (let i = 0; i < recordsToPublish.rows.length; i++) {
let row = recordsToPublish.rows[i];
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${process.env.ANNOUNCEMENTS_CHANNEL_ID}`,
content: `${record.fields.Content}`,
});
await lib.airtable.query['@1.0.0'].records.update({
table: `Scheduled Announcements`,
id: `${id}`,
fields: {
Published: true,
},
});
}
}