5.1.0
Create instance of PlugAPI.
Extends EventEmitter3
(any)
(Function?)
An optional callback utilized in async mode
There are multiple ways to create a bot. Sync vs Async, FB vs guest or email. Please choose only one of the examples to use.
// Sync
// Password
const bot = new PlugAPI({email: 'something@something.com', password: 'hunter2'});
// Facebook
// To login with fb will require logging in via plug and viewing the data sent in to /_/auth/facebook via the network tab of dev tools.
const bot = new PlugAPI({
facebook: {
userID: 'xxxxxxxx',
accessToken: 'xxxxxx'
}
});
// Guest
const bot = new PlugAPI();
// OR
const bot = new PlugAPI({ guest: true });
// Async
// Password
new PlugAPI({email: 'something@something.com', password: 'hunter2'}, (err, bot) => {
if (err) throw new Error(err);
});
// Facebook
new PlugAPI({
facebook: {
userID: 'xxxxxxxx',
accessToken: 'xxxxxx'
}
}, (err, bot) => {
if (err) throw new Error(err);
});
// Guest
new PlugAPI({ guest: true }, (err, data) => {
if (err) throw new Error(err);
]});
(Object)
: Room ranks
ROOM_ROLE.NONE
Number
Room role of 0. User has no role.
ROOM_ROLE.RESIDENTDJ
Number
Room role of 1000. User is a resident DJ.
ROOM_ROLE.BOUNCER
Number
Room role of 2000. User is a bouncer.
ROOM_ROLE.MANAGER
Number
Room role of 3000. User is a manager.
ROOM_ROLE.COHOST
Number
Room role of 4000. User is a cohost.
ROOM_ROLE.HOST
Number
Room role of 5000. User is a host.
(Object)
: Global Ranks
GLOBAL_ROLES.NONE
Number
Global role of 0. No global role set.
GLOBAL_ROLES.PLOT
Number
Global role of 750. PLOT members.
GLOBAL_ROLES.VOLUNTEER
Number
Global role of 2000. Currently none are set as this.
GLOBAL_ROLES.MODERATOR
Number
Global role of 25000. Site Moderators.
GLOBAL_ROLES.AMBASSADOR
Number
Global role of 3000. Brand Ambassador role.
GLOBAL_ROLES.LEADER
Number
Global role of 4000. Currently none are set as this.
GLOBAL_ROLES.ADMIN
Number
Global role of 5000. Admin global role.
(Object)
: Ban Reasons
BAN_REASON.SPAMMING_TROLLING
Number
Reason 1. Reason is "Spamming or Trolling".
BAN_REASON.VERBAL_ABUSE
Number
Reason 2. Reason is "Verbal abuse or offensive language".
BAN_REASON.OFFENSIVE_MEDIA
Number
Reason 3. Reason is "Playing offensive videos/songs".
BAN_REASON.INAPPROPRIATE_GENRE
Number
Reason 4. Reason is "Repeatedly playing inappropriate genre(s)".
BAN_REASON.NEGATAIVE_ATTITUDE
Number
Reason 5. Reason is "Negative Attitude".
(Object)
: Mute Reasons
MUTE_REASON.VIOLATING_COMMUNITY_RULES
Number
Reason 1. Reason is "Violating community rules".
MUTE_REASON.VERBAL_ABUSE
Number
Reason 2. Reason is "Verbal abuse or harassment".
MUTE_REASON.SPAMMING_TROLLING
Number
Reason 3. Reason is "Spamming or trolling".
MUTE_REASON.OFFENSIVE_LANGUAGE
Number
Reason 4. Reason is "Offensive Language".
MUTE_REASON.NEGATIVE_ATTITUDE
Number
Reason 5. Reason is "Negative attitude"
(Object)
: WaitList Ban Reasons
WLBAN_REASON.SPAMMING_TROLLING
Number
Reason 1. Reason is "Spamming or Trolling".
WLBAN_REASON.VERBAL_ABUSE
Number
Reason 2. Reason is "Verbal abuse or offensive language".
WLBAN_REASON.OFFENSIVE_MEDIA
Number
Reason 3. Reason is "Playing offensive videos/songs".
WLBAN_REASON.INAPPROPRIATE_GENRE
Number
Reason 4. Reason is "Repeatedly playing inappropriate genre(s)".
WLBAN_REASON.NEGATAIVE_ATTITUDE
Number
Reason 5. Reason is "Negative Attitude".
Prefix that defines if a message is a command. Default is !
Type: String
Should the bot split messages up if the message length limit is reached?
Type: Boolean
The maximum number of messages sent after splitting the message.
Type: Number
Should the bot process commands the bot itself is sending?
Type: Boolean
Should the bot be able to delete all chat regardless of role? Note: This will NOT delete gRole chat.
Type: Boolean
Should muted users trigger normal events?
Type: Boolean
Pre-command Handler
(Object?)
An object used to pre process commands
Boolean
:
If false, the command is not getting handled.
// this prevents anyone without the user id of 1234567 from running a command. There are also other things a user can do such as cooldowns per command.
bot.preCommandHandler((data) => {
if (data && data.from && !Object.is(data.from.id, 1234567)) return false;
})
Connect to a room
bot.connect('plugcubed');
Get information about the booth such as who's DJing, if booth is locked, cycle is enabled, DJs in waitList
(Boolean)
: True if waitlist is locked. False if not.
(Boolean)
: True if dj cycle is enabled. False if not
Object
:
An object of booth metadata.
bot.getBoothMeta();
Get the currently playing media. Null if there isn't
(String)
: The song's author
(String)
: The unique id of the song that is used for YouTube or SoundCloud playback.
(Number)
: Time in seconds of how long the song is.
(Number)
: 1 if the song is YouTube. 2 if SoundCloud
(String)
: A url to a thumbnail image of the song on YouTube or SoundCloud
(String)
: The song's title.
(Object | null)
:
Null if nothing is playing, or an object of the song info.
bot.getMedia();
Get the room's metadata
(String)
: The room's description.
(boolean)
: If the bot has favorited the room.
(Number)
: The amount of guests in the room.
(Number)
: The room host's ID.
(Number)
: The room host's username.
(Number)
: The room's ID.
(Number)
: The minimum chat level set in the room for users to chat.
(String)
: The room's name
(Boolean)
: If the room is categorized as nsfw (18+, suggestive images, etc)
(Number)
: the amount of users in the room.
(String)
: The room's welcome message.
Object
:
an object of the room's metadata.
bot.getRoomMeta();
Get the current room score fot the song playing.
(Number)
: Amount of grabs for song.
(Number)
: Amount of people listening to song.
(Number)
: Amount of mehs for song.
(Number)
: Amount of woots for song.
Object
:
An object with the listeners, and the amount of votes / grabs on the song.
bot.getRoomScore();
Adds bot to waitList.
(RESTCallback)
Callback function
Boolean
:
If the REST request got queued
bot.joinBooth();
Removes bot from waitList.
(RESTCallback)
Callback function
Boolean
:
If the REST request got queued
bot.leaveBooth();
Send a chat message
(String)
Message
(int?)
If set, auto deletes the message after x seconds. (Needs to have modChat permission)
// without timeout
bot.sendChat('Hello world!');
// with timeout. Will delete after 5 seconds.
bot.sendChat('Hello world!', 5)
Get all available avatars
(RESTCallback)
Callback function
Boolean
:
If the REST request got queued
bot.getAvatars((err, data) => console.log(err, data));
Set avatar Be sure you only use avatars that are available PlugAPI#getAvatars
(String)
Avatar ID
(RESTCallback)
Callback function
Boolean
:
If the REST request got queued
bot.setAvatar('classic07');
Get all staff for the community, also offline.
(RESTCallback)
Callback function
bot.getAllStaff((err, data) => console.log(err, data));
Implementation of plug.dj haveRoomPermission method
Boolean
:
True if user has permission specified, false if not
// is user bouncer or above?
bot.havePermission(123456, PlugAPI.ROOM_ROLE.BOUNCER);
// is user a BA or admin?
bot.havePermission(123456, PlugAPI.ROOM_ROLE.BOUNCER, true);
Woot current song
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.woot();
Meh current song
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.meh();
Grab current song
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.grab();
Activate a playlist
(Number)
Playlist ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.activatePlaylist(123456);
Add a song to a playlist
(Number)
Playlist ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.addSongToPlaylist(123456, [{cid: '789abc', format: 1, image: 'https://i.ytimg.com/blah', duration: 300, title: 'My song', author: 'My song author'}])
Removes a media from a playlist
(Number)
Playlist ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.removeSongFromPlaylist(1233456, 789abc);
Create a new playlist
(String)
Name of new playlist
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queue
bot.createPlaylist('Swag');
Delete a playlist
(Number)
Playlist ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.deletePlaylist(123456);
Get all medias in playlist
(Number)
Playlist ID
(RESTCallback)
Callback function
const playlistMedias = bot.getPlaylistMedias(123456);
Move a media in a playlist
(Number)
Playlist ID
(Number)
Move them before this media ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
Shuffle playlist
(Number)
Playlist ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.shufflePlaylist(123456);
Add a DJ to Waitlist/Booth
(Number)
User ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateAddDJ(123456);
Ban a user from the community
(Number)
User ID
(Number?)
Reason ID
(String?)
Duration of the ban
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
// Note for the reason / time you can either use bot. or PlugAPI.
bot.moderateBanUser(123456, bot.BAN_REASON.SPAMMING_TROLLING, bot.BAN.PERMA);
Delete a chat message
(String)
Chat ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateDeleteChat('123456-78910');
Skip current media
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateForceSkip();
Skip self
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.selfSkip();
Move a DJ in the waitList
(Number)
User ID
(Number)
New position in the waitList
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateMoveDJ(123456, 1);
Mute user
(Number)
User ID
(Number?)
Reason ID
(String?)
Duration ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
// Note for the reason / time you can either use bot. or PlugAPI.
bot.moderateMuteUser(123456, bot.MUTE._REASON.VIOLATING_COMMUNITY_RULES, bot.MUTE.LONG);
Remove a DJ from Waitlist/Booth
(Number)
User ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateRemoveDJ(123456);
Set the role of a user
Boolean
:
If the REST request got queued
// Note for the role you can either use bot. or PlugAPI.
bot.moderateSetRole(123456, bot.ROOM_ROLE.BOUNCER);
Ban a user from the WaitList
(Number)
User ID
(Number?)
Reason ID
(String?)
Duration of the ban
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
// Note for the reason / time you can either use bot. or PlugAPI.
bot.moderateWaitListBan(123456, bot.BAN_REASON.SPAMMING_TROLLING, bot.BAN.PERMA);
Unban a user
(Number)
User ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateUnbanUser(123456);
Unban a user from the WaitList
(Number)
User ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateWaitListUnban(123456);
Unmute a user
(Number)
User ID
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.moderateUnmuteUser(123456);
Change the name of the community
(String)
New community name
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.changeRoomName('Yolo Swag');
Change the chat level of the community
(Number)
The chat level to set to
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.changeRoomChatLevel(3);
Change the description of the community
(String)
New community description
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.changeRoomDescription('My room is better than yours. #420');
Change the welcome message of the community
(String)
New community welcome
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
// Both %u and %r are automatically replaced by plug to the welcomed user's username and the room's name.
bot.changeRoomWelcome('Welcome %u to %r');
Change the DJ cycle of the community
(Boolean)
True if DJ Cycle should be enabled, false if not.
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.changeDJCycle(false);
Set your badge. Be sure you only use badges that are available PlugAPI#getBadges
(String)
The badgeID to set.
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.setBadge('raveb02');
Get all available badges
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
bot.getBadges((err, data) => { console.log(err, data); });
Lock/Clear the waitList/booth
(Boolean)
Lock the waitList/booth
(Boolean)
Clear the waitList
(RESTCallback?)
Callback function
Boolean
:
If the REST request got queued
// PlugAPI has an alias function moderateLockWaitList. Both work the same
// To lock and not clear
bot.moderateLockBooth(true, false);
// To lock and clear
bot.moderateLockBooth(true, true);
// to unlock
bot.moderateLockBooth(false, false);
This is emitted when the bot is banned.
This is emitted when a user is muted
bot.on(PlugAPI.events.MODERATE_MUTE, (data) => {
console.log(`${data.moderator.username} has ${!Object.is(data.duration, 'Unmuted') ? `muted ${data.user} - ${data.duration}` : `unmuted ${data.user}`}`);
});
This is emitted when the room welcome message has changed.
bot.on(PlugAPI.events.ROOM_WELCOME_UPDATE, (data) => {
console.log(`${data.user.username} changed the room welcome message to ${data.welcome}`);
});
This is emitted when the song has changed to another one.
(Object)
: The advance event object
data.currentDJ
User
The current DJ that is playing.
data.media
Object
Info about the currently playing media.
data.lastPlay
Object
Information about the previously played song. This includes the DJ, Score, Media.
data.playlistID
Number
The bot's current active playlist as an ID
data.startTime
String
When the song started playing.
data.historyID
String
the song's ID in history
bot.on(PlugAPI.events.ADVANCE, (data) => { });
This is emitted when a user votes on the song (Undecided, Meh, Woot)
bot.on(PlugAPI.events.VOTE, (data) => { *
if (Object.is(data.vote, 1)) {
console.log(`${data.user.username} Wooted`);
} else if (Object.is(data.vote, -1)) {
console.log(`${data.user.username} Mehed`);
} else if (Object.is(data.vote, 0)) {
console.log(`${data.user.username} hasn't voted`);
}
})
This is emitted when the bot connects to plug more than once.
This is emitted when someone grabs a song.
bot.on(PlugAPI.events.GRAB, (data) => {*
console.log(`${data.user.username} grabbed the currently playing song`)
});
This is emitted when someone gifts the bot Plug Points.
This is emitted when the bot earns XP or Plug Points
bot.on(PlugAPI.events.EARN, (data) => {
console.log(`You are currently level ${data.level} with: ${data.pp} PP and ${data.xp} XP `);
});
This is emitted when the waitList has changed.
This is emitted when the dj waitList has been locked, cleared, or unlocked.
bot.on(PlugAPI.events.DJ_LIST_LOCKED, (data) => {
console.log(`${data.user.username} ${data.locked ? 'Locked' : 'Unlocked'} the waitList and ${data.clear ? 'Did' : "didn't"} clear the waitList`);
});
This is emitted when the dj cycle is enabled or disabled
bot.on(PlugAPI.events.DJ_LIST_CYCLE, (data) => {
console.log(`${data.user.username} ${data.cycle? 'Enabled' : 'Disabled'} the DJ Cycle `);
});
This is emitted when a user is banned from waitList.
bot.on(PlugAPI.events.MODERATE_WLBAN, (data) => {
console.log(`${data.moderator.username} banned ${data.user} from the waitList ${data.duration}`);
});
This is emitted when a chat message starting with the PlugAPI#commandPrefix is received
(Object)
: The chat data Object
data.id
String
The chat id of the message.
data.command
String
The command message.
data.message
String
The chat message.
data.args
(Array<User> | Array<String>)
An array of strings / user objects after the command.
data.from
User
The user object of the message sender
data.raw
Object
The raw data object from plug.dj. Not changed by PlugAPI
data.mentions
Array<User>
An array of mentioned users.
data.muted
Boolean
If the user is muted.
data.type
String
The message type (mention, emote, messaage)
data.isFrom
Function
Checks if the message sender is from the inputted array of IDs or ID
data.respond
Function
Sends a message specified and mentions the command user.
data.respondTime
Function
Same as data.respond, except it has an additional parameter to delete the message after specified amount of time in seconds.
data.havePermission
Function
Checks if command user has specified permission or above.
bot.on('command:ping', (data) => {
data.respond('Pong!');
});
bot.on('command:add', (data) => {
// check for bouncer or above permissions.
if (data.havePermission(PlugAPI.ROOM_ROLE.BOUNCER)) {
// check if a user was mentioned and is not in waitList
if (data.args[0] && data.args[0].id && (Object.is(bot.getWaitListPosition(data.args[0].id, -1)) || (bot.getDJ() && bot.getDJ().id && !Object.is(bot.getDJ().id, data.args[0].id)))) {
bot.moderateAddDJ(data.args[0].id, () => {
data.respond(`Added ${data.args[0].username} to waitList`);
});
}
}
});
bot.on('command:skip', (data) => {
if (data.havePermission(PlugAPI.ROOM_ROLE.BOUNCER)) {
bot.moderateForceSkip(()=> {
data.respond('Song Skipped.');
});
}
});
This is emitted when the chat level has been updated.
bot.on(PlugAPI.events.CHAT_LEVEL_UPDATE, (data) => {
console.log(`${data.user.username} updated the chat level to ${data.level}`);
});
This is emitted when a chat message starting with /em or /me has been received.
This is emitted when a chat message has been deleted.
bot.on(PlugAPI.events.CHAT_DELETE, (data) => {
const user = bot.getUser(mi);
console.log(`${user.username} deleted message: ${data.c}`);
});
This is emitted when a chat message starting with the PlugAPI#commandPrefix is received.
This is emitted when a chat message has been received.
(Object)
: The chat data Object
data.id
String
The chat id of the message.
data.message
String
The chat message.
data.from
User
The user object of the message sender
data.raw
Object
The raw data object from plug.dj. Not changed by PlugAPI
data.mentions
Array<User>
An array of mentioned users.
data.muted
Boolean
If the user is muted.
data.type
String
The message type (mention, emote, message)
bot.on(PlugAPI.events.CHAT, function(data) {
console.log(`[${data.id}] [${data.from.username}] ${data.message}`);
});
This is emitted when a bouncer or above skips a song
bot.on(PlugAPI.events.MODERATE_SKIP, (data) => {
console.log(`${data.user.username} Skipped the song`);
})
This is emitted when the room name has changed.
bot.on(PlugAPI.events.ROOM_NAME_UPDATE, (data) => {
console.log(`${data.user.username} changed the room name to ${data.name}`);
});
This event is emitted when staff roles are changed.
bot.on(PlugAPI.events.MODERATE_STAFF, (data) => {
if (data.users.length > 0) {
console.log(`${data.moderator.username} has changed ${data.users.map((item) => {
if (item.user != null) {
return `${item.user.username} to ${item.role}`;
}
})}`);
}
});
This is emitted when a user is banned
bot.on(PlugAPI.events.MODERATE_BAN, (data) => {
console.log(`${data.moderator.username} banned ${data.user} ${data.duration}`);
});
Common callback for all API calls
Type: Function
((null | String))
Error message on error; otherwise null
((null | any))
Data on success; otherwise null
Represents a User. Note that some properties are only shown for the bot only and not other users.
(Object)
Represents a user.
Name | Description |
---|---|
data.avatarID (String | null)
(default null )
|
The user's avatar ID. |
data.badge (String | null)
(default null )
|
The user's badge ID. |
data.blurb (String | null)
(default undefined )
|
The user's blurb from their profile page. |
data.gRole Number
(default 0 )
|
The user's global role (0 if not a BA / Admin) |
data.grab Boolean
(default false )
|
If the user has grabbed a song |
data.id Number
(default -1 )
|
The user's ID. |
data.ignores Array
(default [] )
|
An array of users that are ignored. Only shown for the bot user. |
data.joined String
(default '' )
|
The time a user joined plug.dj as as string. Empty if not provided. |
data.language String
(default null )
|
The user's language. |
data.level Number
(default 1 )
|
The user's level. Only shown for the bot user. |
data.notifications Array
(default [] )
|
The user's notifications. Only shown for the bot user. |
data.pp (Number | null)
(default undefined )
|
The user's Plug Points. Only shown for the bot user. |
data.pw (Boolean | null)
(default undefined )
|
Whether the bot user is signed in via password or not. |
data.rawun String
(default '' )
|
The user's username. |
data.role Number
(default 0 )
|
The user's Role. See PlugAPI.ROOM_ROLE for more info. |
data.silver Boolean
(default false )
|
Whether the user is a silver subscriber or not. |
data.slug (String | null)
(default null )
|
The user's slug to be used in a profile. https://plug.dj/@/slug (only exists for level > 5) |
data.status Number
(default 1 )
|
The user's status. |
data.sub Number
(default 0 )
|
Whether the user is a gold subscriber or not. |
data.username String
(default '' )
|
The user's username with HTML entities decoded. |
data.vote Number
(default 0 )
|
The user's current vote. |
data.xp (Number | null)
(default undefined )
|
The user's XP. Only shown for the bot user. |
(Room)
The specific instance of the Room Class.