From fe06dbab3f892748bb5669b9cab1d148bd5e5d89 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Mon, 5 Feb 2024 22:38:13 -0500 Subject: [PATCH] Livestream command --- commands/livestream.js | 51 ++++++++++++++++++++++++++++++++++++++++++ index.js | 3 +++ 2 files changed, 54 insertions(+) create mode 100644 commands/livestream.js diff --git a/commands/livestream.js b/commands/livestream.js new file mode 100644 index 0000000..8280f11 --- /dev/null +++ b/commands/livestream.js @@ -0,0 +1,51 @@ +const { DiscordStreamClient } = require('discord-stream-client'); + +module.exports = { + name: 'livestream', + description: 'Starts a live stream in a voice channel with a provided video link.', + async execute(message, args, deleteTimeout) { + if (args.length < 2) { + return message.channel.send('Usage: .livestream ') + .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); + } + + 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)); + } + + try { + const connection = await message.client.streamClient.joinVoiceChannel(channel, { + selfDeaf: true, + selfMute: true, + selfVideo: false, + }); + + const stream = await connection.createStream(); + const player = message.client.streamClient.createPlayer(videoLink, stream.udp); + + player.on('error', err => console.error(err)); + + player.play({ + kbpsVideo: 7000, + fps: 60, + hwaccel: true, + kbpsAudio: 128, + volume: 1, + }); + + 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)); + } + }, +}; + diff --git a/index.js b/index.js index b757526..368011b 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,11 @@ require('dotenv').config(); const { Client } = require('discord.js-selfbot-v13'); +const { DiscordStreamClient } = require('discord-stream-client'); const client = new Client(); const fs = require('fs'); +client.streamClient = new DiscordStreamClient(client); + const PREFIX = process.env.PREFIX || '.'; const MESSAGE_DELETE_TIMEOUT = 10000