index.js
structure:
const { Core } = require('discore.js');
new Core({
// options
}).login('token');
- Alternate login system
const { Core } = require('discore.js');
new Core({
token: 'token',
});
- All options (defaults)
const { Core } = require('discore.js');
new Core({
eventsFolder: 'events',
commandsFolder: 'commands',
token: null,
// To make multiple prefixes you can make an array
// Example: ['!', '.']
prefix: undefined,
spaceAfterPrefix: false,
splitArgs: ' ',
ignoreCase: true,
permLevels: new PermissionLevels(),
ignoreSelf: true,
ignoreBots: true,
db: null,
});
- Per-guild configuration.
this.client.config.guild.set('guild_id', {
// Default settings:
prefix: undefined,
splitArgs: ' ',
ignoreCase: true,
permLevels: new PermissionLevels(),
ignoreSelf: true,
ignoreBots: true,
});
// If you want to leave current default prefixes
// and add new one then you can use add() method.
this.client.config.guild.add('guild_id', {
prefix: '.', // Example.
});
uniqid.gen()
// Generates unique identificator
Events are placed in .\events\
(eventsFolder option).
For instance creating .\events\Main\ready.js
will be an event ready
in the Main
category. Subcategories are also allowed and gonna be a second and more folder levels.
Their structure (options argument defined with default configuration):
const { Event } = require('discore.js');
module.exports = class extends Event {
get options() {
return {
// Will run run() method if true, otherwise disabledRun() method.
enabled: true,
key: null, // Same as name but more important.
name: null, // Key is going to be event name.
once: false, // If true, event will emitted only once.
id: undefined, // UniqID if not defined. Used to get the event.
};
// If key and name are null then they will be defined as file name.
// For example, ready.js is gonna be 'ready'
}
get customOptions() {
return {
// You can put any options you want.
// And use it via this.custom.
};
}
get cOptions() {
return {
// Same as customOptions property.
/*
If you define both customOptions and cOptions
then customOptions becomes more priority
*/
};
}
run(...params) {
// Event code.
// Runs only if enabled.
}
disabledRun(...params) {
// Same as run but runs only if disabled.
}
init() {
// Optional method. Runs on 'ready'
// event so you are able to use discord
// data via this.client.
}
};
toggle()
enable()
disable()
unload()
reload()
toString()
categories
Commands are placed in .\commands\
(commandsFolder option).
For instance creating .\events\Main\Command.js
will be a command Command
in the Main
category. Subcategories are also allowed and gonna be a second and more folder levels.
Their structure (options argument defined with default configuration):
const { Command } = require('discore.js');
module.exports = class extends Command {
get options() {
return {
// Will run run() method if true, otherwise disabledRun() method.
enabled: true,
key: null, // Same as name but more important.
name: null, // Key is going to be command name.
id: undefined, // UniqID if not defined. Used to get the event.
cooldown: 0, // In milliseconds
aliases: [],
permLevel: 0, // Runs noPermsRun() method if tests not passed.
description: undefined,
usage: undefined,
};
// If key and name are null then they will be defined as file name.
// For example, test.js is gonna be 'test'
}
get customOptions() {
return {
// You can put any options you want.
// And use it via this.custom.
};
}
get cOptions() {
return {
// Same as customOptions property.
/*
If you define both customOptions and cOptions
then customOptions becomes more priority.
*/
};
}
run(message, args) {
// Command code.
// Runs only if enabled.
}
disabledRun(message, args) {
// Same as run but runs only if disabled.
}
noPermsRun(message, args) {
// Same as run
// but runs only if Permission Level test is not passed.
}
init() {
// Optional method. Runs on 'ready'
// event so you are able to use discord
// data via this.client.
}
};
toggle()
enable()
disable()
unload()
reload()
toString()
categories
const command = this.client.commands.get('command');
command
.toggle()
.enable()
.disable()
.unload()
.reload()
.toString();
Do you want to load event or command in live mode? You can use load() method!
.\
is gonna be your main file's root folder.
load()
get()
this.client.events.load('./events/event');
this.client.commands.load('./commands/command');
this.client.events.get('event_id');
this.client.events.get('event_name'); // Same as previus example
this.client.commands.get('command_id');
this.client.commands.get('command_name'); // Same as previus example
this.client.commands.get('command_alias'); // Same as previus example
Their structure:
const { Core, PermissionLevels } = require('discore.js');
const config = require('./config');
const permLevels = new PermissionLevels();
permLevels
.add(0, true, msg => msg.author.id === '1') // Throws error.
// Permissions Level 1 is true only if message author id is '1'
.add(1, false, msg => msg.author.id === '1')
// Same as previus example
.addLevel(2, false, (msg, client) => {
return msg.author.id === client.user.id;
});
// Test for a role.
permLevels.add(3, true, msg => msg.member.roles.has('roleid'));
// Testing. Returns boolean.
permLevels.test(3, msg);
// You can define client as third argument if needed.
permLevels.test(2, msg, this.client);
new Core(config);
addLevel()
add()
test()
length
Their structure:
const { Pages, Embed } = require('discore.js');
const pages = new Pages(this.client, {
prevPage: '⏮', // Emoji which is used to switch to the previus page.
nextPage: '⏭', // Emoji which is used to switch to the next page.
filter: (reaction, user) => user.id === message.author.id, // Example.
});
const embed = new Embed()
.setTitle('Embedded Page!')
.setDescription('Yay! You can add embedded page!')
.setFooter('Page: 2');
pages
// AddPage method adds only one page.
.addPage('Hey! You are on the first page!')
// With add method you can add one page.
.add(embed)
// Or tons of pages!
.add('`Third page.`', '`Fourth and the last page.`');
const msg = await pages.send(message.channel);
const timeout = 5000; // 5000 milliseconds = 5 seconds.
// To turn off pages just delete the message!
// Example:
msg.delete(timeout);
// or
setTimeout(() => msg.delete(), timeout);
addPage()
add()
send()
client
options
emojis
pages
filter
Their structure:
const { Embed } = require('discore.js');
const embed = new Embed()
.addBlankField()
.addField('Title', 'Description')
.attachFile(file)
.attachFiles(files)
.setAuthor('author', 'image url')
.setColor(color)
.setDescription('description')
.setFooter('footer', 'image url')
.setImage('image url')
.setThumbnail('image url')
.setTimestamp()
.setTitle('title')
.setURL('url');
addBlankField()
addField()
attachFile()
attachFiles()
setAuthor()
setColor()
setDescription()
setFooter()
setImage()
setThumbnail()
setTimestamp()
setTitle()
setURL()
author
color
description
fields
file
files
footer
image
length
thumbnail
timestamp
title
url
Structure:
const { Core, Mongo } = require('discore.js');
const db = new Mongo('url', {
/* Options */
});
new Core({
db,
});
dbConnected
dbError
dbDisconnected
addModel()
open()
( Open connection )close()
( Close connection )
collection
Their structure:
// Must define all default properties.
// You can leave properties as undefined.
const data = {
id: { type: Mongo.Types.String, default: undefined },
messageCount: { type: Mongo.Types.Number, default: 0 },
};
db.addModel('modelName', data);
Number
Double
String
Object
Array
ObjectId
Boolean
Date
RegExp
hasOne()
findOne()
insertOne()
deleteOne()
updateOne()
upsertOne()
// Working with model from previus example.
// You can use `db['modelName']`
// Searches for document with `id` of '123'.
let res1 = db.modelName.hasOne({ id: '123' });
let res2 = db.modelName.hasOne('id', '123'); // Same.
let res3 = db.modelName.hasOne(val => val.id === '123'); // Same.
console.log(typeof res); // Returns true or false (Boolean).
console.log(typeof res2); // Same.
console.log(typeof res3); // Same.
// Working with model from previus example.
// You can use `db['modelName']` or `db.modelName`
// Searches for document with `id` of '123'.
let res1 = db.modelName.findOne({ id: '123' });
let res2 = db.modelName.findOne('id', '123'); // Same.
let res3 = db.modelName.findOne(val => val.id === '123'); // Same.
/*
Returns document. If there is no document
then you will getdefault settings which
were defined by yourself.
That means you can not get undefined or
null.
*/
console.log(typeof res);
console.log(typeof res2); // Same.
console.log(typeof res3); // Same.
// **upsertOne() method is recommended to use!**
db.modelName.insertOne({
id: '3213',
messageCount: 1, // If not defined, going to be 0.
});
// returns null or document.
db.modelName.deleteOne({ id: '3213' });
/*
Does the same thing but returns null
because document is already deleted.
*/
db.modelName.deleteOne('id', '3212');
// Same as previus example.
db.modelName.deleteOne(val => val.id === '3212');
// **upsertOne() method is recommended to use!**
/*
All of these examples are going to search
for `id` of '3213' and update
*/
db.modelName.updateOne({ id: '3213' }, { messageCount: 2 });
db.modelName.updateOne('id', '3212', { messageCount: 2 });
db.modelName.updateOne(val => val.id === '3212', { messageCount: 2 });
/*
upsertOne() method is trying to update
a document. If document is not exists then
is going to insert it.
*/
// All of these examples are going to search
// for `id` of '3213' and update
// messageCount to 2.
db.modelName.upsertOne({ id: '3213' }, { messageCount: 2 });
db.modelName.upsertOne('id', '3212', { messageCount: 2 });
db.modelName.upsertOne(val => val.id === '3212', { messageCount: 2 });
Structure:
const { Core, MySql } = require('discore.js');
const db = new MySql('url');
new Core({
db,
});
dbConnected
dbError
dbDisconnected
addModel()
open()
( Open connection )close()
( Close connection )
collection
Their structure:
// Must define all default properties.
// You can leave properties as undefined.
const data = {
id: { type: MySql.Types.VarChar(18), default: undefined },
messageCount: { type: MySql.Types.Int, default: 0 },
rowId: {
type: MySql.Types.Int(null, 'NOT NULL', 'AUTO_INCREMENT', 'PRIMARY'),
default: 0,
},
};
db.addModel('modelName', data);
Double
Boolean
Date
VarChar
TinyText
Text
Blob
MediumText
LongText
LongBlob
TinyInt
SmallInt
MediumInt
Int
BigInt
Float
Decimal
DateTime
Timestamp
Time
Enum
Set
hasOne()
findOne()
insertOne()
deleteOne()
updateOne()
upsertOne()
// Working with model from previus example.
// You can use `db['modelName']`
// Searches for document with `id` of '123'.
let res1 = db.modelName.hasOne({ id: '123' });
let res2 = db.modelName.hasOne('id', '123'); // Same.
let res3 = db.modelName.hasOne(val => val.id === '123'); // Same.
console.log(typeof res); // Returns true or false (Boolean).
console.log(typeof res2); // Same.
console.log(typeof res3); // Same.
// Working with model from previus example.
// You can use `db['modelName']` or `db.modelName`
// Searches for document with `id` of '123'.
let res1 = db.modelName.findOne({ id: '123' });
let res2 = db.modelName.findOne('id', '123'); // Same.
let res3 = db.modelName.findOne(val => val.id === '123'); // Same.
/*
Returns document. If there is no document
then you will getdefault settings which
were defined by yourself.
That means you can not get undefined or
null.
*/
console.log(typeof res);
console.log(typeof res2); // Same.
console.log(typeof res3); // Same.
// **upsertOne() method is recommended to use!**
db.modelName.insertOne({
id: '3213',
messageCount: 1, // If not defined, going to be 0.
});
// returns null or document.
db.modelName.deleteOne({ id: '3213' });
/*
Does the same thing but returns null
because document is already deleted.
*/
db.modelName.deleteOne('id', '3212');
// Same as previus example.
db.modelName.deleteOne(val => val.id === '3212');
// **upsertOne() method is recommended to use!**
/*
All of these examples are going to search
for `id` of '3213' and update
*/
db.modelName.updateOne({ id: '3213' }, { messageCount: 2 });
db.modelName.updateOne('id', '3212', { messageCount: 2 });
db.modelName.updateOne(val => val.id === '3212', { messageCount: 2 });
/*
upsertOne() method is trying to update
a document. If document is not exists then
is going to insert it.
*/
// All of these examples are going to search
// for `id` of '3213' and update
// messageCount to 2.
db.modelName.upsertOne({ id: '3213' }, { messageCount: 2 });
db.modelName.upsertOne('id', '3212', { messageCount: 2 });
db.modelName.upsertOne(val => val.id === '3212', { messageCount: 2 });