This is the old version of the hbd bot running on Node.js runtime. To view the new and improved (yet work in progress) version of this bot that is on edge runtime, click here.
a discord bot for user's birthdays, horoscopes, and wishing user's a happy birthday.
-
π INVITE
-
π DISCORD SERVER
-
π CHANGELOG
π WIKI
- Getting Started β Information about configuring the bot for your guild
-
data is stored in mongoose models
- guild settings (channels, roles)
- user's birthdays
- birthday wishes
-
when the bot logs in, the
timeevent is emitted:
client.login(process.env.BOT_TOKEN!).then(() => client.emit("time"));- which checks the time, if it is midnight, the
intervalis emitted- this returns an interval that runs every 24 hrs and checks for birthdays
- if there's a birthday present, the
birthdayevent is emitted with the designated user & guild ID
module.exports = (client: Client) => {
const handleInterval = async (client: Client) => {
let date = new Date();
let filter = {};
const birthdays = await Birthday.find(filter);
const dateString = date.toLocaleDateString();
const dateArray = dateString.split("/");
const dateParsed = dateArray[0] + `/` + dateArray[1];
for (const birthday of birthdays) {
if (birthday.Birthday === dateParsed) {
client.emit("birthday", [birthday.UserID, birthday.GuildID]);
} else {
//
}
}
};
return setInterval(
async () => await handleInterval(client),
1000 * 60 * 60 * 24
); // 1000 * 60 * 60 = 1 hr
};- fetches the channel to announce in and announces the birthday
//...
const announceChannelId = guildData.AnnouncementChannel!;
channel = await(
await(await client.guilds.fetch(guildId)).channels.fetch(announceChannelId)
).fetch() as TextChannel;
return await channel.send(/* ... */);- fetches the birthday role (if it exists) and gives it to the user
let birthdayRole: Role;
targetGuild.roles.cache.forEach((role) => {
if (role.id === guildData.BirthdayRole) {
birthdayRole = role;
}
return;
});
try {
return await user.roles.add(birthdayRole);
} catch (err) {
//...
}