如何将成员移至其他频道

时间:2020-08-05 06:34:12

标签: node.js discord discord.js

因此,我一直在寻找如何制作将某人移至其他频道的命令,但是他们使用名为.setVoiceChannel的命令,但我找不到它吗?我知道这可能是一个菜鸟问题。

这是我目前拥有的

const user = message.author.id;
const member = message.guild.member(user);

// what a I trying to do
member.setVoiceChannel(/* them parameters */); // not defined and I can't find it in documents

1 个答案:

答案 0 :(得分:1)

// The member is the message author.
const member = message.member;
// Getting the channel.
const channel = client.channels.cache.get("Channel");

// Checking if the channel exists and if the channel is a voice channel.
if (!channel || channel.type !== "voice") return console.log("Invalid channel");
// Checking if the member is in a voice channel.
if (!member.voice.channel) return console.log("The member is not in a voice channel.");

// Moving the member.
member.voice.setChannel(channel).catch(e => console.error(`Couldn't move the user. | ${e}`));

注意:setVoiceChannel()是Discord JS v11中GuildMember的有效方法。

在Discord JS v12中已将其更改为GuildMember.voice.setChannel(ChannelResolvable)