【问题标题】:How can I redirect user to another channel?如何将用户重定向到另一个频道?
【发布时间】:2020-12-19 18:36:00
【问题描述】:

我希望我的机器人在用户尝试加入任何其他频道时将其移动到指定的语音频道。

据我所知:

client.on('voiceStateUpdate', (oldMember, newMember) => console.log(oldMember));

已被替换为:

client.on('voiceStateUpdate', (oldState, newState) => console.log(oldState));

那么如何才能让加入语音频道的用户返回呢?

【问题讨论】:

    标签: javascript discord discord.js bots


    【解决方案1】:

    您可以使用VoiceStatemember 属性获取加入VoiceChannel 的用户。

    client.on("voiceStateUpdate", (oldState, newState) => {
        const Channel = client.channels.cache.get("ChannelID"); // The channel you want the user to be moved in.
    
        if (!Channel) return console.error("Invalid channel."); // Making sure the channel exists.
    
        if (!newState.channel) return false; // The user was disconnected from a channel.
    
        if (newState.channelID !== Channel.id) { // Checking if the user is in the wanted channel.
            newState.member.voice.setChannel(Channel).catch(error => console.error(error)); // Moving the user to the desired channel.
        };
    });
    

    我真的建议您拒绝 Join Channel 权限而不是这样做。

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 2012-04-05
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      相关资源
      最近更新 更多