Skip to content

Instantly share code, notes, and snippets.

@niklasbuschmann
Created October 29, 2020 23:32
Show Gist options
  • Save niklasbuschmann/dee06de153f2428639846e63f8df45c0 to your computer and use it in GitHub Desktop.
Save niklasbuschmann/dee06de153f2428639846e63f8df45c0 to your computer and use it in GitHub Desktop.
Discord Chatroulette Bot
const Discord = require('discord.js');
const BOT_TOKEN = /* TOKEN */;
const client = new Discord.Client();
const createChannel = (name, hidden, guild) => guild.channels.create(name, {
type: 'voice',
parent: guild.channels.cache.filter(channel => channel.type === 'category').last(),
permissionOverwrites: hidden && [{
id: guild.roles.cache.findKey(role => role.name === '@everyone'),
deny: ['VIEW_CHANNEL']
}]
});
client.on('guildCreate', guild => {
if (!guild.channels.cache.find(channel => channel.name === 'Enter Chatroulette')) {
createChannel('Enter Chatroulette', false, guild);
}
});
client.on('voiceStateUpdate', (left, joined) => {
if (left.channel && left.channel.name.includes('Chatroulette Channel') && left.channel.members.size === 0) {
left.channel.delete();
}
if (joined.channel && joined.channel.name === 'Enter Chatroulette' && joined.channel.members.size % 2 === 0) {
createChannel('Chatroulette Channel ' + joined.guild.channels.cache.size, true, joined.guild).then(channel => {
joined.channel.members.first(2).forEach(member => member.voice.setChannel(channel));
});
}
});
client.login(BOT_TOKEN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment