Package Exports
- apexify.js
- apexify.js/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (apexify.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Jedi-Studio Introduce
Greetings everyone! 🌟 This marks the release of a beta version for our package. If you encounter any issues or need assistance, feel free to reach out. Direct message me on Discord at jedi.79 (ID: 1130583393176920095).
🚀 Getting Started
- If you're new and facing issues or unable to register and execute commands (slash / prefix).
- Use the code snippet below (Note: This may slightly increase bot latency by approximately 50ms).
const { Client, GatewayIntentBits, Partials } = require("discord.js");
const { starter } = require('apexify.js');
const path = require('path');
const client = new Client({
intents: Object.keys(GatewayIntentBits).map((a)=>{
return GatewayIntentBits[a]
}),
partials: Object.values(Partials),
});
const token = process.env.token;
const eventsPath = path.join(__dirname, 'src', 'events');
const prefixCommandPath = path.join(__dirname, 'src', 'prefix');
const options = {
status: 'online', // idle, online, dnd
name: 'Playing with commands',
type: 0, // type is for activity (Playing, Watching, Custom , Listening, etc.)
botName: 'tools', // bot name
botAvatar: './pfp.jpeg', // set your bot avatar as a URL or local file (GIF also works)
eventsPath,
// Note: Don't provide guildId or put it in the options if you set global as true
slashCommandPath: {
baseDir: __dirname, // need to be provided to read your commands path
path: './src/slash',
global: true, // true for making slash commands global
guildId: '', // guild if global is false
logsId: '', // channel ID for commands log
},
prefixCommandPath: {
path: prefixCommandPath, // your prefix commands path
logsId: '', // channel ID for commands log
prefix: '!', // prefix of the bot
},
lavalink: {
// Lavalink configuration for music
nodes: [],
search: 'ytmsearch', // (ytmsearch) => YouTube musics || (spsearch) => Spotify musics
version: 'v4', // your Lavalink version
},
mongo: {
mongoURI: '', // Your MongoDB URI for connecting to MongoDB
dataName: '', // Your Database name to create in MongoDB
},
webView: {///creating aport using express
port: 3000,
hostname: 'jedi-studio.com'
middleware:,
routs:
}
};
starter(client, token, options);🚀 Usage Guidelines 🤖
Ai Chat & Imagine
For a standard reply without AI images or voice messages, set both draw and voice to false. Activate voice replies and AI images by setting them to true. Trigger the bot to draw AI images with specific words or phrases using drawTrigger.
// Use this for js files (cjs modules)
const { apexAI } = require('apexify.js');
// For es module (.mjs/(.js if "type": "module" in package.json) or ts
import { apexAI } from 'apexify.js';
const allowedChannelId = 'Channel_ID';
client.on('messageCreate', async (message) => {
if (message.author.bot || message.channel.id !== allowedChannelId) return;
await apexAI(message, {
voice: false,///for voice replies
voiceModel: "apexAI", //apexAI, google, zenithAi
voice_code: "en-US-3", ///only if voiceModel zenithAi
apiKey: "", ///only if voiceModel zenithAi/apexAI (join the support server for more info)
type: "b", ///only if voiceModel apexAI (a, b, c, d, e, f, g, h) those letters you can use
draw: true, // Enable AI images
drawTrigger: ['create', 'draw', 'imagine', 'ارسم'],
imageModel: 'prodia', // Choose AI image generator (check the end of the page for modals)
chatModel: 'v3-32k', // Choose chat model (check the end of the page for modals)
keywords: ['bot name', 'your name', 'who are you'],
keywordResponses: {
'bot name': 'My name is apexAI, and I was developed by Elias79.',
'your name': 'I am known as apexAI, created by Elias79.',
'who are you': 'I am apexAI, an AI created by Elias79.',
},
loadingMessage: null,/// a message being sent while generating response
nsfw: true, ////Prevent generating ai images (NSFW)
readFiles: true,///Read pdf/txt files
});
});📊 Database MongoDb (Online) 📁
- To connect to MongoDB/Mongoose, provide your URL and name your database. Follow these steps:
///for cjs module (.cjs/.js)
const { mongoConnect } = require('apexify.js');
///for es module (.mjs/(.js if "type": "module" in package.json) or ts
import { mongoConnect } from 'apexify.js';
// Connect to MongoDB
const mongoSuccess = await mongoConnect('mongoURI', 'dbName');
// Access connected databases using getDb functions
const mongoDb = getDb();
/*----------------------------------------*/
//if you wanted to use your database to save/edit/delete then use this example below
// Example usage:
const { save, updateData, find, remove, removeSpecific } = require('apexify.js');
///# Save (insertOne)
const collectionName = 'exampleCollection';
const document = { key: 'value' };
const options = {
uniqueFields: ['key'], // Example unique field
};
// Saving the document to MongoDB with options
const savedDocument = await save(collectionName, document, options);
///# Find (findOne)
const collectionName = 'exampleCollection';
const filter = { _id: '6063b0f4e8e8b652780e97e0' }; // Example filter, you can customize it
const projection = { name: 1, age: 1 }; // Example projection, you can customize it
const options = {
sort: { age: -1 }, // Example sort option, you can customize it
limit: 5, // Example limit option, you can customize it
};
// Finding a document in MongoDB with options
const foundDocument = await find(collectionName, filter, projection, options);
///# SearchMany (find().toArray)
const collectionFilters = [
{ collectionName: 'collection1', displayment: 5, filter: { status: 'active' } },
{ collectionName: 'collection2', displayment: null, filter: { type: 'public' } },
// Add more collection filters as needed to search for
];
// Searching for documents in multiple collections with specific filters
const searchResults = await searchMany(collectionFilters);
///# Remove (deleteOne)
const collectionName = 'exampleCollection';
const filter = { _id: '6063b0f4e8e8b652780e97e0' }; // Example filter, you can customize it
// Removing a document from MongoDB
const removalResult = await remove(collectionName, filter);//remove the document which mathces the filter
///# RemoveSpecific (deleteOne(filter))
const collectionName = 'exampleCollection';
const filter = { _id: '6063b0f4e8e8b652780e97e0', name: 'John Doe' }; // Example filter, you can customize it
const keyToRemove = { name: 1 }; // Example key to remove, you can customize it
// Removing a document from MongoDB with specific keys removed
const removalResult = await removeSpecific(collectionName, filter, keyToRemove);//remove the key without remvoe the full document
///# RemoveMany (deleteMany)
const collectionName = 'exampleCollection';
const filter = { status: 'inactive' }; // Example filter, you can customize it
// Removing multiple documents from MongoDB based on a filter
const removalResult = await removeMany(collectionName, filter);
///# UpdateData (updateOne)
const collectionName = 'yourCollectionName'; // Replace with your actual collection name
const filter = { _id: 'yourDocumentId', age: 23, name: 'Elias' }; // Replace with your actual filter criteria
const update = { age: 19, gender: 'male' }; // Replace with your actual update data
const uniqueFields = ['field1', 'field2']; // Replace with your unique fields, if any!
// Updating document data in the specified collection
const updateResult = await updateData(collectionName, filter, update, uniqueFields);
///# UpdateAll (updateMany)
const collectionName = 'yourCollectionName'; // Replace with your actual collection name
const filter = { level: 20, serverId: guildId, userId: userId }; // Replace with your actual filter criteria
const update = { level: 31 }; // Replace with your actual update data
const uniqueFields = ['userId', 'serverId']; // Replace with your unique fields, if any!
// Updating all documents matching the filter in the specified collection
const updateResult = await updateAll(collectionName, filter, update, options);
///# MigrateData
const sourceCollection = 'yourSourceCollection'; // Replace with your actual source collection name
const destinationCollection = 'yourDestinationCollection'; // Replace with your actual destination collection name
// Transferring data from the source collection to the destination collection
const transferResult = await migrateData(sourceCollection, destinationCollection);
///# MigrateAndPrune
const sourceCollection = 'yourSourceCollection'; // Replace with your actual source collection name
const destinationCollection = 'yourDestinationCollection'; // Replace with your actual destination collection name
// Transferring data from the source collection to the destination collection
const transferResult = await migrateAndPrune(sourceCollection, destinationCollection);
///# Drop (drop)
const dropCollectiom = 'collectionToRemove'; // Replace with your actual collection name
// Removing collection from mongoDb
const dropResults = await drop(dropCollectiom);
///# DataSize
const dataToCheck = 'collectioNameToCheck'; // Replace with your actual collection name
// Check collection size in db
const size = await dataSize(dataToCheck);
📊 Database NanoDb (local) 📁
- NanoDb is specially made for apexify library to make database easy for all (json database)
///for cjs module (.cjs/.js)
const { NanoDb } = require('apexify.js');
///for es module (.mjs/(.js if "type": "module" in package.json) or ts
import { NanoDb } from 'apexify.js';
/// Setting Which data json to configure
const db = awai NanoDb('path/file/to/json'); // Example: ../data.json
///# AddOne (inserting new data)
const result = await db.addOne({ userId: , serverId: , name: , age: 27}, { uniqueKeys: ['userId', 'serverId'] });
///# FindData (search for single document)
const result = await db.findData({ username: 'john', age: 40 });
///# DisplayData (display data array)
const displayOptions = {
displayment: 10,//display how many documents
filters: {
country: 'usa'///your filter
},
page: 1,
pageSize: 10,
sortBy: 'size', // Replace with the actual field you want to sort by
sortOrder: 'asc', // or 'desc' asc => ascending, desc => descending
};
// Displaying data using the displayData method
const result = await db.displayData(displayOptions);
///# RemoveOne (remove a single key from single document)
const filterQuery = {
xp: 1000 => assign it 'any' if you dont have specific value
};
///# RemoveOne (remove a single key from a single document)
const removeFilter = {
level: 'any'
};
// Removing fields using the removeOne method
const result = await db.removeOne(filterQuery, removeFilter);
///# RemoveDoc (remove a a full document)
const result = await db.removeDoc({ userId: value, serverId: value });
///# UpdatData (update a single document in the json)
const result = await db.updateData({ userId: value, validate: value}, { validate: newValue });
///# UpdateMany (update a many documents in the json)
const result = await db.updateMany({ validate: value, session: value }, { session: newvalue });
///# Drop (remove whole data in json)
const result = await db.drop();
📸 Manipulating Images Using Canvas 🎨
//You can use import for es module/.mjs
const { ApexPainter } = require('apexify.js');
const paintImage = new ApexPainter();
///Creating a background
const canvasOptions = {
width: 1200,//background width
height: 300,//background height
customBg: '',/// it can be URL only for now and if used plz dont use bgColor or bgGradient
backgroundColor: '#3498db', // Example color (blue) or use 'transparent' for no backgound color
backgroundGradient: {////Adding a gradient instead of constant color
type: 'linear',/// change to 'radial' if you want gradient start from middle
startX: 0,
startY: 0,
startRadius: 0,///add if radial only!
endRadius: 0,///add if radial only!
endX: 100,
endY: 0,
colors: [
{ stop: 0, color: 'red' },
{ stop: 0.5, color: 'green' },
{ stop: 1, color: 'blue' },
///add more colors if needed
],
},
borderRadius: 0,///adding a radius to create a curvy edges or use 'circular' to make it a circle
};
////
const images = [
{
source: 'square',///drawing shapes as images. We only support those shapes ('square', 'triangle', 'circle', 'pentagon').
x: 385,///positions on background horizontally.
y: 225,///positions on background vertically.
rotate: 0,//rotate only applyed for shapes.
filled: true,///to fill the shape if true.
width: 500,///shape width.
height: 80,//shape height.
borderRadius: 35,///adding a radius to create a curvy edges or use 'circular' to make it a circle.
color: 'rgba(0, 0, 0, 0.4)',///only being applied for shapes (filling the shape with the provided color).
gradient:, ////Adding a gradient instead of constant color (used same way as in canvas (only works with shapes).
stroke: {//Adding stroke
color: '#498afc',//color of the stroke
width: 5,//size of the stroke.
borderRadius: 35,///adding a radius to create a curvy edges or use 'circular' to make it a circle.
},
},
{
source: 'square',
x: 395,
y: 235,
rotate: 0,
filled: true,
width: 440,
height: 60,
borderRadius: 35,
gradient: {
type: 'linear',
startX: 0,
startY: 0,
endX: 100,
endY: 0,
colors: [
{ stop: 0, color: 'red' },
{ stop: 0.5, color: 'green' },
{ stop: 1, color: 'blue' },
],
},
},
{
source: 'local/file/path || image url',//you can provide an image url or local path and for images styling you can use same as above in shapes except for rotate and gradient which won't work.
x: 120,
y: 120,
width: 210,
height: 210,
borderRadius: 20,///adding a radius to create a curvy edges or use 'circular' to make it a circle.
shadow: {
color: null,//shadow color.
offsetX: 0,///shadow position off from image horizontally.
offsetY: 0,///shadow postion off from image vertically.
opacity: 0,//shadow opacity.
blur: 0,//shadow blur.
borderRadius: null,///adding a radius to create a curvy edges or use 'circular' to make it a circle.
}
},
];
////image already got buffered you can send it directly or add text option
const image = await paintImage.drawImages(images, canvasOptions, __dirname);
const textOptionsArray = [
{
text: 'elias79. Rank',//adding a text.
x: 440,//text horizontally positon .
y: 145,//text vetically position.
fontName: 'Wind',//name your font as you want or use default (Arial).
fontPath: './wind.ttf',//font path for custom font.
fontSize: 50,///size of the font.
color: 'white',//font color.
shadow: {
offsetX: 3,
offsetY: 3,
color: "rgba(0, 0, 0, 0.5)",
blur: 5
},
stroke: {
color: '#deff08',
width: 1.2,
},
},
{
text: '95/100 XP',
x: 530,
y: 250,
fontName: 'Arial',
fontSize: 35,
color: 'white',
stroke: {
color: 'black',
width: 0.5,
},
},
];
///Adding the text on the drawn image before
const buffer = await paintImage.addText(textOptionsArray, image, __dirname);
//sending the buffered image with text on it
await message.channel.send({files: [buffer] });Discord-Build ⚒️
- Easy & Simple ways to make buttons & menus & paginator & permschecker
//////MAKE BUTTONS///////
const { ButtonManager } = require('apexify.js'); ///cjs modules .js
import { ButtonManager } from 'apexify.js'; /// ejs modules .mjs or ts
const buttonsData = [
{
customId: 'button1',
style: 'Primary',// style: Primary, Secondary, Link, Danger, Success
label: 'Primary Button',
emoji: '😃', // Emoji for the button
disabled: false, // Whether the button is disabled
},
{
customId: 'button2',
style: 'Secondary',
label: 'Secondary Button',
emoji: '🚀',
disabled: true,
},
{
customId: 'linkButton',
style: 'Link',
label: 'Link Button',
url: 'https://example.com', // URL for link-style button
emoji: '🔗',
},
];
// Create an instance of ButtonManager
const buttonManager = new ButtonManager(buttonsData);
// Create an action row with the buttons
const actionRow = buttonManager.ButtonBuild();
// Define a message with the action row
message.reply({ content: 'Click the buttons:',
components: [actionRow],
});
// Define in interaction
interaction.reply({ content: 'Click the buttons:',
components: [actionRow],
});
//////MAKE MENUS///////
const { SelectMenuManager } = require('apexify.js');// cjs module .js
import { SelectMenuManager } from 'apexify.js'; // ejs module .mjs or ts
// Define select menu options
const selectMenuOptions = [
{ label: 'Option 1', value: 'option1', description: 'Description for Option 1', emoji: '🌟', default: true },
{ label: 'Option 2', value: 'option2', description: 'Description for Option 2', emoji: '🚀' },
{ label: 'Option 3', value: 'option3', description: 'Description for Option 3', emoji: '🔗' },
];
// Create an instance of SelectMenuManager
const selectMenuManager = new SelectMenuManager(
selectMenuOptions,
'customSelectMenuId', // Custom ID for the select menu
'Select an option', // Placeholder text for the select menu
1, // Minimum number of selected values
2, // Maximum number of selected values
false // Disabled state for meny (true or false)
);
// Create a select menu with the specified options
const selectMenuRow = selectMenuManager.createSelectMenu();
// Define a message with the select menu
message.reply({
content: 'Please choose an option:',
components: [selectMenuRow],
});
// Define a interaction with the select menu
interaction.reply({
content: 'Please choose an option:',
components: [selectMenuRow],
});
////////MAKE EMBED PAGINATOR////////
const { Paginator } = require('apexify.js');// cjs module .js
import { Paginator } from 'apexify.js'; // ejs module .mjs or ts
const pageOptions = [
{
title: 'Page 1',
description: 'Content for Page 1',
color: '#3498db', // Hex color code
authorName: 'Author Name',
authorIcon: 'https://example.com/author-icon.png', // URL to author's icon
footerName: 'Footer Name',
footerIcon: 'https://example.com/footer-icon.png', // URL to footer's icon
image: 'https://example.com/image.png', // URL to image
thumbnail: 'https://example.com/thumbnail.png', // URL to thumbnail
url: 'https://example.com/page-1', // URL for the entire embed
timestamp: true, // Include timestamp
},
{
title: 'Page 2',
description: 'Content for Page 2',
color: '#e74c3c',
authorName: 'Another Author',
authorIcon: 'https://example.com/another-author-icon.png',
footerName: 'Another Footer',
footerIcon: 'https://example.com/another-footer-icon.png',
image: 'https://example.com/another-image.png',
thumbnail: 'https://example.com/another-thumbnail.png',
url: 'https://example.com/page-2',
timestamp: true,
},
{
title: 'Page 3',
description: 'Content for Page 3',
color: '#2ecc71',
authorName: 'Yet Another Author',
authorIcon: 'https://example.com/yet-another-author-icon.png',
footerName: 'Yet Another Footer',
footerIcon: 'https://example.com/yet-another-footer-icon.png',
image: 'https://example.com/yet-another-image.png',
thumbnail: 'https://example.com/yet-another-thumbnail.png',
url: 'https://example.com/page-3',
timestamp: true,
},
// Add more pages as needed
];
// Create an instance of the Paginator class
const paginator = new Paginator({ options: pageOptions, timeout: 30000 });
/// In messages
client.on('messageCreate', async (msg) => {
// Check if the message author is a bot
if (msg.author.bot) return;
// Send the paginated message when the command !sendPaginator is received
if (msg.content === '!sendPaginator') {
const user = msg.author;
const options = { ownerOnly: false, hidden: false, };
// Send the paginated message
await paginator.send(msg, user, options);
}
});
/// In interactions
client.on('interactionCreate', async (i) => {
// Check if the message author is a bot
if (i.user.bot) return;
// Send the paginated message when the command/ button is used
if (i.customId === 'button') {
const user = i.user;
const options = { ownerOnly: false, hidden: false, };
// Send the paginated message
await paginator.send(i, user, options);
}
});
//////PERMISSION CHECKER///////
const { PermissionChecker } = require('apexify.js'); // cjs module .js
import { PermissionChecker } from 'apexify.js'; // ejs module .mjs or ts
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!checkPermissions')) {
try {
// Specify the required permissions you want to check
const requiredPermissions = ['KickMembers', 'BanMembers', 'ManageChannels'];
// Instantiate the PermissionChecker
const permissionChecker = new PermissionChecker();
// Check if the message author has the required permissions
const hasPermissions = await permissionChecker.checker(message.author.id, message.guild, requiredPermissions);
if (hasPermissions) {
message.reply('You have the required permissions!');
} else {
message.reply('You do not have the required permissions!');
}
} catch (error) {
console.error('Error:', error.message);
}
}
});
client.on('interactionCreate', async (i) => {
if (i.customId === 'button_checker') {
try {
// Specify the required permissions you want to check
const requiredPermissions = ['KickMembers', 'BanMembers', 'ManageChannels'];
// Instantiate the PermissionChecker
const permissionChecker = new PermissionChecker();
// Check if the message author has the required permissions
const hasPermissions = await permissionChecker.checker(i.user.id, i.guild, requiredPermissions);
if (hasPermissions) {
i.reply('You have the required permissions!');
} else {
i.reply('You do not have the required permissions!');
}
} catch (error) {
console.error('Error:', error.message);
}
}
});📚 More Info & Documentation 📖
Explore a detailed list of apexify.js and their usage at our Support Server.
🚨 Important Notes 📌
Voice Messages: Currently in beta, occasional disruptions may occur.
Commands: Support for slash commands is coming soon.
Music: Utilizing Lavalink for audio streaming. Customize Lavalink node if needed.
Database: There is two type of Database NanoDb (local db json) and MongoDb (online db bson).
Keep experimenting, and feel free to contact me for assistance! Suggestions and adjustments are welcome. 🌟