discord-birthday is a powerful package that allows you to create a birthday system on your discord bot easily and quickly.
npm install discord-birthday
npm install @ayrozdzn/discord-birthday
yarn add discord-birthday
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 |
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
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 |
client.birthday.deleteUserBirthday(user)
Parameter | Type | Description |
---|---|---|
user | User | The user whose birthday is to be delete |
returns : Birthday
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]>
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
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
const status = client.birthday.checkMemberGuildBirthdaysStatus(member) // returns true or false
Parameter | Type | Description |
---|---|---|
member | GuildMember | The member whose birthday is checked |
returns : boolean
client.birthday.setGuildBirthdayChannel(channel)
Parameter | Type | Description |
---|---|---|
channel | TextChannel | The channel in which the birthdays will be wished |
returns : Birthday
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>
client.birthday.deleteGuildBirthdayChannel(guild)
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild in which the birthdays channel will be delete |
returns : Birthday
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 |
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 |
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 |
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 |
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 |
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 |
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 |