Created
October 19, 2018 04:40
-
-
Save intercaetera/8fb1092ee36343ea679c1bf6c9f7119e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = require('./config') | |
const Discord = require('discord.js') | |
const client = new Discord.Client() | |
const owner = "93034899488899072" | |
client.on('ready', () => { | |
console.log('This voice bar thing ready') | |
}) | |
client.on('message', msg => { | |
if(msg.author.id != owner) return | |
if(msg.content.startsWith('ping')) { | |
msg.reply('pong') | |
} | |
}) | |
client.on('voiceStateUpdate', async (before, after) => { | |
const guild = after.guild | |
if(guild.id != '444793783259889676' && guild.id != '311805678324940821') return | |
const beforeName = before.voiceChannel ? before.voiceChannel.name : undefined | |
const afterName = after.voiceChannel ? after.voiceChannel.name : undefined | |
if(beforeName === afterName) return | |
if(beforeName) { | |
// If role doesn't exist, create role. | |
let foundRole = guild.roles.find('name', beforeName) | |
if(!foundRole) { | |
let role = await guild.createRole({ | |
name: beforeName, | |
color: 'WHITE' | |
}) | |
const textChannel = guild.channels.find('name', beforeName+'-text') | |
if(role && textChannel) { | |
assignPermissions(role, textChannel) | |
foundRole = role | |
console.log('Created role', role.name) | |
} | |
} | |
//Remove role from user who just left | |
before.removeRole(foundRole) | |
console.log('Removed', foundRole.name, 'from user', before.displayName) | |
} | |
if(afterName) { | |
let foundRole = guild.roles.find('name', afterName) | |
after.addRole(foundRole) | |
console.log('Added', foundRole.name, 'to user', after.displayName) | |
} | |
}) | |
function assignPermissions(role, channel) { | |
channel.overwritePermissions(role, { | |
VIEW_CHANNEL: true, | |
SEND_MESSAGES: true | |
}) | |
.catch(console.error) | |
} | |
client.login(config.token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment