Celebrate everyone in your server on their birthday! This bot sends automated birthday messages once a day to a discord channel using Scheduler API. Requires Google Sheets. Enjoy! Set up your Google Sheet with three fields `Name`, `Role`, `BirthdayMonth` BirthdayDay` like so: https://docs.google.com/spreadsheets/d/1SKw97duf9RG7S6_3XcnQ2jKg7d-vuZfrq8_2rpDIoMQ/edit?usp=sharing
const lib = require('lib')({
token: process.env.STDLIB_SECRET_TOKEN,
});
/**
* An HTTP endpoint that acts as a webhook for Scheduler daily event
* @returns {object} result Your return value
*/
const gifs = [
'https://media.giphy.com/media/WRL7YgP42OKns22wRD/giphy.gif',
'https://media.giphy.com/media/WRL7YgP42OKns22wRD/giphy.gif',
'https://media.giphy.com/media/g5R9dok94mrIvplmZd/giphy.gif',
'https://media.giphy.com/media/l4KhS0BOFBhU2SYIU/giphy.gif',
'https://media.giphy.com/media/l4KibWpBGWchSqCRy/giphy.gif',
'https://media.giphy.com/media/arGdCUFTYzs2c/giphy.gif'
];
const randomGif = gifs[Math.floor(Math.random() * gifs.length)];
module.exports = async () => {
// Store API Responses
const result = {
googlesheets: {},
discord: {},
giphy: {},
};
const momentTimezone = require('moment-timezone');
let date = momentTimezone().tz('America/Los_Angeles'); //sets the timezone of the date object to 'America/Los_Angeles'
let today_day = date.format('D'); //return the day 1, 2, 3, ... 31
let today_month = date.format('M'); // return the month 1, 2, 3.. 12
console.log(date);
console.log(today_day);
console.log(today_month);
console.log(
`Running [Google Sheets β Select Rows from a Spreadsheet by querying it like a Database]...`
);
result.googlesheets.selectQueryResult = await lib.googlesheets.query[
'@0.3.0'
].select({
range: `A:E`,
bounds: 'FIRST_EMPTY_ROW',
where: [
{
BirthdayMonth: today_month,
BirthdayDay: today_day,
},
],
limit: {
count: 0,
offset: 0,
},
});
if (result.googlesheets.selectQueryResult.rows.length != 0) {
let usernames;
for (
let i = 0;
i < result.googlesheets.selectQueryResult.rows.length;
i++
) {
if (i == 0) {
usernames =
result.googlesheets.selectQueryResult.rows[i].fields['Username'];
console.log(usernames);
} else if (
i > 0 &&
i < result.googlesheets.selectQueryResult.rows.length - 1
) {
usernames =
usernames +
', ' +
result.googlesheets.selectQueryResult.rows[i].fields['Username'];
console.log(usernames);
} else {
usernames =
usernames +
', and ' +
result.googlesheets.selectQueryResult.rows[i].fields['Username'];
console.log(usernames);
}
}
console.log(
`Running [Discord -> Send a Message from your Bot to a Channel]`
);
result.discord.response = await lib.discord.channels[
'@0.1.2'
].messages.create({
channel_id: `${process.env.CHANNEL_ID}`,
content: `Birthdates π`,
tts: false,
allowed_mentions: {
replied_user: false,
parse: ['roles'],
},
embeds: [
{
type: 'rich',
title: `Happy Birthday ${usernames}! π We hope you have a great day!`,
color: 0xff0095,
image: {
url: randomGif,
height: 0,
width: 0,
},
thumbnail: {
url: `https://media.istockphoto.com/vectors/birthday-cake-vector-isolated-vector-id901911608?k=6&m=901911608&s=612x612&w=0&h=d6v27h_mYUaUe0iSrtoX5fTw-2wGVIY4UTbQPeI-T5k=`,
height: 0,
width: 0,
},
},
],
});
return result;
}
};