首页 > 解决方案 > 我如何自动将某人移回频道?

问题描述

所以,基本上我有一些代码设置,我没有看到代码的问题。但基本上我想要它做的是,如果切换频道的成员之前的语音频道是“请勿打扰”,它会将他们移回“请勿打扰”语音频道。我做错了什么?我在控制台中收到 0 个错误。

    client.on('voiceStateUpdate', async (oldState, newState) => {
        let newUserChannel = newState.channel;
        let oldUserChannel = oldState.channel;

       if(oldUserChannel.id === "894024223088050176") {
                    var dndChannel = oldState.guild.channels.cache.find(ch => ch.type === "voice" && ch.name === "DO NOT DISTURB")
                    newState.member.voice.setChannel(dndChannel)
                }
      });

标签: javascriptnode.jsdiscord.js

解决方案


仔细检查 if 条件中的 channelid 是否正确并使用

Guild.channels.fetch(channelId)

安装的Guild.channels.cache.find()


推荐阅读