README
Button-Utils
A utility package for Discord Bots using buttons!
For errors and questions you can join our support server
Button bot example
Soon
Table of content:
installation
-Giveaways
-Button Roles
-npm:
npm i button-utils
yarn:
yarn add button-utils
Giveaways
soon
Preview
soon
Usage
connect
You can connect to the mongoDB database
const butils = require('button-utils');
butils.giveaways.connect(mongURI);
params
mongoURI: the mongo URI
Create
You can create giveaways with .create
Example code can be found below
const butils = require('button-utils')
butils.giveaways.create({
message: message,
prize: 'test',
host: message.author.id,
winners: 1,
endAfter: '10s',
requirements: { enabled: false },
channel: message.channel.id,
});
options
message: Discord Message
prize: String, prize of the giveaway
host: the host of the giveaway
winners: Number, the winners count
endAfter: String, The time after the giveaway will end
requirements: Object, the requirements for the giveaway. example: requirements: {enabled: true, roles: ['role']}
channel: the channel ID the embed will be sent to
buttonclick
IMPORTANT. THIS HANDLES THE BUTTONS IN YOUR GIVEAWAY, WITHOUT THIS THE BUTTONS WONT WORK!
handles the buttons in your code, can be put in clickButton
event
client.on('clickButton', button => {
butils.giveaways.buttonclick(client, button);
});
End
End is a function which will help you end giveaways easily
You can end giveaways with .end
butils.giveaways.end(message, data, giveawaymsg);
params
message: Discord Message
data: data from the database, can be obtained by using the .getByMessageID
property
giveawaymsg: fetched giveaway message
Reroll
You can reroll giveaways easily with .reroll
You can simply use this function by writing a line of code.
(async () => {
const win = await butils.giveaways.reroll(client, messageID);
}()
params
client: The Discord Client
messageID: The message ID of the giveaway
startTimer
you can start the timer again after restart, note that it automatically starts the timer when the giveaway start.
You can simply use this function by writing a line of code.
await butils.giveaways.startTimer(message, data);
params
message: Discord Message
data: mongoose document, can be obtained by using .getByMessageID
GotoGiveaway
returns a url button leading to the giveaway.
(async () => {
const button = await butils.giveaways.gotoGiveaway(data);
}()
params:
data: mongoose document, can be obtained by using .getByMessageID
getByMessageID
This gets the mongoose document for the giveaway
(async () => {
const doc = await butils.giveaways.getByMessageID(messageID);
}()
params
messageID: the message ID of the giveaway
startAgain
starts the giveaway again after restart, put this in ready event to start All the giveaways again.
butils.giveaways.startAgain(client)
params
client: Discord Client
Button Roles
buttonroles
click here
constructor. use .setrole() on it to create buttons
const something = new butils.buttonroles().addrole({color: 'red', label: 'test', role: '781061040514269185'});
options
color: the button color. Optional. Defaults to gray
label: Button label
role: role that would be added on click
emoji: ID of the emoji on the button, optional.
create
creates the button roles
butils.buttonroles.create({ message: message, role: something, content: new Discord.MessageEmbed().setTitle('xd').setDescription('xdxd') });
options
message: Discord Message
role: The object recieved from the buttonroles constructor.
content: content, can be a string or a Discord Embed
buttonclick
handles the buttons in button-roles
IMPORTANT. THIS HANDLES THE BUTTONS IN YOUR GIVEAWAY, WITHOUT THIS THE BUTTONS WONT WORK!
butils.buttonroles.buttonclick(client, button);