tardis-bot/modules/announcer/index.js

26 lines
820 B
JavaScript
Raw Permalink Normal View History

2021-04-05 14:09:36 +00:00
module.exports = function(bot, api) {
bot.on('voiceStateUpdate', async (oldState, newState) => {
if (newState.member.user.bot) return;
if (oldState.channel && newState.channel) return;
const channel = oldState.channel || newState.channel;
if (!channel) return;
if (channel.members.array().length < 2) {
return await api.leaveChannel(channel);
}
await api.joinChannel(channel);
let joined = false;
if (!oldState.channel) {
joined = true;
}
let username = newState.member.displayName;
let str = "";
if (!joined) {
str = username + " left the channel";
} else {
str = username + " joined the channel";
}
api.speak(channel, str);
})
}