【问题标题】:DiscordJS v13 Music BotDiscordJS v13 音乐机器人
【发布时间】:2022-01-11 01:35:53
【问题描述】:

我在尝试让我的 discord 机器人播放歌曲时遇到问题。 可以进入语音频道搜索歌曲,但是进去后什么都播放不了,我看播放器的状态,就出来了'buffering'。

    const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, AudioPlayerStatus, NoSubscriberBehavior  } = require('@discordjs/voice');
const { Client, Intents, Interaction } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const ytdl = require('ytdl-core');
const yrS = require('yt-search');
async function vdSearch(cancion){
    const vdE = await yrS(cancion);
    return vdE.videos.length > 0 ? vdE.videos[0] : null;
}

client.on('messageCreate', async(message) =>{
    switch(args[0]){
        case 'play':
            const vdRepro = await vdSearch(args[1]);
            if(!vdRepro){
                message.channel.send("No se ha encontrado esa cancion");
            }else{
                message.channel.send("Reproduciendo: "+ vdRepro.title);
            }
            //CONEXION
            const stream = ytdl(vdRepro.url, { filter:'audioonly' });
            const connection = joinVoiceChannel({
                channelId: message.member.voice.channel.id,
                guildId: message.guild.id,
                adapterCreator: message.guild.voiceAdapterCreator
            })
            var resource = createAudioResource(stream, {inputType:StreamType.Arbitrary,});
            const player = createAudioPlayer({
                behaviors: {
                noSubscriber: NoSubscriberBehavior.Pause,
                },
            });
            player.play(resource);
            connection.subscribe(player);
            console.log(player.state);
            break;
    }
})

有谁知道我该如何解决? 感谢您花时间阅读

【问题讨论】:

    标签: node.js discord.js bots audio-player


    【解决方案1】:

    我建议您使用“Distube”。它非常易于使用,非常适合 Musik Bots。

    https://distube.js.org/#/docs/JS-DisTube/v2/class/DisTube

    例如 Distube 中的 play() 命令是distube.play(message, "searchQuery")

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 2021-12-04
      • 2018-03-27
      • 2021-05-05
      • 2020-11-01
      • 2021-12-16
      • 2020-09-22
      • 2019-04-04
      • 1970-01-01
      相关资源
      最近更新 更多