Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
discore.js
Advanced tools
Readme
index.js
structure:
const { Core } = require('discore.js');
new Core({
// options
}).login('token');
const { Core } = require('discore.js');
new Core({
token: 'token',
});
const { Core } = require('discore.js');
new Core({
folders: {
inhibitors: 'inhibitors',
commands: 'commands',
monitors: 'monitors',
triggers: 'triggers',
events: 'events',
},
prefixOptions: {
spaceSeparator: false, // Allow space after prefix
ignoreCase: false, // Ignore prefix case
mention: false, // Allow using @mention as prefix
},
commandOptions: {
argsSeparator: ' ', // Regular expressions are allowed
permLevels: new PermissionLevels(),
ignoreCase: false,
ignoreBots: true, // Prevents bots from using commands.
ignoreSelf: true, // Prevents the bot from using commands on itself.
},
mainPath: '.',
// Displays the bot as online from a mobile
mobile: false,
// Regular expressions and arrays (Strings, RegExps) are allowed.
prefix: undefined,
token: null,
db: null,
});
this.client.config.guild.set('guild_id', {
prefix: undefined,
mentionPrefix: false,
argsSeparator: ' ',
ignoreCase: true,
ignorePrefixCase: 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.
});
Events are placed in .\events\
(CoreOptions#folders#events option).
For instance, creating .\events\Main\ready.js
will be an event named ready
in the Main
category. Subcategories are also allowed and will have second and greater folder levels.
Their structure (options argument defined with default configuration):
load
(Store).
load:{type}s
(Store).
voiceChannelJoin
(oldState: VoiceState, newState: VoiceState)
voiceChannelSwitch
(oldState: VoiceState, newState: VoiceState)
voiceChannelLeave
(oldState: VoiceState, newState: VoiceState)
dbConnect
dbError
dbDisconnect
const { Event } = require('discore.js');
module.exports = class extends Event {
get options() {
return {
enabled: true,
name: null, // Event name.
once: false, // Unloads after first use.
id: undefined, // Used to get the event.
};
// If name is not defined then it will be defined as file name.
// For example, ready.js will 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
*/
};
}
// Params of the event
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\
(CoreOptions#folders#commands option).
For instance, creating .\events\Main\help.js
will be a command named help
in
the Main
category. Subcategories are also allowed and will have second and greater folder levels.
Their structure (options argument defined with default configuration):
const { Command } = require('discore.js');
module.exports = class extends Command {
get options() {
return {
enabled: true,
name: null, // Command name.
id: undefined, // Used to get the command.
cooldown: 0, // In milliseconds
aliases: [],
permLevel: 0, // Runs noPermsRun() method if tests not passed.
once: false, // Unloads after first use.
requiredRoles: [], // Accepts string and string array
requiredPerms: [], // Accepts number, string and array of strings and numbers
};
// If name is not defined then it will be defined as file name.
// For example, test.js will 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, { usedPrefix, usedCommand }) {
// Command code.
// runs only if enabled.
}
disabledRun(message, args, { usedPrefix, usedCommand }) {
// runs only if disabled.
}
noPermsRun(message, args, { usedPrefix, usedCommand }) {
// runs if Permission Level test hasn't passed.
}
noRequiredRolesRun(message, args, { usedPrefix, usedCommand }) {}
noRequiredPermsRun(message, args, { usedPrefix, usedCommand }) {}
cdRun(message, args, { usedPrefix, usedCommand }) {
// runs if user have active cooldown on his id
}
init() {
// runs on 'ready'
// event so you are able to use discord
// data via this.client
}
};
toggle()
enable()
disable()
unload()
reload()
toString()
categories
Monitors are placed in .\monitors\
(CoreOptions#folders#monitors option).
Runs on any message and receives message as first argument.
For instance, creating .\monitors\Main\filter.js
will be a monitor named filter
in the Main
category. Subcategories are also allowed and will have second and greater folder levels.
Their structure (options argument defined with default configuration):
const { Monitor } = require('discore.js');
module.exports = class extends Monitor {
get options() {
return {
enabled: true,
name: null, // Monitor name.
id: undefined, // Used to get the command.
once: false, // Unloads after first use.
};
// If name is not defined then it will be defined as file name.
// For example, filter.js will be 'filter'
}
get customOptions() {
return {
// You can put any options you want.
// And use it via this.custom
};
}
get cOptions() {
return {
// Shortcut for customOptions property.
/*
If you define both customOptions and cOptions
then customOptions becomes more priority
*/
};
}
run(message) {
// Monitor code.
// Runs only if enabled.
}
disabledRun(message) {
// 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
Triggers are placed in .\triggers\
(CoreOptions#folders#triggers option).
Runs on any message if it is not a command and receives message as first argument.
For instance, creating .\triggers\Main\xp.js
will be a trigger named xp
in the Main
category.
Subcategories are also allowed and will have second and greater folder levels.
Their structure (options argument defined with default configuration):
const { Trigger } = require('discore.js');
module.exports = class extends Trigger {
get options() {
return {
enabled: true,
name: null, // Trigger name.
id: undefined, // Used to get the command.
once: false, // Unloads after first use.
};
// If name is not defined then it will be defined as file name.
// For example, xp.js will be 'xp'
}
get customOptions() {
return {
// You can put any options you want.
// And use it via this.custom
};
}
get cOptions() {
return {
// Shortcut for customOptions property.
/*
If you define both customOptions and cOptions
then customOptions becomes more priority
*/
};
}
run(message) {
// Trigger code.
// Runs only if enabled.
}
disabledRun(message) {
// 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
Inhibitors are placed in .\inhibitors\
(CoreOptions#folders#inhibitors option).
Runs on any message if it is a command and receives message as first argument
and command as second argument.
For instance, creating .\inhibitors\Main\inhibit.js
will be an inhibitor named inhibit
in the Main
category. Subcategories are also allowed and will have second and greater folder levels.
Their structure (options argument defined with default configuration):
const { Inhibitor } = require('discore.js');
module.exports = class extends Inhibitor {
get options() {
return {
enabled: true,
name: null, // Inhibitor name.
id: undefined, // Used to get the command.
once: false, // Unloads after first use.
};
// If name is not defined then it will be defined as file name.
// For example, server.js will be 'server'
}
get customOptions() {
return {
// You can put any options you want.
// And use it via this.custom
};
}
get cOptions() {
return {
// Shortcut for customOptions property.
/*
If you define both customOptions and cOptions
then customOptions becomes more priority
*/
};
}
run(cmd, message, args, { usedPrefix, usedCommand }) {
// Inhibitor code.
// Runs only if enabled.
// Should return true in the end.
// Doesn't run commands if return false or undefined.
}
disabledRun(cmd, message, args, { usedPrefix, usedCommand }) {
// 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
Finalizers are placed in .\finalizers\
(CoreOptions#folders#finalizers option).
Runs after a command.
Receives message as first argument, message response as second one, and a boolean,
which is true wheather if command is enabled, as third argument.
For instance, creating .\finalizers\Main\reply.js
will be a finalizer named reply
in the Main
category. Subcategories are also allowed and will have second and greater folder levels.
Their structure (options argument defined with default configuration):
const { Finalizer } = require('discore.js');
module.exports = class extends Finalizer {
get options() {
return {
enabled: true,
name: null, // Inhibitor name.
id: undefined, // Used to get the command.
once: false, // Unloads after first use.
};
// If name is not defined then it will be defined as file name.
// For example, server.js will be 'server'
}
get customOptions() {
return {
// You can put any options you want.
// And use it via this.custom
};
}
get cOptions() {
return {
// Shortcut for customOptions property.
/*
If you define both customOptions and cOptions
then customOptions becomes more priority
*/
};
}
run(message, res, enabled) {
// Inhibitor code.
// Runs only if enabled.
// Should return true in the end.
// Doesn't run commands if return false or undefined.
}
disabledRun(message, res, enabled) {
// 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
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()
search()
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 previous example
this.client.commands.get('command_id');
this.client.commands.get('command_name'); // Same as previous example
this.client.commands.get('command_alias'); // Same as previous example
this.client.commands.search('hlp');
this.client.commands.search('hlep');
Their structure:
const { PermissionLevels } = require('discore.js');
const permLevels = new PermissionLevels();
permLevels
.add(0, true, (msg) => msg.author.id === '1')
// Permissions Level 1 gives access only if message author id is equal to '1'
.add(1, false, (msg) => msg.author.id === '1')
// Permissions Level 2 gives access only to the bot
.addLevel(2, false, (msg, client) => {
return msg.author.id === client.user.id;
});
// Tests 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);
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 previous 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
DBs you use but much faster, powerful and object-oriented
save()
populate()
json()
const doc = await db.getCollection('users').findOne({ id: 'some id' });
doc.someProp = 'some value';
doc.save().then(() => console.log('Saved!'));
Structure:
const { Core, Mongo } = require('discore.js');
const db = new Mongo('url', {
/* Options */
});
new Core({
db,
});
addModel()
open()
( Open connection )close()
( Close connection )getCollection()
collections
connection
Their structure:
// If default value is not defined, it will be set to undefined.
// You can leave values as undefined.
const data = {
id: Mongo.Types.String,
messageCount: { type: Mongo.Types.Number, default: 0 },
};
db.addModel('modelName', data);
Number
Double
String
Object
Array
ObjectId
Boolean
Date
RegExp
fetch()
getData()
filterKeys()
filter()
findKey()
findOne()
getOne()
insertOne()
insertMany()
deleteOne()
deleteMany()
updateOne()
upsertOne()
// Fetches all documents from the database.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
const data = await collection.fetch();
// Returns data from local storage.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
const data = await collection.getData();
// Filters the collection and returns only keys.
// Returns Promise<string[]>
const collection = db.getCollection('name');
const keys = await collection.filterKeys(
(value) => value.username === 'zargovv'
);
// Filters the collection.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
const newCollection = await collection.filter(
(value) => value.username === 'zargovv'
);
// Finds document and returns key.
// Returns Promise<string | undefined>
const collection = db.getCollection('name');
const result = await collection.findKey(
(value) => value.username === 'zargovv'
);
// Finds document.
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const result = await collection.findOne(
(value) => value.username === 'zargovv'
);
// Gets document
// (Searches for it, if there is no one, then returns default values).
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const document = await collection.getOne(
(value) => value.username === 'zargovv'
);
// Creates new document
// Returns Document
const collection = db.getCollection('name');
const result = collection.insertOne({ id: '1', username: 'zargovv' });
// Creates new documents
// Returns Document[]
const collection = db.getCollection('name');
const result = collection.insertMany([
{ id: '1', username: 'zargovv' },
{ id: '2', username: 'discore.js' },
]);
// Deletes document
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const result = await collection.deleteOne({ username: 'zargovv' });
// Deletes document
// Returns Promise<Document[]>
const collection = db.getCollection('messages');
const result = collection.deleteMany((doc) => doc.messageCount < 1);
// Updates document. Returns undefined if document wasn't found.
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const result = await collection.updateOne({ username: 'zargovv' }, { id: '0' });
// Updates document. Creates new one if not found.
// Returns Promise<Document>
const collection = db.getCollection('name');
const result = await collection.updateOne({ username: 'zargovv' }, { id: '0' });
Structure:
const { Core, MySql } = require('discore.js');
const db = new MySql(/* connection url(string) or connection options(object) */);
new Core({
db,
});
dbConnect
dbError
dbDisconnect
addModel()
open()
( Open connection )close()
( Close connection )getCollection()
collections
Their structure:
// If default value is not defined, it will be set to undefined.
// You can leave values as undefined.
const data = {
id: MySql.Types.VarChar(18),
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
fetch()
getData()
filterKeys()
filter()
findKey()
findOne()
getOne()
insertOne()
insertMany()
deleteOne()
deleteMany()
updateOne()
upsertOne()
// Fetches all documents from the database.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
collection.fetch().then((data) => {});
// Returns data from local storage.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
const data = await collection.getData();
// Filters the collection and returns only keys.
// Returns Promise<string[]>
const collection = db.getCollection('name');
const keys = await collection.filterKeys(
(value) => value.username === 'zargovv'
);
// Filters the collection.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
const newCollection = await collection.filter(
(value) => value.username === 'zargovv'
);
// Finds document and returns key.
// Returns Promise<string | undefined>
const collection = db.getCollection('name');
const result = await collection.findKey(
(value) => value.username === 'zargovv'
);
// Finds document.
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const result = await collection.findOne(
(value) => value.username === 'zargovv'
);
// Gets document
// (Searches for it, if there is no one, then returns default values).
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const document = await collection.getOne(
(value) => value.username === 'zargovv'
);
// Creates new document
// Returns Document
const collection = db.getCollection('name');
const result = collection.insertOne({ id: '1', username: 'zargovv' });
// Creates new documents
// Returns Document[]
const collection = db.getCollection('name');
const result = collection.insertMany([
{ id: '1', username: 'zargovv' },
{ id: '2', username: 'discore.js' },
]);
// Deletes document
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const result = collection.deleteOne({ username: 'zargovv' });
// Deletes document
// Returns Promise<Document[]>
const collection = db.getCollection('messages');
const result = collection.deleteMany((doc) => doc.messageCount < 1);
// Updates document. Returns undefined if document wasn't found.
// Returns Promise<Document | undefined>
const collection = db.getCollection('name');
const result = await collection.updateOne({ username: 'zargovv' }, { id: '0' });
// Updates document. Creates new one if not found.
// Returns Promise<Document>
const collection = db.getCollection('name');
const result = await collection.updateOne({ username: 'zargovv' }, { id: '0' });
Structure:
const { Core, Json } = require('discore.js');
const db = new Json(/* path to the directory */);
new Core({
db,
});
addModel()
getCollection()
save()
collections
Their structure:
// Default values.
// You can leave values as undefined.
const data = {
id: undefined,
messageCount: 0,
rowId: 0,
};
db.addModel('modelName', data);
fetch()
getData()
filterKeys()
filter()
findKey()
findOne()
getOne()
insertOne()
insertMany()
deleteOne()
deleteMany()
updateOne()
upsertOne()
// Fetches all documents from the database.
// Returns Promise<Collection<string, Document>>
const collection = db.getCollection('name');
collection.fetch().then((data) => {});
// Returns data from local storage.
// Returns Promise<Collection<string, MongoDocument>>
const collection = db.getCollection('name');
const data = await collection.getData();
// Filters the collection and returns only keys.
// Returns string[]
const collection = db.getCollection('name');
const keys = collection.filterKeys((value) => value.username === 'zargovv');
// Filters the collection.
// Returns Collection<string, Document>
const collection = db.getCollection('name');
const newCollection = collection.filter(
(value) => value.username === 'zargovv'
);
// Finds document and returns key.
// Returns string | undefined
const collection = db.getCollection('name');
const result = collection.findKey((value) => value.username === 'zargovv');
// Finds document.
// Returns Document | undefined
const collection = db.getCollection('name');
const result = collection.findOne((value) => value.username === 'zargovv');
// Gets document
// (Searches for it, if there is no one, then returns default values).
// Returns Document | undefined
const collection = db.getCollection('name');
const document = collection.getOne((value) => value.username === 'zargovv');
// Creates new document
// Returns Document
const collection = db.getCollection('name');
const result = collection.insertOne({ id: '1', username: 'zargovv' });
// Creates new documents
// Returns Document[]
const collection = db.getCollection('name');
const result = collection.insertMany([
{ id: '1', username: 'zargovv' },
{ id: '2', username: 'discore.js' },
]);
// Deletes document
// Returns Document | undefined
const collection = db.getCollection('name');
const result = collection.deleteOne({ username: 'zargovv' });
// Deletes document
// Returns Promise<Document[]>
const collection = db.getCollection('messages');
const result = collection.deleteMany((doc) => doc.messageCount < 1);
// Updates document. Returns undefined if document wasn't found.
// Returns Document | undefined
const collection = db.getCollection('name');
const result = collection.updateOne({ username: 'zargovv' }, { id: '0' });
// Updates document. Creates new one if not found.
// Returns Document
const collection = db.getCollection('name');
const result = collection.updateOne({ username: 'zargovv' }, { id: '0' });
FAQs
Discord.js-based powerful node.js module to interact with Discord API.
The npm package discore.js receives a total of 57 weekly downloads. As such, discore.js popularity was classified as not popular.
We found that discore.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.