【发布时间】:2019-04-07 22:13:25
【问题描述】:
我遵循了一些教程并获得了一些帮助,但无论我尝试什么,playFile 始终显示错误。该机器人也可以播放音乐,但音乐(通过链接)部分工作正常。那么我将如何播放根文件夹中的音频文件并且仅当有人加入语音频道时?
bot.on('voiceStateUpdate', (oldMember, newMember) => {
// Here I'm storing the IDs of their voice channels, if available
let oldChannel = oldMember.voiceChannel ? oldMember.voiceChannel.id : null;
let newChannel = newMember.voiceChannel ? newMember.voiceChannel.id : null;
if (oldChannel === newChannel) return; // If there has been no change, exit
// Here I'm getting the bot's channel (bot.voiceChannel does not exist)
let botMember = oldMember.guild.member(bot.user),
botChannel = botMember ? botMember.voiceChannel.id : null;
var server = servers[botMember.guild.id];
// Here I'm getting the channel, just replace VVV this VVV with the channel's ID
let textChannel = oldMember.guild.channels.get('438025505615249408');
if (!textChannel) throw new Error("That channel does not exist.");
// Here I don't need to check if they're the same, since it would've exit before
if (newChannel === botChannel) {
// console.log("A user joined.");
server.dispatcher = botMember.voiceConnection.playFile('./audiofile.mp3');
textChannel.send(newMember.displayName + " joined.");
} else if (oldChannel === botChannel) {
// console.log("A user left.");
textChannel.send(newMember.displayName + " left.");
}
});
【问题讨论】:
标签: discord.js