discord.js-selfbot-v13/Document/VoiceCall.md

64 lines
1.6 KiB
Markdown
Raw Normal View History

2022-05-21 14:14:59 +00:00
# Setup
- Before you use it, properly initialize the module (`@discordjs/voice` patch)
```js
new Client({
patchVoice: true, // Enable default
})
```
# Usage: Call DM / Group DM
```js
const dmChannel = client.channels.cache.get('id');
/* or
const dmChannel = User.dmChannel || await User.createDM();
*/
const connection = await dmChannel.call();
/* Return @discordjs/voice VoiceConnection */
```
# Play Music using `play-dl`
```js
const connection = await message.member.user.dmChannel.call();
const play = require('play-dl');
const {
createAudioPlayer,
createAudioResource,
2022-05-21 14:26:20 +00:00
NoSubscriberBehavior,
2022-05-21 14:14:59 +00:00
} = require('@discordjs/voice');
2022-08-14 11:43:00 +00:00
const channel = (await (message.member.user.dmChannel || message.member.user.createDM()));
const connection = channel.voiceConnection || await channel.call();
let stream;
if (!args[0]) {
return message.channel.send('Enter something to search for.');
} else if (args[0].startsWith('https://www.youtube.com/watch?v=')) {
stream = await play.stream(args.join(' '));
} else {
const yt_info = await play.search(args, {
limit: 1
});
stream = await play.stream(yt_info[0].url);
}
const resource = createAudioResource(stream.stream, {
2022-05-21 14:14:59 +00:00
inputType: stream.type,
2022-08-14 11:43:00 +00:00
inlineVolume: true,
2022-05-21 14:14:59 +00:00
});
2022-08-14 11:43:00 +00:00
resource.volume.setVolume(0.25);
const player = createAudioPlayer({
2022-05-21 14:14:59 +00:00
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
},
});
2022-08-14 11:43:00 +00:00
let i = setInterval(() => {
const m = channel.voiceUsers.get(message.author.id);
if (m) {
player.play(resource);
connection.subscribe(player);
clearInterval(i);
}
else console.log('waiting for voice connection');
}, 250);
2022-05-21 14:14:59 +00:00
```