dsc-ac
v1.3.3
Published
Utility for djs -> acode.
Downloads
19
Readme
dsc-ac
Utility for djs -> acode.
Prerequisites
- Discord Bot Token and Client ID
- acode's lib import
- index.js file
- Handlers JSON in the following sample format:
{
"READY" : "/functions/events/discord/ready/ready.js",
"BOT_MENTION": "/functions/events/discord/message/create/bot_mention/bot_mention.js",
"PREFIX": {
"!ping" : "/functions/events/discord/message/create/prefix/ping.js",
"!button" : "/functions/events/discord/message/create/prefix/button.js",
"!selectmenu" : "/functions/events/discord/message/create/prefix/selectmenu.js"
},
"APPLICATION_COMMAND": {
"ping": "/functions/events/discord/command/ping.js"
},
"MESSAGE_COMPONENT": {
"button-id": "/functions/events/discord/message/button/button.js",
"selectmenu-id": "/functions/events/discord/message/selectmenu/selectmenu.js"
},
"MODAL_SUBMIT": {
"ping-modal": "/functions/events/discord/modal/ping.js"
}
}
- Note: First-level keys shall not be modified.
- First-level keys are the event triggers, except for
INTERACTION_CREATE
andMESSAGE_CREATE
.
Initialization
- Import both discordJS and lib
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const { Client, GatewayIntentBits, ActivityType } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
Usage
Files
- Modules for Message Create events should have two arguments.
module.exports = async (lib, context) => {
//your custom code here
}
- Modules for Interaction events should have at least two arguments.
interaction
is needed ifInteraction
from this module will be used.
module.exports = async (lib, context, interaction) => {
//your custom code here
}
Command Builder
- Create a json file containing your command details. Strictly follow the format below:
{
"global_commands" : [
{
"name": "ping",
"description": "get pong!"
}
],
"guild_commands" : {
"guild_id": "GUILD ID HERE",
"commands": [
{
"name": "pong",
"description": "if you want to get pong!"
}
]
}
}
- After you initialize the
CommandBuilder()
, call itsinit()
containing your json file path with respect to theindex.js
. Example directory:
/Discord Bot
├── index.js
├── commands.json
└── commands
└── ping.js
const { CommandBuilder } = require('dsc-ac');
const commandBuilder = new CommandBuilder(DISCORD_BOT_TOKEN, CLIENT_ID);
commandBuilder.init('/commands.json');
Handler
const { Handler } = require('dsc-ac');
const handlers_json = require('./handlers.json');
const handler = new Handler(handlers_json, CLIENT_ID, lib, interaction);
client.on('raw', async (data) => {
await handler.process(data);
});
Note: interaction
is optional for the Handler
. This is needed if you are going to use the Interaction()
properties.
Interactions
- Initialization
const { Interaction } = require('dsc-ac');
const interaction = new Interaction(DISCORD_BOT_TOKEN, CLIENT_ID);
- Interaction file
module.exports = async (lib, context, interaction) => {
await interaction.responses.ephemeral.create({
id: context.params.event.id,
token: `${context.params.event.token}`,
response_type: 'CHANNEL_MESSAGE_WITH_SOURCE',
content: `pong!`
});
}
Note: id
should always be included in the parameters of responses.
- Response Types
PONG
CHANNEL_MESSAGE_WITH_SOURCE
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
DEFERRED_UPDATE_MESSAGE
UPDATE_MESSAGE
APPLICATION_COMMAND_AUTOCOMPLETE_RESULT
MODAL
- Supported Interactions
/
└── responses
├── create
├── ephemeral
│ └── create
└── modals
└── create
requireModule()
- No params
const { requireModule } = require('dsc-ac');
await requireModule('/directory/file.js');
- With params
const { requireModule } = require('dsc-ac');
const _module = await requireModule('/directory/file.js');
await _module("Hello World!");
- Module file:
module.exports = async function (params) {
console.log(params);
}
Support
Need help? Contact us via Discord.