【问题标题】:How do I make a play command in discord.js?如何在 discord.js 中创建播放命令?
【发布时间】:2021-05-16 14:21:26
【问题描述】:

我想知道如何制作播放命令。我让它加入语音频道,但它不会播放任何音乐。

代码如下:

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());
        });
    }
});

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    安装 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());
                });
            }
        });
    
    

    编辑:还要确保你安装了 ffmpeg 和 opusscript

    【讨论】:

    • 没有用。刚刚连接但没有播放任何东西。
    • 您使用的是什么操作系统?你有安装 ffmpeg 和 opusscript 吗?
    • 很遗憾,我使用的是 chromebook,所以我使用了repl.it IDE。我不知道
    • 转到repl.it的shell并使用npm i ffmpeg-static opusscript安装ffmpeg-static和opusscript
    • 我尝试在 repl.it 中复制您的机器人并使其工作。我把link放在这里以防你想检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2022-10-22
    • 1970-01-01
    • 2020-03-12
    • 2023-04-03
    相关资源
    最近更新 更多