Discord Birthday

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");
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.EuropeParis 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).catch(err => {
    console.error(err);
});
Parameter Type Description
user User The user whose birthday is to be set
date Date The birthday date

returns : Promise

deleteUserBirthday

client.birthday.deleteUserBirthday(user).catch(err => {
    console.error(err);
});
Parameter Type Description
user User The user whose birthday is to be delete

returns : Promise

getUserBirthday

client.birthday.getUserBirthday(user).then((birthday) => {
    console.log(birthday)
    /*
    {
        user: <User>,
        date: <Date>,
        active: {
            "guildID": <Boolean>
        }
    }
    */
}).catch((err) => console.error(err));
Parameter Type Description
user User The user whose birthday is to be collected

returns : Promise <Object>

getGuildBirthdays

client.birthday.getGuildBirthdays(guild).then((birthdays) => {
    console.log(birthdays)
    /*
    [
        {
            member: <GuildMember>,
            date: <Date>
        },
        ...
    ]
    */
}).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).catch(err => {
    console.error(err);
});
Parameter Type Description
member GuildMember The member whose birthday is to be activated

returns : Promise

deactivateMemberBirthday

client.birthday.deactivateMemberBirthday(member).catch(err => {
    console.error(err);
});
Parameter Type Description
member GuildMember The member whose birthday is to be deactivated

returns : Promise

setGuildBirthdayChannel

client.birthday.setGuildBirthdayChannel(channel).catch(err => {
    console.error(err);
});
Parameter Type Description
channel GuildChannel The channel in which the birthdays will be wished

returns : Promise

deleteGuildBirthdayChannel

client.birthday.deleteGuildBirthdayChannel(guild).catch(err => {
    console.error(err);
});
Parameter Type Description
guild Guild The guild in which the birthdays channel will be delete

returns : Promise

getGuildBirthdayChannel

client.birthday.getGuildBirthdayChannel(guild).then((channel) => {
    console.log(channel) /* <GuildChannel> */
}).catch((err) => console.error(err));
Parameter Type Description
guild Guild The guild in which the channel is to be collected

returns : Promise <GuildChannel>

Events

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, guild) => {
    console.log(`The birthday of ${member.user.tag} has been activated in ${guild.name}`);
});
Parameter Type Description
member GuildMember The member whose birthday has been activated
guild Guild The guild where the birthday has been activated

birthdayMemberDeactivate

client.birthday.on("birthdayMemberDeactivate", (member, guild) => {
    console.log(`The birthday of ${member.user.tag} has been deactivated in ${guild.name}`);
});
Parameter Type Description
member GuildMember The member whose birthday has been deactivated
guild Guild The guild where the 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

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

GitHub

View Github