NodeJS 如何让一个不和谐的机器人undeafen他们自己当它加入一个语音通道

06odsfpq  于 2023-03-17  发布在  Node.js
关注(0)|答案(1)|浏览(180)

我正试图让我的机器人播放一些音乐从一个链接,我们有我们能够有机器人加入语音通道,但它加入已经聋了,所以它不会播放我们需要的声音。
我怎样才能让机器人能够加入并使自己不受伤害?

require('dotenv').config(); //initialize dotenv
require('discord-reply');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMembers
    ] });
const {
    token,
    voicechannel,
    list
} = require('./config.json');

const { 
    joinVoiceChannel, 
    getVoiceConnection,
    createAudioPlayer,
    createAudioResource

} = require('@discordjs/voice');

const voice = require('@discordjs/voice');
client.on("messageCreate", (message) => {
message.content.startsWith('!activetest')) {
//cha and gui is a const i have somewhere else, it will define the channel id and the guild id
        const connection = joinVoiceChannel({
            channelId: cha,
            guildId: gui,
            adapterCreator: client.guilds.cache.get("1080859608257671338").voiceAdapterCreator,
        });
}
});

有了上面的代码,机器人将加入该频道时,要求,我将如何让他取消静音自己从该频道。我已经尝试了一些不同的方法,但没有工作。

cbjzeqam

cbjzeqam1#

当你的机器人加入语音通道时,你可以将selfDeaf选项设置为false。我想这就是你要找的:

const connection = joinVoiceChannel({
  channelId: cha,
  guildId: gui,
  adapterCreator: client.guilds.cache.get('1080859608257671338')
    .voiceAdapterCreator,
  selfDeaf: false,
});

相关问题