Discord-CommandLine
Discord-CommandLine is a template for a discord bot, made to simply add custom commands & run CMD commands on the local machine.
Features
- Create custom commands for a Discord bot.
- Run windows CMD commands on your local machine.
- Run JS scripts.
Requirements
- Nodejs (npm)
Setup
Step 1
Run setup.bat
to create all the base files & install dependencies.
Step 2
Add your bot token & the ID of your discord server channel in the user/options.json
files. You can obtain a token from the Discord Dev Protal after having created a new Application & Discord bot.
{
"token":"",
"channel_ID":"",
"prefix":"$",
"allowJS":"true",
"log":"true",
"accessJS": [],
"accessCMD": []
}
See how you can obtain your channel ID here
See how to obtain a Discord Bot & its token here
Step 3 (Optional)
Add custom command bindings in the user/commands.js
file.
Step 4
Launch run.bat
to start the bot.
Run Windows CMD commands
$cmd
$cmd yourCMDcommand
Example
User input in discord channel :
$cmd dir
Bot reply :
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Your\Path\to\repo\Discord-CommandLine\build
2021-02-24 09:47 AM <DIR> .
2021-02-24 09:47 AM <DIR> ..
2021-02-24 11:36 AM 3,312 index.js
1 File(s) 3,312 bytes
2 Dir(s) 74,909,536,256 bytes free
&&
to write multiple cmd commands
Add try :
$cmd cd.. && dir
Add Custom Commands
Add the custom commands in user/commands.js
.
commands.add('COMMAND_NAME', function , permissions);
Custom Command examples
Simple command
commands.add('ping',() => (
'pong'
));
User input in discord channel :
$ping
Bot reply :
pong
Command with arguments
commands.add('mult',(arg) => (
arg[0] * arg[1]
));
User input in discord channel :
$mult 4 5
Bot reply :
20
Command with no return
commands.add('loop',(arg) => {
for (let i = 0; i < arg[0]; i++) {
msg.channel.send(i);
}
});
User input in discord channel :
$loop 4
Bot reply :
0
1
2
3
Add permissions to a command
commands.add('ping',(arg) => {
'pong'
},['UserA','UserC']);
UserB
would not be able to use this command while UserA
& UserC
can. You might want to disable allowJS
because this allows for permissions changes.
Run JS scripts
The allowJS
property in user/options.json
should be set to "true"
for the feature to be enabled.
Example
User input in discord channel :
```js
let a = 10;
let b = 4;
msg.channel.send(a+b);
```
Bot reply :
14