【发布时间】:2021-11-13 21:33:58
【问题描述】:
我开始学习 discord.js 库并尝试在用户加入特殊语音频道并且机器人创建新频道并移动用户时进行事件。现在 bot 可以创建频道,但是当它尝试移动用户时出现错误“无法读取未定义的属性(正在读取 'setChannel')”
这是我的代码:
const {Collection} = require('discord.js')
let privateVoice = new Collection()
config = require('../config.json');
module.exports = async (bot, oldState, newState)=>{
const user = await bot.users.fetch(newState.id)
const member = newState.guild.members.fetch(user)
if(!oldState.channel && newState.channel.id === (config.createChannel)){
const channel = await newState.guild.channels.create(user.tag,{
type: "GUILD_VOICE",
parent: newState.channel.parent
})
member.voice.setChannel(channel);
privateVoice.set(user.id, channel.id)
}
};
【问题讨论】:
标签: javascript discord discord.js