[英]DiscordJS Play audio file on voice channel
我遵循了一些教程並混合了一些代碼並且它可以工作,但是無論我如何改變它,我都很難理解與message.guild.channels.forEach的異步。
我希望機器人只加入用戶輸入“測試”的語音通道,而不在所有語音通道上運行。
謝謝你
exports.run = async (client, message, args, level) => {
async function play(channel) {
await channel.join().then(async (connection) => {
let dispatcher = await connection.playFile('./img/aniroze.mp3');
await dispatcher.on('end', function () {
message.channel.send("🎧 **x** 🎧").then(sentEmbed => {
sentEmbed.react("👍")
sentEmbed.react("👎")
channel.leave();});
});
});
}
let timer = 10000;
message.guild.channels.forEach(async (channel) => {
if (channel.type == 'voice' && channel.members.size > 1) {
const embed2 = new Discord.RichEmbed()
.setTitle('🎧 🎧')
.setColor("#3498DB")
.setThumbnail(`${message.author.displayAvatarURL}`)
.setTimestamp()
message.channel.send(embed2);
setTimeout(function () {
play(channel);
}, timer);
}});
setTimeout(function () {
}, timer);
};
exports.conf = {
enabled: true,
aliases: ['test'],
guildOnly: true,
permLevel: 'User'
}
如果您希望機器人加入發送命令的用戶的語音頻道,請使用以下命令:
const voiceChannel = message.member.voiceChannel
if (!voiceChannel) return message.reply('you are not in a voice channel')
voiceChannel.join()
注意:這是 discord.js v11 答案,對於 v12 將member.voiceChannel
替換為member.voice.channel
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.