A library for making slash commands easy for discord bot developers!
A small library for making slash commands easy without using gateways or discord.js. Just the raw Discord Api.
This project requires NodeJS (version 8 or later) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.
$ npm -v && node -v
6.4.1
v8.16.0
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
BEFORE YOU INSTALL: please read the prerequisites
To install and set up the library, run:
$ npm install discord-easy-slash
Or if you prefer using Yarn:
$ yarn add --dev discord-easy-slash
var client = require('discord-easy-slash');
client.PUBLIC_KEY = '<PUBLIC_KEY>'
client.TOKEN = '<TOKEN>'
client.APP_ID = '<APPLICATION_ID>'
client.GUILD_ID = 'GUILD_ID' // (you still need this, as you have to have a testing server)
client.command('help', 1, 'help command?', null)
The command function takes 4 arguments, Name (Of the command), Type (Of the command), Description (Of the command), and Options, any options that the command takes.
or look at this page by discord.
They look like this:
[ { "name": "nameofoption", "description": "descriptionofoption", "type": 4, "required": true, } ]
It takes an array, with all the options for the command. Because of this, you can have multiple options for a single command.
For types of objects: or look at this page by discord.
client.on('slash_event', (command, data, res, type) => {
console.log('slash event!')
})
slash_event takes 4 arguments, command, data, res, and type.
command is the name of the slash command that was sent.
data is the data that was sent with the command.
res is the response object that you can use to send a message back to the user.
and type is the type of the command.
client.on('slash_event', (command, data, res, type) => {
if(command == 'help'){
client.reply(res, 'Help command?', null)
}else {
client.reply(res, 'Cound not find command..', null)
}
});
client.reply takes 3 arguments, res, which is mandatory because it is used to send the message, message, which is the message to send, and embeds, which is an array of embeds for the command to send.
[ { "title": "title", "description": "description", "color": "color", "fields": [ { "name": "name", "value": "value", "inline": true }, { "name": "name", "value": "value", "inline": true } ] } ]
client.listen(80)
Inside the INTERACTION ENDPOINTS URL box, put in the url of the server your bot is running on, with the endpoint “/event”.
For example:
https://server_address/event
or
discord.com/developers/applications/
$ npm start
You can contribute to the project by making a pull request on GitHub.
See also the list of contributors who participated in this project.
MIT License © Amukh1