docs: Update example (Voice)
This commit is contained in:
parent
04a0112ff0
commit
d54089279d
@ -28,15 +28,36 @@ const {
|
|||||||
createAudioResource,
|
createAudioResource,
|
||||||
NoSubscriberBehavior,
|
NoSubscriberBehavior,
|
||||||
} = require('@discordjs/voice');
|
} = require('@discordjs/voice');
|
||||||
let stream = await play.stream('youtube link');
|
const channel = (await (message.member.user.dmChannel || message.member.user.createDM()));
|
||||||
let resource = createAudioResource(stream.stream, {
|
const connection = channel.voiceConnection || await channel.call();
|
||||||
inputType: stream.type,
|
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
|
||||||
});
|
});
|
||||||
let player = createAudioPlayer({
|
stream = await play.stream(yt_info[0].url);
|
||||||
|
}
|
||||||
|
const resource = createAudioResource(stream.stream, {
|
||||||
|
inputType: stream.type,
|
||||||
|
inlineVolume: true,
|
||||||
|
});
|
||||||
|
resource.volume.setVolume(0.25);
|
||||||
|
const player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
noSubscriber: NoSubscriberBehavior.Play,
|
noSubscriber: NoSubscriberBehavior.Play,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
let i = setInterval(() => {
|
||||||
|
const m = channel.voiceUsers.get(message.author.id);
|
||||||
|
if (m) {
|
||||||
player.play(resource);
|
player.play(resource);
|
||||||
connection.subscribe(player);
|
connection.subscribe(player);
|
||||||
|
clearInterval(i);
|
||||||
|
}
|
||||||
|
else console.log('waiting for voice connection');
|
||||||
|
}, 250);
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user