简体   繁体   English

如何在 discord.js 中发出播放命令?

[英]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.

相关问题 我如何在Discord.js中执行“ + mention”命令 - How do I make a “+mention” command in Discord.js 当有人在 Discord.js 中键入未知命令时,如何发出“无效命令”消息? - How do I make an "Invalid Command" message when someone types an unknown command in Discord.js? Discord.js:当有人进入任何频道时,我如何让我的机器人播放音频 - Discord.js : How do i make my bot play an audio when someones enter any channel 我怎样才能使这个命令循环? [不和谐.js] - how can i make this command loop? [Discord.js] Discord.js | 如何创建添加到数组变量的命令? - Discord.js | How do I make a command that adds to an array variable? Discord.js | 我如何制作通过 id 发送到特定频道的命令 - Discord.js | How do i make a command that sends to a specific channel by id discord.js 问题。 我如何让机器人对一个命令给出不同的响应? - discord.js question. how do i make the bot give a different response to one command? 如何使斜杠命令在 dms discord.js v14 中不可用 - How do I make a slash command not usable in dms discord.js v14 如何让某些角色运行 discord.js 命令? - How do I make certain roles run a discord.js command? 如何发出使 discord.js 中的状态发生变化的命令? - How do I make a command that makes the status change in discord.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM