-
Notifications
You must be signed in to change notification settings - Fork 117
/
discord.js
30 lines (24 loc) · 1.05 KB
/
discord.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// npm i discord.js @discordjs/opus ffmpeg-static puppeteer puppeteer-stream
// start this script
const { Client } = require("discord.js");
const { launch, getStream } = require("puppeteer-stream");
const client = new Client();
console.log("starting ...");
client.on("ready", () => console.log("bot started: enter !play in a server channel"));
client.on("message", async (message) => {
if (message.content !== "!play") return;
if (!message.member) return message.reply("This command can only be executed on a server");
if (!message.member.voice || !message.member.voice.channel) return message.reply("Join a Voice Channel first");
const browser = await launch({
defaultViewport: {
width: 1920,
height: 1080,
},
});
const connection = await message.member.voice.channel.join();
const page = await browser.newPage();
await page.goto("https://dl5.webmfiles.org/big-buck-bunny_trailer.webm");
const stream = await getStream(page, { audio: true, video: false });
const dispatcher = await connection.play(stream);
});
client.login(process.env.TOKEN);