Untitled
unknown
javascript
2 years ago
1.1 kB
77
Indexable
const whitelist = []; // whitelist (everyone if empty)
const CMD = '>play'; // prefix
const audioCommandsMessageHandler = {
Description: 'Audio commands listener',
Priority: -1,
Callback: (data, sender, msg) => {
// Check if whisper and sender authorized
// data.Types: "Whisper" | "Chat" | "Emote" | "Action"
if (data.Type == "Whisper" && (whitelist.length == 0 || whitelist.includes(sender.MemberNumber))) {
// Check if command
if (!msg.startsWith(CMD))
return false;
// Get sound name from message
let soundName = msg.split(' ')[1];
// Play audio
let played_audio = AudioPlaySoundEffect(soundName, 100);
// Return value is true if audio played, false otherwise. Act accordingly.
if (!played_audio)
console.log('Audio didn\'t exist:', soundName);
}
// false to not stop further processing
return false;
}
};
// Register the message handler with BC
ChatRoomRegisterMessageHandler(audioCommandsMessageHandler);
Editor is loading...
Leave a Comment