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

Move all users to your Channel (Discord JS)(将所有用户移至您的频道 (Discord JS))

本文介绍了将所有用户移至您的频道 (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);
});

这篇关于将所有用户移至您的频道 (Discord JS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将所有用户移至您的频道 (Discord JS)

基础教程推荐