如何将通话中的特定人转移到另一个通话中[Discord.js]

时间:2020-10-05 12:28:57

标签: javascript discord discord.js

我正在尝试执行一个命令,该命令将一个不和谐呼叫中的某个人使用@提及,然后使用频道名称移动到服务器上的另一个不和谐呼叫中,我已经尝试了几个小时,但我仍然不知道该怎么做它

const { Command } = require('discord.js-commando');
const { MessageEmbed } = require('discord.js');

module.exports = class MoveCommand extends Command {
 constructor(client) {
  super(client, {
   name: 'move',
   aliases: ['m'],
   memberName: 'move',
   group: 'guild',
   description: 'Use to move other people in call',
   guildOnly: true,
   userPermissions: ['MANAGE_CHANNELS', 'MOVE_MEMBERS'],
   clientPermissions: ['MANAGE_CHANNELS', 'MOVE_MEMBERS'],
   args: [
    {
     key: 'usersToMove',
     prompt:
      'Please mention the user you want to move with @ or provide his/her ID.',
     type: 'string',
    },
    {
     key: 'Channel',
     prompt: 'Please mention the Channel you wish to move the user to.',
     type: 'string',
    },
   ],
  });
 }

 run(message, { usersToMove, Channel }) {
  const user =
   message.mentions.members.first() || message.guild.members.fetch(usersToMove);
  if ((user, Channel == undefined))
   return message.channel.send('Please try again with a valid user');
  return message.channel.send('Please try again with a valid Channel');
  user.then(() => mem.voice.setChannel(message.member.voice.channel));
  message.channel.send(':right_facing_fist: ' + member).catch((e) => {
   message.say(
    'Something went wrong when trying to move this user, I probably do not have the permission to move this user or some shit'
   );
   return console.error(e);
  });
 }
};

1 个答案:

答案 0 :(得分:1)

您没有写下代码的当前实际结果,但我会大胆猜测,说您的代码总是返回文本“请使用有效的频道重试”。

我猜测的原因是,在if语句之后有一个return语句,因此它将始终被触发(除非if语句返回true,在这种情况下它仍会从代码中返回,但会有所不同消息)。

看看下面的代码,然后尝试一下。我添加了评论来解释一切:

run(message, { usersToMove, Channel }) {
  // Get the mentioned user
  const user = message.mentions.members.first() || message.guild.members.fetch(usersToMove);
  
  // Check if the user is valid
  if (!user) return message.channel.send('Please try again with a valid user');
  
  // Check if the channel is valid
  if (!Channel) return message.channel.send('Please try again with a valid Channel');
  
  // If we reach this point, we know we have a valid user AND a valid Channel
  
  // Move the mentioned user to the mentioned Channel
  user.voice.setChannel(Channel)
    // If the moving was successful, send a success message
    .then(() => {
      message.channel.send(`:right_facing_fist: ${user}`);
    })
    // If the moving was unsuccessful, send a message with the error
    .catch((error) => {
      message.channel.send(`Something went wrong with moving the user. Here's the error: ${error}`);
    });
}