【问题标题】:How to use discord.js .setSelfDeaf() in my code?如何在我的代码中使用 discord.js .setSelfDeaf()?
【发布时间】:2021-01-13 16:25:25
【问题描述】:

我的 join.js 代码如下:- 我希望机器人在加入任何语音频道时自动自聋。

module.exports = {
  name: "join",
  description: "Joins your voice channel",
  category: "music",
  execute(message, args) {  
    if (message.member.voice.channel) {
      message.member.voice.channel.join().then((connections) => {
        message.channel.send({
          embed: {
            color: message.client.messageEmbedData.color,
            author: {
              name: "✔️ Hey, i joined your voice channel",
            },
            timestamp: new Date(),
          },
        });
      });
    } else {
      message.channel.send({
        embed: {
          color: message.client.messageEmbedData.color,
          author: {
            name: "❗ You are not in a voice channel",
          },
          timestamp: new Date(),
        },
      });
    }
  },
};

我尝试了很多方法,但无法实现 .setSelfDeaf(true) 。

有人帮忙吗?

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    您可以使用VoiceState#setSelfDeaf 来实现这一点。这样做很容易。


    if (message.guild.me.voice.channel) { // Checking if the bot is in a VoiceChannel.
        message.guild.me.voice.setSelfDeaf(true); // Using setSelfDeaf to self-deafen the bot.
    };
    

    module.exports = {
        name: "join",
        description: "Joins your voice channel",
        category: "music",
        execute(message, args) {
            if (message.member.voice.channel) {
                message.member.voice.channel.join().then((connections) => {
                    message.guild.me.voice.setSelfDeaf(true);
                    message.channel.send({
                        embed: {
                            color: message.client.messageEmbedData.color,
                            author: {
                                name: "✔️ Hey, i joined your voice channel",
                            },
                            timestamp: new Date(),
                        },
                    });
                });
            } else {
                message.channel.send({
                    embed: {
                        color: message.client.messageEmbedData.color,
                        author: {
                            name: "❗ You are not in a voice channel",
                        },
                        timestamp: new Date(),
                    },
                });
            }
        },
    };
    

    【讨论】:

    • 如果您将这个sn-p插入我的代码版本并回复会更好。那么这将非常有帮助@Jakye
    猜你喜欢
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    • 2019-11-09
    • 2020-05-13
    • 2019-02-06
    • 2013-10-17
    • 2018-07-26
    相关资源
    最近更新 更多