【发布时间】:2021-08-14 06:44:46
【问题描述】:
有没有什么办法可以让 discord js 机器人将用户转移到不同的语音频道?我在网上看到的一切似乎都过时了,因为我不断收到错误。现在我只是将它硬编码到某个频道以测试它是否可以工作,但它没有。
client.on('message', message => {
console.log('' + message.author + ': ' + message.content);
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(" ");
const c = args;
for(var i = 0; i < c.length; i++) {
c[i] = c[i].toLowerCase();
}
if (c[0] === 'movevoice'){
if(!message.mentions.members.first()){
message.author.voice.setChannel(762760164364648479)
}else{
const member = message.mentions.members.first();
member.voice.setChannel(762760164364648479);
}
}
【问题讨论】:
-
频道 ID 必须是字符串 (
'762760164364648479'),而不是数字 (762760164364648479) -
它给了我错误“TypeError: cannot read property 'setChannel' of undefined”
-
将
message.author.voice.setChannel()更改为message.member.voice.setChannel()。 More information -
我设法让它工作。非常感谢!
标签: javascript discord.js