【问题标题】:How to await to fetch all voice channels with X people in discord.js V12?如何在 discord.js V12 中等待获取 X 人的所有语音频道?
【发布时间】:2021-03-01 10:47:00
【问题描述】:

我正在使用 discord.js V12 制作一个 Discord 机器人。我想发出命令等待以获取 X 人或更多人的所有频道,但我不熟悉等待和获取。到目前为止,这是我的代码:

命令:

    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);
        }
    }

我尝试不等待或获取,但它仍然不起作用,同时给出错误。

感谢您花时间帮助我:)

【问题讨论】:

    标签: javascript node.js async-await fetch discord.js


    【解决方案1】:

    假设您的消息来自公会,您可以使用频道缓存。

    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>
    

    如果您已编辑缓存行为,则需要先获取频道和/或公会,然后再读取它们的属性。你可以这样做,例如:

    const guild = await message.guild.fetch()
    

    【讨论】:

    • 我认为它会起作用,但我还有另一个问题 - 如何将消息作者发送到第一个获取的频道?我试过message.member.voice.setChannel(yourVoiceChannels.first());,但它不起作用并且没有给出错误。
    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 2021-05-04
    • 2019-07-31
    • 2021-11-15
    • 2020-10-30
    • 2021-02-28
    • 2021-01-07
    • 2018-09-24
    相关资源
    最近更新 更多