【发布时间】:2021-02-01 02:21:40
【问题描述】:
这是我的整个命令代码,问题是当我这样做时 - 移动所有人 123132123123(例如频道 ID)。该命令完美运行,但给我一个错误(node:317) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'voice' of undefined。我一直在尝试.catch() 错误,但它仍然给我这个错误。每当我做return member.voice.setChannel(`${move}`);。错误停止了,但也只是出于某种原因让我感动......
if (command === 'move') {
if (!message.member.permissions.has("MOVE_MEMBERS")) return message.channel.send(':x: **You do not have the permission to use this command!**');
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const mem = message.mentions.members.first()
let move = args[1]; // Remember arrays are 0-based!.
let move2 = args[2];
let idcheckchannel1 = client.channels.cache.get(move)
let idcheckchannel2 = client.channels.cache.get(move2)
if (!args[0]) return message.channel.send('Please mention user and voice channel ID/IDs')
if (!args[1]) return message.channel.send('Please mention voice channel ID/IDs')
if(args[0] === 'everyone' && !move2) {
if (!idcheckchannel1) return message.channel.send('Please use a valid voice channel ID')
let channel = message.guild.channels.cache.get(message.member.voice.channel.id);
for (const [memberID, member] of channel.members)
member.voice.setChannel(`${move}`);
}
if (!mem.voice.channel) return message.channel.send('User is not in voice channel')
if (!move2) {
if (!idcheckchannel1) return message.channel.send('Please use a valid voice channel ID')
mem.voice.setChannel(`${move}`)
} else {
if (!idcheckchannel1) return message.channel.send('Please use a valid voice channel ID')
if (!idcheckchannel2) return message.channel.send('Please use a valid voice channel ID')
mem.voice.setChannel(`${move}`)
mem.voice.setChannel(`${move2}`)
}
}
【问题讨论】:
标签: node.js discord discord.js bots