首页 > 解决方案 > 不和谐.js。无法从用户短信中获取频道 ID

问题描述

所以我试图让一个机器人加入我的语音频道,然后让它发送一条消息。问题是我不完全确定我使用voiceChannel.join()的是正确的方法,因为我收到以下错误"Cannot ready property "join" of undefined"

client.on('message', msg=>{
if(msg.content === "testing"){
const channel = msg.member.voiceChannel;
channel.join() //voiceChannel.join()
        .then(msg.channel.send("!p https://www.youtube.com/watch?v=e-IWRmpefzE"));
    }
})

我得到了这个错误:

C:\Users\Jakob\Desktop\DiscordBot\index.js:13

channel.join();

^



TypeError: Cannot read property 'join' of undefined

at Client.<anonymous> (C:\Users\Jakob\Desktop\DiscordBot\index.js:13:17)

机器人读取了消息,然后我不完全确定尝试加入时出了什么问题......

标签: javascriptdiscord.js

解决方案


这是 Discord.js v12 中的一个变化。替换msg.member.voiceChannelmsg.member.voice.channel


推荐阅读