discord.js/src/structures/VoiceChannel.js
Schuyler Cebulskie 68acf37fd4 Add stricter/better ESLint config (#589)
* Add stricter/better ESLint config

* Remove more unnecessary @returns
2016-09-03 20:45:23 +01:00

76 lines
1.8 KiB
JavaScript

const GuildChannel = require('./GuildChannel');
const Collection = require('../util/Collection');
/**
* Represents a Server Voice Channel on Discord.
* @extends {GuildChannel}
*/
class VoiceChannel extends GuildChannel {
constructor(guild, data) {
super(guild, data);
/**
* The members in this Voice Channel.
* @type {Collection<string, GuildMember>}
*/
this.members = new Collection();
}
setup(data) {
super.setup(data);
/**
* The bitrate of this voice channel
* @type {number}
*/
this.bitrate = data.bitrate;
/**
* The maximum amount of users allowed in this channel - 0 means unlimited.
* @type {number}
*/
this.userLimit = data.user_limit;
this.type = 'voice';
}
/**
* Sets the bitrate of the channel
* @param {number} bitrate the new bitrate
* @returns {Promise<VoiceChannel>}
* @example
* // set the bitrate of a voice channel
* voiceChannel.setBitrate(48000)
* .then(vc => console.log(`Set bitrate to ${vc.bitrate} for ${vc.name}`))
* .catch(console.log);
*/
setBitrate(bitrate) {
return this.rest.client.rest.methods.updateChannel(this, { bitrate });
}
/**
* Attempts to join this Voice Channel
* @returns {Promise<VoiceConnection, Error>}
* @example
* // join a voice channel
* voiceChannel.join()
* .then(connection => console.log('Connected!'))
* .catch(console.log);
*/
join() {
return this.client.voice.joinChannel(this);
}
/**
* Leaves this voice channel
* @example
* // leave a voice channel
* voiceChannel.leave();
*/
leave() {
const exists = this.client.voice.connections.get(this.guild.id);
if (exists) {
if (exists.channel.id === this.id) {
exists.disconnect();
}
}
}
}
module.exports = VoiceChannel;