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

2022-01-10 00:00:00 discord node.js javascript discord.js

我想创建一个命令,移动我的 Discord 语音频道中的所有用户.这是我尝试过的.

I'd like to create a command, that moves all users in my Discord voice channel. Here is what i tried.

...
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"后,我收到以下错误消息:

After I tried to run the command "!movetome" in discord chat I got the following error message:

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

感谢您的帮助:)

推荐答案

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

Firstly this seems like a bad idea if any user can do it but regardless, .setVoiceChannel is v11, they moved it to <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);
});

相关文章