Discord Birthday
![](https://camo.githubusercontent.com/c57876f0c391a33c3656cd897e59d074515f7bdf30f077eb42ff88d0a0c6a136/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f64742f646973636f72642d62697274686461793f7374796c653d666f722d7468652d6261646765)
discord-birthday is a powerful package that allows you to create a birthday system on your discord bot easily and quickly.
Installation
Download package
npm install discord-birthday
npm install @ayrozdzn/discord-birthday
yarn add discord-birthday
Connect to your discord bot
const { Birthday, Timezone } = require("discord-birthday"); // or @ayrozdzn/discord-birthday
const { Client } = require("discord.js");
const client = new Client({ ... });
client.birthday = new Birthday(client, {
timezone: Timezone.UTC,
hour: 10,
minute: 0,
});
Parameter |
Type |
Optional |
Default |
Description |
client |
Client |
|
|
The discord client |
timezone |
Timezone |
✓ |
Timezone.UTC |
Your timezone |
hour |
Number |
✓ |
10 |
A number between 0 and 23 |
minute |
Number |
✓ |
0 |
A number between 0 and 59 |
Methods
setUserBirthday
client.birthday.setUserBirthday(user, date, seeAge)
Parameter |
Type |
Optional |
Default |
Description |
user |
User |
|
|
The user whose birthday is to be set |
date |
Date |
|
|
The birthday date |
seeAge |
Boolean |
✓ |
true |
Set the visibility variable accessible after |
returns : Birthday
getUserBirthday
client.birthday.getUserBirthday(user).then((birthday) => {
console.log(birthday)
/*
{
user: <User>,
seeAge: <Boolean>,
date: <Date>,
age: <Number>,
nextBirthday: <Date>,
daysBeforeNext: <Number>,
guilds: <Array<Guild>>,
}
*/
}).catch((err) => console.error(err));
Parameter |
Type |
Description |
user |
User |
The user whose birthday is to be collected |
returns : Promise <Object>
deleteUserBirthday
client.birthday.deleteUserBirthday(user)
Parameter |
Type |
Description |
user |
User |
The user whose birthday is to be delete |
returns : Birthday
getGuildBirthdays
client.birthday.getGuildBirthdays(guild).then((birthdays) => {
console.log(birthdays)
/*
[
{
member: <GuildMember>,
seeAge: <Boolean>,
date: <Date>,
age: <Number>,
nextBirthday: <Date>,
daysBeforeNext: <Number>,
guild: <Guild>
},
...
]
*/
}).catch((err) => console.error(err));
Parameter |
Type |
Description |
guild |
Guild |
The guild in which the birthdays are to be collected |
returns : Promise <Array[Object]>
activateMemberBirthday
client.birthday.activateMemberBirthday(member) // return error if already activated or member has no birthday set
Parameter |
Type |
Description |
member |
GuildMember |
The member whose birthday is to be activated |
returns : Birthday
deactivateMemberBirthday
client.birthday.deactivateMemberBirthday(member) // return error if already deactivated or member has no birthday set
Parameter |
Type |
Description |
member |
GuildMember |
The member whose birthday is to be deactivated |
returns : Birthday
checkMemberGuildBirthdaysStatus
const status = client.birthday.checkMemberGuildBirthdaysStatus(member) // returns true or false
Parameter |
Type |
Description |
member |
GuildMember |
The member whose birthday is checked |
returns : boolean
setGuildBirthdayChannel
client.birthday.setGuildBirthdayChannel(channel)
Parameter |
Type |
Description |
channel |
TextChannel |
The channel in which the birthdays will be wished |
returns : Birthday
getGuildBirthdayChannel
client.birthday.getGuildBirthdayChannel(guild).then((channel) => {
console.log(channel) /* <NonThreadGuildBasedChannel> */
}).catch((err) => console.error(err));
Parameter |
Type |
Description |
guild |
Guild |
The guild in which the channel is to be collected |
returns : Promise <GuildChannel>
deleteGuildBirthdayChannel
client.birthday.deleteGuildBirthdayChannel(guild)
Parameter |
Type |
Description |
guild |
Guild |
The guild in which the birthdays channel will be delete |
returns : Birthday
Events
isBirthday
client.birthday.on("isBirthday", (user, guilds) => {
console.log(`The birthday of ${user.tag} has been wished in ${guilds.length}`);
guilds.forEach(guild => {
guild.channels.get("...").send({content: `It's the birthday of ${member.user.tag}`})
})
});
Parameter |
Type |
Description |
user |
User |
The user whose birthday has been wished |
guilds |
Array <Guild> |
Array of all guild where the birthday has been wished |
birthdayUserSet
client.birthday.on("birthdayUserSet", (user, date) => {
console.log(`The birthday of ${user.tag} is ${date.toDateString()}`);
});
Parameter |
Type |
Description |
user |
User |
The user whose birthday has been set up |
date |
Date |
The birthday date |
birthdayUserDelete
client.birthday.on("birthdayUserDelete", (user) => {
console.log(`The birthday of ${user.tag} has been delete`);
});
Parameter |
Type |
Description |
user |
User |
The user whose birthday has been deleted |
birthdayMemberActivate
client.birthday.on("birthdayMemberActivate", (member) => {
console.log(`The birthday of ${member.user.tag} has been activated in ${member.guild.name}`);
});
Parameter |
Type |
Description |
member |
GuildMember |
The member whose birthday has been activated |
birthdayMemberDeactivate
client.birthday.on("birthdayMemberDeactivate", (member) => {
console.log(`The birthday of ${member.user.tag} has been deactivated in ${member.guild.name}`);
});
Parameter |
Type |
Description |
member |
GuildMember |
The member whose birthday has been deactivated |
birthdayGuildChannelSet
client.birthday.on("birthdayGuildChannelSet", (channel) => {
console.log(`The birthday channel ${channel.name} has been set for the guild ${channel.guild.name}`);
});
Parameter |
Type |
Description |
channel |
GuildChannel |
The channel whose birthday channel has been set up |
birthdayGuildChannelDelete
client.birthday.on("birthdayGuildChannelSet", (guild) => {
console.log(`The birthday channel of ${guild.name} has been delete`);
});
Parameter |
Type |
Description |
guild |
Guild |
The Guild whose birthday channel has been delete |