【发布时间】:2021-03-29 18:19:28
【问题描述】:
我正在尝试使用多个用户提及,而 message.mention.members.first() 无法做到这一点。所以我做了一些挖掘,从Parsing Mention Arguments找到了这个函数:
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}
当我尝试使用此功能时,我得到“Discord JS - TypeError: Cannot read property 'setChannel' of undefined”这是导致错误的代码
let channel = client.channels.cache.find(channel => channel.name === args[0]);
const user1 = getUserFromMention(args[1]);
const user2 = getUserFromMention(args[2]);
message.member.voice.setChannel(channel.id);
user1.voice.setChannel(channel.id);
user2.voice.setChannel(channel.id);
此代码旨在将我自己和提及的用户移动到选定的语音频道,它在使用 message.mention.members.first() 时工作得非常好,但只能处理提及的用户中的二分之一。
我想知道是否可以修复我当前的错误,或者是否有其他方法可以解决这个问题?
【问题讨论】:
标签: node.js discord discord.js bots