Discord.js 代码在播放本地文件时工作正常,在尝试播放网址时它不会播放任何内容

问题描述 投票:0回答:1


const Discord = require('discord.js');

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents:

  [

      GatewayIntentBits.Guilds,

      GatewayIntentBits.GuildMessages,

      GatewayIntentBits.GuildVoiceStates,

]

});

const config =  require('./config.json');

const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus, StreamType } = require('@discordjs/voice');

const { join } = require('path');

client.once('ready', async() => {

    console.log("connected");

    const channels = client.guilds.cache.find(f => f.name==="<my-guild>").channels;

  let channel= channels.cache.find(r => r.name === "General");

const connection = joinVoiceChannel({

channelId: channel.id,

guildId: channel.guildId,

adapterCreator: channel.guild.voiceAdapterCreator,

});                                                                                                                                         console.log("joined voice channel");

const player = createAudioPlayer();

let resource = createAudioResource("https://streams.ilovemusic.de/iloveradio2.mp3", { inlineVolume: true,

  inputType: StreamType.Arbitrary});

resource.volume.setVolume(1)

connection.subscribe(player);

player.play(resource);

});

client.login(config.token);

上个月运行良好,本月尝试运行它,但通过流听不到任何声音,但本地音频文件运行良好。

期望:Url 应该播放为不和谐的 createAudioResource 支持 url。

主要问题是本地文件可以播放,而远程网址则不能。但没有错误,所以我对如何调试它感到困惑。

javascript discord discord.js voice
1个回答
0
投票

应该是ffmpeg安装的问题,尝试在新机器上运行脚本(安装ffmpeg后),效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.