Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/matiasvlevi/discord-commandline

A Discord Bot that runs CMD commands, JS scripts & Custom Commands.
https://github.com/matiasvlevi/discord-commandline

cmd command-line discord discord-bot discord-js windows

Last synced: 3 months ago
JSON representation

A Discord Bot that runs CMD commands, JS scripts & Custom Commands.

Awesome Lists containing this project

README

        

# 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](https://discord.com/developers/applications) 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](https://www.swipetips.com/how-to-get-channel-id-in-discord/)

See how to obtain a Discord Bot & its token [here](https://www.writebots.com/discord-bot-token/)


#### 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 .
2021-02-24 09:47 AM ..
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
```

##### Add `&&` to write multiple cmd commands

try :
```
$cmd cd.. && dir
```



## Add Custom Commands

Add the custom commands in `user/commands.js`.

```js
commands.add('COMMAND_NAME', function , permissions);
```



## Custom Command examples

#### Simple command
```js
commands.add('ping',() => (
'pong'
));
```

User input in discord channel :
```
$ping
```

Bot reply :
```
pong
```


#### Command with arguments
```js
commands.add('mult',(arg) => (
arg[0] * arg[1]
));
```
User input in discord channel :
```
$mult 4 5
```

Bot reply :
```
20
```


#### Command with no return
```js
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

```js
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
```