2024-02-05 22:38:13 -05:00
|
|
|
const { DiscordStreamClient } = require('discord-stream-client');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'livestream',
|
2024-02-05 23:07:41 -05:00
|
|
|
description: 'Starts or stops a live stream in a voice channel with a provided video link.',
|
2024-02-05 22:38:13 -05:00
|
|
|
async execute(message, args, deleteTimeout) {
|
2024-02-05 23:07:41 -05:00
|
|
|
if (args[0] === 'stop') {
|
2024-02-06 00:17:15 -05:00
|
|
|
if (message.client.voiceConnection) {
|
|
|
|
message.client.voiceConnection.disconnect();
|
|
|
|
message.client.voiceConnection = null;
|
|
|
|
|
|
|
|
if (message.client.currentPlayer) {
|
|
|
|
message.client.currentPlayer.stop();
|
|
|
|
message.client.currentPlayer.removeAllListeners('end');
|
|
|
|
message.client.currentPlayer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return message.channel.send('Livestream stopped.').then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
2024-02-05 23:07:41 -05:00
|
|
|
} else {
|
2024-02-06 00:17:15 -05:00
|
|
|
return message.channel.send('No active livestream to stop.').then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
2024-02-05 23:07:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-05 22:38:13 -05:00
|
|
|
if (args.length < 2) {
|
2024-02-05 23:07:41 -05:00
|
|
|
return message.channel.send('Usage: .livestream <channelId> <videoLink> | .livestream stop')
|
2024-02-05 22:38:13 -05:00
|
|
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
|
|
|
}
|
2024-02-05 23:07:41 -05:00
|
|
|
|
2024-02-05 22:38:13 -05:00
|
|
|
const channelId = args[0];
|
|
|
|
const videoLink = args[1];
|
|
|
|
const channel = message.client.channels.cache.get(channelId);
|
|
|
|
|
|
|
|
if (!channel) {
|
|
|
|
return message.channel.send('Channel not found.')
|
|
|
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
|
|
|
}
|
|
|
|
|
2024-02-05 23:42:20 -05:00
|
|
|
const voiceState = message.guild.members.me.voice;
|
|
|
|
if (voiceState.channel) {
|
|
|
|
console.log('Already in a voice channel, leaving...');
|
|
|
|
await voiceState.disconnect();
|
|
|
|
}
|
|
|
|
|
2024-02-05 22:38:13 -05:00
|
|
|
try {
|
2024-02-05 23:07:41 -05:00
|
|
|
if (message.client.currentPlayer) {
|
|
|
|
message.client.currentPlayer.stop();
|
|
|
|
}
|
|
|
|
|
2024-02-05 22:38:13 -05:00
|
|
|
const connection = await message.client.streamClient.joinVoiceChannel(channel, {
|
|
|
|
selfDeaf: true,
|
|
|
|
selfMute: true,
|
|
|
|
selfVideo: false,
|
|
|
|
});
|
2024-02-05 23:07:41 -05:00
|
|
|
|
2024-02-05 22:38:13 -05:00
|
|
|
const stream = await connection.createStream();
|
|
|
|
const player = message.client.streamClient.createPlayer(videoLink, stream.udp);
|
2024-02-05 23:07:41 -05:00
|
|
|
message.client.currentPlayer = player;
|
2024-02-05 22:38:13 -05:00
|
|
|
|
|
|
|
player.on('error', err => console.error(err));
|
2024-02-05 23:07:41 -05:00
|
|
|
|
2024-02-05 23:25:44 -05:00
|
|
|
const playStream = () => {
|
|
|
|
player.play(videoLink, {
|
2024-02-05 23:07:41 -05:00
|
|
|
kbpsVideo: 7000,
|
|
|
|
fps: 60,
|
|
|
|
hwaccel: true,
|
|
|
|
kbpsAudio: 128,
|
|
|
|
volume: 1,
|
|
|
|
});
|
2024-02-05 23:25:44 -05:00
|
|
|
};
|
2024-02-05 23:07:41 -05:00
|
|
|
|
2024-02-05 23:25:44 -05:00
|
|
|
player.on('finish', () => {
|
|
|
|
console.log('Media ended, replaying...');
|
2024-02-05 23:42:20 -05:00
|
|
|
playStream();
|
2024-02-05 22:38:13 -05:00
|
|
|
});
|
|
|
|
|
2024-02-05 23:42:20 -05:00
|
|
|
playStream();
|
2024-02-05 23:25:44 -05:00
|
|
|
|
2024-02-05 22:38:13 -05:00
|
|
|
message.channel.send('Livestream started with the provided video link.')
|
|
|
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
message.channel.send('Failed to start the livestream.')
|
|
|
|
.then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|