Add .livestream stop command
This commit is contained in:
parent
fd0aa70556
commit
d8951ebdd7
|
@ -2,13 +2,25 @@ const { DiscordStreamClient } = require('discord-stream-client');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'livestream',
|
name: 'livestream',
|
||||||
description: 'Starts a live stream in a voice channel with a provided video link.',
|
description: 'Starts or stops a live stream in a voice channel with a provided video link.',
|
||||||
async execute(message, args, deleteTimeout) {
|
async execute(message, args, deleteTimeout) {
|
||||||
|
if (args[0] === 'stop') {
|
||||||
|
const voiceState = message.guild.me.voice;
|
||||||
|
if (voiceState.channel) {
|
||||||
|
voiceState.disconnect();
|
||||||
|
return message.channel.send('Livestream stopped.')
|
||||||
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
||||||
|
} else {
|
||||||
|
return message.channel.send('No active livestream to stop.')
|
||||||
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
return message.channel.send('Usage: .livestream <channelId> <videoLink>')
|
return message.channel.send('Usage: .livestream <channelId> <videoLink> | .livestream stop')
|
||||||
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelId = args[0];
|
const channelId = args[0];
|
||||||
const videoLink = args[1];
|
const videoLink = args[1];
|
||||||
const channel = message.client.channels.cache.get(channelId);
|
const channel = message.client.channels.cache.get(channelId);
|
||||||
|
@ -19,17 +31,32 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (message.client.currentPlayer) {
|
||||||
|
message.client.currentPlayer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
const connection = await message.client.streamClient.joinVoiceChannel(channel, {
|
const connection = await message.client.streamClient.joinVoiceChannel(channel, {
|
||||||
selfDeaf: true,
|
selfDeaf: true,
|
||||||
selfMute: true,
|
selfMute: true,
|
||||||
selfVideo: false,
|
selfVideo: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const stream = await connection.createStream();
|
const stream = await connection.createStream();
|
||||||
const player = message.client.streamClient.createPlayer(videoLink, stream.udp);
|
const player = message.client.streamClient.createPlayer(videoLink, stream.udp);
|
||||||
|
message.client.currentPlayer = player;
|
||||||
|
|
||||||
player.on('error', err => console.error(err));
|
player.on('error', err => console.error(err));
|
||||||
|
|
||||||
|
player.on('end', () => {
|
||||||
|
player.play({
|
||||||
|
kbpsVideo: 7000,
|
||||||
|
fps: 60,
|
||||||
|
hwaccel: true,
|
||||||
|
kbpsAudio: 128,
|
||||||
|
volume: 1,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
player.play({
|
player.play({
|
||||||
kbpsVideo: 7000,
|
kbpsVideo: 7000,
|
||||||
fps: 60,
|
fps: 60,
|
||||||
|
|
Loading…
Reference in New Issue