如何将每个人从某个角色转移到某个渠道

时间:2019-03-12 15:42:44

标签: javascript discord.js

代码需要能够看到每个人都扮演某个角色,然后将所有这些人置于语音通道中。

const team1role = message.guild.roles.find("name", "Team 1");
const voice = args.join(" ");
const chan1 = message.guild.channels.find("name", "Team 1");
team1role.setVoiceChannel(chan1);

出现此错误:

TypeError: team1role.setVoiceChannel is not a function
    at pass.run (F:\Discord_Bot\expbotworking\Experiance\commands\move.js:17:17)
    at Client.bot.on (F:\Discord_Bot\expbotworking\Experiance\index.js:26:11)
    at Client.emit (events.js:197:13)
    at MessageCreateHandler.handle (F:\Discord_Bot\expbotworking\Experiance\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (F:\Discord_Bot\expbotworking\Experiance\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (F:\Discord_Bot\expbotworking\Experiance\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (F:\Discord_Bot\expbotworking\Experiance\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (F:\Discord_Bot\expbotworking\Experiance\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:197:13)

1 个答案:

答案 0 :(得分:1)

问题在于team1role是角色的实例,而不是成员。您必须从上述角色中获取所有成员,并为每个成员设置语音通道。

下面您可以找到示例代码,尝试一下,让我知道它的运行方式。

const team1role = message.guild.roles.find((role) => role.name === "Team 1");
const team1members = team1role.members;

const chan1 = message.guild.channels.find((channel) => channel.name === "Team 1")

team1members.forEach((member) => {
  member.setVoiceChannel(chan1);
});