亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法讓自動斷開機器人斷開已經在語音中的用戶

無法讓自動斷開機器人斷開已經在語音中的用戶

臨摹微笑 2023-05-25 15:47:49
我目前正在嘗試運行一個不和諧的機器人,它會在特定用戶嘗試進入時斷開我服務器上 afk 頻道的連接。誠然,我不太擅長編碼,而且我所做的大部分工作都是從我瀏覽過的其他幫助部分拼湊而成的。我已經設法讓機器人進入這樣的狀態,當用戶直接進入 afk 頻道時,它會斷開用戶的連接,但我無法弄清楚當用戶離開時如何讓它做同樣的事情一個頻道到 afk 頻道。我遇到問題的部分在這里:client.on("voiceStateUpdate", (oldMember, newMember) => {  const newUserChannel = newMember.voiceChannel;  const oldUserChannel = oldMember.voiceChannel;  if (    oldUserChannel === undefined &&    newUserChannel.name === "afk" &&    data.find(      guild =>        guild.id === newMember.guild.id &&        guild.blacklist.find(id => newMember.id === id)    )  ) {    newMember.setVoiceChannel(null);  }我已經嘗試設置oldUserChannel === undefined &&為特定頻道,并且 !== undefined,但是除了 === undefined 以外的任何東西都會給我一個 TypeError: Cannot read property 'name' of undefined。我也嘗試過使用 usernewUserChannel.id而不是 .name,但這只會給我帶來與“name”更改為“id”相同的錯誤。我對此真的很陌生,所以我正在努力想我能做些什么來修復這個錯誤。
查看完整描述

1 回答

?
白板的微信

TA貢獻1883條經驗 獲得超3個贊

如果用戶正AFK從另一個頻道移動到該頻道,oldUserChannel將被定義為VoiceChannel.

您應該檢查是否newUserChannel存在(如果是這樣,我們知道用戶仍然連接到 a?VoiceChannel,并檢查頻道的 ID/名稱是否等于“AFK”/“頻道 ID”。

注意:我鼓勵你切換到 Discord JS v12。

client.on("voiceStateUpdate", (oldMember, newMember) => {

? ? if (!newMember.voiceChannel) return false; // The GuildMember is not in a VoiceChannel.

? ? if (newMember.voiceChannel.guild.id !== "GUILD ID") return false; // Making sure this works in a certain Guild. I don't think you want this to happen in every Guild your bot is in which has a VoiceChannel called "AFK".?


? ? if (newMember.voiceChannel.name == "AFK" && newMember.id == "USER ID") { // Checking if the channel's name is AFK and making sure the user is the one you want to disconnect.

? ? ? ? newMember.setVoiceChannel(null);

? ? ? ? // I'm not sure if Discord JS v11 has a method of disconnecting the user from a VoiceChannel.

? ? ? ? // But setting the voice channel to null will work.

? ? };

});


查看完整回答
反對 回復 2023-05-25
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號