将所有用户移至您的频道(Discord JS)

时间:2020-06-14 20:47:04

标签: javascript node.js discord discord.js

我想创建一个命令,该命令将所有用户移动到Discord语音通道中。 这是我尝试过的。

...
client.on('message', async message =>{
    //Check message is not Bot
    if(message.author.bot) return;
    if(message.content=="!movetome"){

        if(message.member.voice.channel) {//Is user in voicechannel

            message.guild.members.cache.forEach(member => { //Loop every user
                if(member.id!=message.member.id&&member.voice.channel){//Is user in voicechannel and is user the command executer
                    member.setVoiceChannel(message.member.voice.channel)//Sets user to channel
                }
            });
        }
    }
});
...

尝试在不和谐聊天中运行命令“!movetome”后,出现以下错误消息:

(node:12268) UnhandledPromiseRejectionWarning: TypeError: member.setVoiceChannel is not a function

感谢您的帮助:)

1 个答案:

答案 0 :(得分:2)

首先,如果任何用户都可以这样做,这似乎是一个坏主意,但是无论.setVoiceChannel是v11,他们都将其移至<GuildMember>.voice.setChannel()

if(message.content=="!movetome")内的内容更改为此

const channel = message.member.voice.channel;
message.guild.members.cache.forEach(member => {
  //guard clause, early return
  if(member.id === message.member.id || !member.voice.channel) return;
  member.voice.setChannel(channel);
});