You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Default options for embeds in Discordutility.generateEmbed() OR DiscordUtility.createEmbedPages() (check them below)
Example
DiscordUtility.defaultEmbed({watermark: "[Support Server](link) | [Invite Me](link)",footer: client.user.username,footerImage: client.user.displayAvatarURL(),author: client.user.username,authorImage: client.user.displayAvatarURL()header: "Make Sure to Invite me!\n\n"//Add "\n\n" to give 2 lines gap between the header and the main description of the embed.color: "#0000ff",thumbnail: client.user.displayAvatarURL(),timestamp: true});// return Promise
Note: You need to use this function only once in ready event.
DiscordUtility.delay()
Parameter
Type
Description
time
Number
Amount of time in milliseconds to delay a function
Example
awaitDiscordUtility.delay(1000);// return Promise
DiscordUtility.shorten()
Parameter
Type
Description
text
String
The text you want to shorten
maxLen
Number
Maximum length of text to return. Default: 2000
Example
letstring="Hello! This is an example code to explain the use of `DiscordUtility.shorten()` method!"DiscordUtility.shorten(string,15);// returns "Hello! This is ..."
String to convert each word's first letter UPPERCASE
split
String
Optional. Split the string to convert word's first letter UPPERCASE Default: " "
Example
letstring="this is a test string";//If you want to convert elemtns of array to uppercase//Change the "string" value to <Array>.join(" ");DiscordUtility.firstUpperCase(string);// returns "This Is A Test String"
DiscordUtility.formatNumber()
Parameter
Type
Description
number
Number
Number to format
minimumFractionDigits
Number
Optional. Minimum fraction digits to format to. Default: 2
Example
letnumber=2967.5779;DiscordUtility.formatNumber(number);// returns 2967.58//To get more decimal digits, simply add the number of digits you want after "number" DiscordUtility.formatNumber(number, 4)//(for 4 decimal digits)
DiscordUtility.base64()
Parameter
Type
Description
text
String
text to convert in base64 format.
mode
String
Optional. Whether to "encode" or "decode". Default: "encode"
Example
letstring="My name is ronak";DiscordUtility.base64(string);//returns "TXkgbmFtZSBpcyByb25haw=="//To decodeletdecodeString="TXkgbmFtZSBpcyByb25haw==";DiscordUtility.base64(decodeString,"decode");//returns "My name is ronak"
Optional. Desired time for the verification to last, extra "yes" and "no" (Array)
Example
letchannel=message.channel;letuser=message.mentions.users.first();DiscordUtility.verify(channel,user);//returns true (If user sends "yes/y/ye/yeah") else false (if user sends "no/n/nah" or time ends)
DiscordUtility.reactMessage()
Parameter
Type
Description
message
Discord.Message
Message to react on.
user
Discord.ClientUser
Discord.ClientUser.
emoji
String
Emoji to react with
fallbackEmoji
String
Optional. Fall back emoji, if main emoji not found, react with it. Default: "✅"
Emoji to react with once a user has been allowed to join the queue
max
Number
Maximum number of users that can join a queue
min
Number
Optional. Minimum number of users required for the queue. Default: 1
Example
letmsg=message;letjoin="join game";letemoji="custom-emoji-id";letmax=5DiscordUtility.awaitPlayers(msg,join,emoji,max);//returns false (if not reached the minimum player req) else Array of player IDs who have joined.
letmessage=message;letauthor=message.author;lettime=30;letvalidReactions=["✅","❌"];DiscordUtility.promptMessage(message,author,time,validReactions).then(async(emoji)=>{if(emoji===""✅){//do something}elseif(emoji==="❌"){//do something}});//returns emoji the AUTHOR reacted with
DiscordUtility.getMember()
Parameter
Type
Description
message
Discord.Message
Discord.Message.
toFind
String
Find member with this data.
Example
lettoFind=message.content;//Use your "args" if you have defined that.DiscordUtility.getMember(message,toFind);//returns Discord.GuildMember
DiscordUtility.getChannel()
Parameter
Type
Description
message
Discord.Message
Discord.Message.
toFind
String
Find channel with this data.
Example
lettoFind=message.content;//Use your "args" if you have defined that.DiscordUtility.getChannel(message,toFind);//returns Discord.GuildChannel
DiscordUtility.getRole()
Parameter
Type
Description
message
Discord.Message
Discord.Message.
toFind
String
Find role with this data.
Example
lettoFind=message.content;//Use your "args" if you have defined that.DiscordUtility.getRole(message,toFind);//returns Discord.Role
DiscordUtility.getUser()
Parameter
Type
Description
client
Discord.Client
Your bot client.
message
Discord.Message
Discord.Message.
toFind
String
Find member with this data.
Example
letclient=newDiscord.Client();letmessage=message;lettoFind=message.content.slice(prefix.length).trim().split(" ").slice(1).join(" ");//Use your "args" if you have defined that.DiscordUtility.getUser(client,message,toFind);//returns Discord.User
Duration unicode to convert into Days, Hours, Minutes and seconds
Example
DiscordUtility.formatDays(264860372)//returns "3 days, 1 hour, 34 minutes and 20 seconds"
DiscordUtility.formatTime()
Parameter
Type
Description
milliseconds
Number
Duration ms to format
trim
Boolean
Optional. Whether to trim the duration and remove duration equal to 0 or not. Default: false
format
String
Optional. Format type. Default: "h:mm:ss"
Example
DiscordUtility.formatTime(60000)//returns "0:01:00"//When trim is true:DiscordUtility.formatTime(60000,true)//returns "01:00"
DiscordUtility.generateEmbed()
Parameter
Type
Description
options
Object
Object containing all the embed data
Example
letoptions={title: "A title",description: "A desscription for the embed",footer: client.user.username,footerImage: client.user.displayAvatarURL()color: "#0000ff",watermark: true//A watermark text must be set using `DiscordUtility.defaultEmbed({watermark: "text here"})` in ready event of the bot.}letembed=DiscordUtility.generateEmbed(options);message.channel.send(embed);//returns Discord.MessageEmbed
DiscordUtility.createEmbedPages()
Parameter
Type
Description
client
Discord.Client
Your Discord.js Client
message
Discord.Message
Your discord.js Message
array
Array
Array of data that need to be converted into pages
options
Object
Optional. Object containing all the embed pages data
Example
require("discord-buttons")(client)//Must be done in your main file (usually index.js)//If you want to use buttons in embed.//Make sure to install discord buttons using `npm install discord-buttons`letoptions={title: "A title",footer: client.user.username,footerImage: client.user.displayAvatarURL()color: "#efc67a",args: message.content.split(" ")[1],buttons: true,//only if you want to use buttons instead of reactions. else, leave it.// IF YOU WANT TO CHANGE EMOJISemojis: {forward: "👉"}//Read below for all emojis options}letarray=["element1","element2","element3","element4","element5","element6","element7","element8"];Utils.createEmbedPages(client,message,array,options)//returns Discord.MessageEmbed// ======== Default Options for embed =========// null means Not set.options.buttons=false//make it true to use buttons instead of reactions for page navigationoptions.header=null//Text that you want to be shown in every page of the embed pages. (description at the top)options.watermark=false//Use `DiscordUtility.defaultEmbed({watermark: "text here"})` in ready event to set a watermark and view in embeds if this is trueoptions.title=null,//embed.titleoptions.color="#0000ff",//embed.coloroptions.args=null,//Whether to use numbers for page navigation or not. To enable, replace "null" with the argument of the messageoptions.joinBy="\n",//How to join the arrays in embedoptions.perpage=5,//How many elements to show perpageoptions.image=null,//embed.image (will be visible in all embed pages)options.thumbnail=null,//embed.thumbnail imageURLoptions.footer=client.user.username,//embed.footeroptions.footerImage=client.user.displayAvatarURL(),//embed.footer imageURLoptions.author=null,//embed.authoroptions.authorImage=null,//embed.author imageURLoptions.timestamp=null,//Whether to view Timestamp in embed. true/falseoptions.user=message.author;//User who will be able to react// ========== EMOJIS ==========options.emojis.forward="▶",//Emojis used to navigate to next pageoptions.emojis.backward="◀",//Emojis used to navigate to previous pageoptions.emojis.delete="🗑",//Emojis used to delete the embed pages messageoptions.emojis.first="⏪",//Emojis used to navigate to first pageoptions.emojis.last="⏩"//Emojis used to navigate to last page// =========== Button Text ===========options.buttonText.next="Next",options.buttonText.previous="Previous",options.buttonText.first="First",options.buttonText.last="Last",options.buttonText.delete="Delete",
constSchema=newmongoose.Schema({guildID: {type: String},prefix: {type: String,default: "!"}});constguildSchema=mongoose.model("guildConfig",Schema);letdata=awaitDiscordUtility.mongoFind(guildSchema,{guildID: "1234567890"});if(!data){//If the database for the server is not availabledata=awaitDiscordUtility.mongoCreate(guildSchema,{guildID: "1234567890"});}//returns Promise
Support
If you are facing any issues or if you have found a bug in this package, feel free to open an issue in the github repository. Click Here
You can contribute to this package. Feel free to create a pull request
You can also reach out to me through discord. My user tag is -> ♡ Rem ♡#2135