简体   繁体   English

如何在discord.js V12中等待获取X人的所有语音频道?

[英]How to await to fetch all voice channels with X people in discord.js V12?

I am making a Discord bot with discord.js V12.我正在使用 discord.js V12 制作一个 Discord 机器人。 I want to make a command to await to fetch all channels with X people or more, but I am not familiar with awaiting and fetching.我想发出一个命令等待获取 X 人或更多人的所有频道,但我不熟悉等待和获取。 Here is my code so far:到目前为止,这是我的代码:

Command:命令:

    else if (command === 'find') {
        if (!args.length) {
            const findHelp = new Discord.MessageEmbed()
            .setTitle('Finding')
            .setDescription('Help')
            .addField('Usage', 'Find a free spot on a voice channel & automaticly join for best Among Us experience!')
            .addField('Commands', '`/find <members>` Find a voice channel with minimum of `<members>` people in it.')
            .setColor(0xE92323);
            message.channel.send(findHelp);
        } else if (args.length === 1) {
            const memberMin = args[0];
            const channel = await (fetch(channels.first.members.length(memberMin)))
            message.author.join(channel);
        }
    }

I tried without awaiting or fetching but it still doesn't work, while giving an error.我尝试了没有等待或获取但它仍然不起作用,同时给出错误。

Thanks for taking your time to help me :)感谢您抽出宝贵时间帮助我:)

Assuming your message comes from a guild, you can use the channel cache.假设您的消息来自公会,您可以使用频道缓存。

const memberMin = args[0]
const voiceChannels = message.guild.channels.cache.filter(c => c.type == 'voice') // Collection<VoiceChannel>

const yourVoiceChannels = voiceChannels.filter(c => c.members.length >= memberMin) // Collection<VoiceChannel>

If you've edited the caching behavior, you'll need to fetch the channels and/or the guild before reading their properties.如果您编辑了缓存行为,则需要在读取通道和/或公会的属性之前获取它们。 You can do that with, for example:你可以这样做,例如:

const guild = await message.guild.fetch()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM