我遵循了一些教程并混合了一些代码,并且可以正常工作,但是无论我如何更改它,我都很难理解 message.guild.channels.forEach 的异步方式。< / p>
我希望漫游器仅加入用户键入“ test”的语音通道,而不在所有语音通道上运行。
谢谢
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'
}
答案 0 :(得分:1)
如果您希望漫游器加入发送命令的用户的语音通道,请使用以下命令:
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