feat(Voice): implement support for @discordjs/voice (#5402)

This commit is contained in:
Amish Shah
2021-06-09 14:21:19 +01:00
committed by GitHub
parent c4f1c75efa
commit 7b2e12b102
27 changed files with 99 additions and 2395 deletions

View File

@@ -25,6 +25,7 @@ const {
VerificationLevels,
ExplicitContentFilterLevels,
NSFWLevels,
Status,
} = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const SystemChannelFlags = require('../util/SystemChannelFlags');
@@ -1328,6 +1329,35 @@ class Guild extends BaseGuild {
return json;
}
/**
* The voice state adapter for this guild that can be used with @discordjs/voice to play audio in voice
* and stage channels.
* @type {Function}
* @readonly
* @example
* const { joinVoiceChannel } = require('@discordjs/voice');
* const voiceConnection = joinVoiceChannel({
* channelId: channel.id,
* guildId: channel.guild.id,
* adapterCreator: channel.guild.voiceAdapterCreator,
* });
*/
get voiceAdapterCreator() {
return methods => {
this.client.voice.adapters.set(this.id, methods);
return {
sendPayload: data => {
if (this.shard.status !== Status.READY) return false;
this.shard.send(data);
return true;
},
destroy: () => {
this.client.voice.adapters.delete(this.id);
},
};
};
}
/**
* Creates a collection of this guild's roles, sorted by their position and IDs.
* @returns {Collection<Snowflake, Role>}