【问题标题】:Defean Bot when join voice channelDefean Bot 加入语音频道
【发布时间】:2020-10-07 20:19:57
【问题描述】:

我找到了这个 sn-p 代码,但我不知道如何在我的 index.js 中使用它。有任何想法吗?

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

【问题讨论】:

  • 欢迎,我的建议只是尝试找到任何现有的 discord bot github 存储库。
  • 嗨,谢谢,我在 stackoverflow 上找到了这个 sn-p .. 我不知道如何使用它:/
  • 这就是为什么我建议检查任何现有的机器人示例,官方文档通常会留下在线代码示例。如果找不到,请向我发送推文。由于您的问题不太清楚。
  • 我只是想让机器人在加入语音频道时自我反抗

标签: javascript discord.js


【解决方案1】:

作为对您评论的回复,以下代码将在每次加入语音频道时阻止您的机器人。

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();

【讨论】:

    猜你喜欢
    • 2020-11-04
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2021-01-05
    • 2020-06-26
    • 2017-06-22
    • 2020-12-21
    相关资源
    最近更新 更多