A generic NodeJS API for creating plug.dj bots.
Originally by Chris Vickery, now maintained by TAT and The plug³ Team.
NOTE: Currently not supporting Facebook login.
Run the following:
npminstallplugapi--productionYou can choose to instantiate plugAPI with either Sync or Async:
Sync:
varPlugAPI=require('plugapi');varbot=newPlugAPI({email: '',password: ''});bot.connect('roomslug');// The part after https://plug.djbot.on('roomJoin',function(room){console.log("Joined "+room);});Async 3.5.0 and Below:
varPlugAPI=require('plugapi');newPlugAPI({email: '',password: ''},function(bot){bot.connect('roomslug');// The part after https://plug.djbot.on('roomJoin',function(room){console.log("Joined "+room);});});Async 4.0.0:
varPlugAPI=require('plugapi');newPlugAPI({email: '',password: ''},function(err,bot){if(!err){bot.connect('roomslug');// The part after https://plug.djbot.on('roomJoin',function(room){console.log("Joined "+room);});}else{console.log('Error initializing plugAPI: '+err);}});Here are some bots that are using this API.
| Botname | Room |
|---|---|
| AuntJackie | Mix-N-Mash |
| BeavisBot | I <3 the 80's and 90's |
| -DnB- | Drum & Bass |
| FlavorBar | Flavorz |
| FoxBot | Approaching Nirvana |
| TFLBot | The F**k Off Lounge | TFL |
| QBot | EDM Qluster |
| Holly Refbots | Connect The Songs (Read Info!) |
| DRPG | Discord Dungeons |
| brainbot | 5M4R7 |
| Toaster-chan | ☆ ♥ Nightcore-331 ♥ ☆ |
Have a bot that uses the API? Let us know!
You can listen on essentially any event that plug emits.
// basic chat handler to show incoming chats formatted nicelybot.on('chat',function(data){if(data.type=='emote')console.log(data.from+data.message);elseconsole.log(data.from+"> "+data.message);});Here's an example for automatic reconnecting on errors / close events!
varreconnect=function(){bot.connect(ROOM);};bot.on('close',reconnect);bot.on('error',reconnect);Please refer to the Wiki for both the Events and Actions.
- Clone repository to empty folder.
- Cd to the folder containing the repository.
- Run
npm installto set up the environment. - Edit your changes in the code, and make sure it follows our Style Guidelines.
- Run
npm testto make sure all tests pass. - After it's bug free, you may submit it as a Pull Request to this repo.
Since plug.dj cuts off chat messages at 250 characters, you can choose to have your bot split up chat messages into multiple lines:
varbot=newPlugAPI(auth);bot.deleteAllChat=false;// Set to true to enable deletion of chat regardless of role . Default is falsebot.multiLine=true;// Set to true to enable multi line chat. Default is falsebot.multiLineLimit=5;// Set to the maximum number of lines the bot should split messages up into. Any text beyond this number will just be omitted. Default is 5.