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应该播放,因为discorde createAudioResource支持URL.
主要的问题是本地文件播放,而远程URL不播放.虽然没有错误,所以我对如何调试它感到困惑.