加入语音频道时的Defean Bot

时间:2020-06-17 21:34:32

标签: javascript discord.js

我已经找到了这段代码,但是我不知道如何在index.js中使用它。有任何想法吗?

voiceChannel.join()
  .then(connection => {
      connection.voice.setSelfDeaf(true);
  });

1 个答案:

答案 0 :(得分:0)

作为对您的评论的答复,以下代码将在您的漫游器每次加入语音通道时对其进行辩护。

client.on("voiceStateUpdate", (oldVoiceState, newVoiceState) => {
    if (!newVoiceState.channel) {return false}; // The bot disconnected.
    if (newVoiceState.id == client.user.id) { // Checking if it is the bot.
        newVoiceState.setSelfDeaf(true); // Setting self defean to true.
    };
});

要让您的漫游器加入语音通道:

// Getting the channel.
const channel = client.channels.cache.get("722944525986955386");
// Joining the channel.
channel.join();