本文介紹了未定義 member.voiceChannel的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我的 discord bot 遇到問題,不知道用戶在哪個(gè)頻道.如果我檢查 member.voiceChannel
,它總是返回 undefined
.即使我在語音頻道內(nèi).
I am having trouble with my discord bot not knowing what channel a user is in. If I check member.voiceChannel
it always returns undefined
. Even if I am inside a voice channel.
代碼:
let voiceChannel;
voiceChannel = msg.member.voiceChannel;
if (!voiceChannel) {
return msg.reply('Please join a voice channel before using this command.');
}
console.log(voiceChannel);
打印 undefined
無論我是否在語音頻道中.
console.log(voiceChannel);
prints undefined
regardless of me being in a Voice Channel or not.
推薦答案
剛剛在使用 Discord.js v12 時(shí)發(fā)生在我身上.
Happened to me just now while using Discord.js v12.
顯然變量在版本之間更改了名稱,現(xiàn)在改為:
Apparently the variable changed names between versions and now instead of:
message.member.voiceChannel
它是:
message.member.voice.channel
像這樣更改變量對我有用
Changing the variable like this worked for me
這篇關(guān)于未定義 member.voiceChannel的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!