[英]How do I make a play command in discord.js?
I want to know how to make a play command.我想知道如何制作播放命令。 I got it to join the Voice Channel, but it will not play any music.
我得到它加入语音频道,但它不会播放任何音乐。
Here's the code:这是代码:
client.on("message", (message) => {
if (message.content.startsWith("!play")) {
const ytdl = require("ytdl-core");
message.member.voice.channel.join().then((connection) => {
const stream = ytdl(args[1], { filter: "audioonly" });
const dispatcher = connection.play(stream);
dispatcher.on("finish", () => voiceChannel.leave());
});
}
});
Install discord-ytdl-core instead of ytdl-core and try the below code安装discord-ytdl-core而不是 ytdl-core 并尝试以下代码
client.on("message", (message) => {
if (message.content.startsWith("!play")) {
const ytdl = require("discord-ytdl-core");
const args = message.content.trim().split(' ');
message.member.voice.channel.join().then((connection) => {
const stream = ytdl(args[1], { filter: "audioonly",opusEncoded: true });
const dispatcher = connection.play(stream, { type: "opus" }).on("finish", () => connection.disconnect());
});
}
});
Edit: also make sure you have ffmpeg and opusscript installed编辑:还要确保您安装了 ffmpeg 和 opusscript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.