当机器人在 discord.js v13 中准备就绪时加入特定的语音频道
Join an specific voice channel when the bot is ready in discord.js v13
我找到了一些关于这个问题的文章。像 .
但它是在 discord v12 中。我想要 discord.js v13
我的代码:
client.on("ready", async() => {
const { joinVoiceChannel } = require('@discordjs/voice');
joinVoiceChannel({
channelId: "863783336860975114",
guildId: "847071265100791849",
adapterCreator: channelId.guild.voiceAdapterCreator
})
// It does not work
}
如何让我的机器人在准备就绪时加入特定频道?
我正在使用 discord.js v13 和 node.js v16.15
在 @discordjs/voice an in the discord.js guide 的文档中我们看到:
const { joinVoiceChannel } = require('@discordjs/voice');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
您需要先获取公会或频道,因为您需要使用 voiceAdapterCreator。
您可以使用 client.channels.fetch 之类的方法来获取频道对象。
放入就绪事件的示例代码:
client.channels.fetch(id) // voice channel's id
.then((channel) => { // channel object
const VoiceConnection = joinVoiceChannel({
channelId: channel.id, // the voice channel's id
guildId: channel.guild.id, // the guild that the channel is in
adapterCreator: channel.guild.voiceAdapterCreator // and setting the voice adapter creator
});
});
我找到了一些关于这个问题的文章。像
但它是在 discord v12 中。我想要 discord.js v13
我的代码:
client.on("ready", async() => {
const { joinVoiceChannel } = require('@discordjs/voice');
joinVoiceChannel({
channelId: "863783336860975114",
guildId: "847071265100791849",
adapterCreator: channelId.guild.voiceAdapterCreator
})
// It does not work
}
如何让我的机器人在准备就绪时加入特定频道?
我正在使用 discord.js v13 和 node.js v16.15
在 @discordjs/voice an in the discord.js guide 的文档中我们看到:
const { joinVoiceChannel } = require('@discordjs/voice');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
您需要先获取公会或频道,因为您需要使用 voiceAdapterCreator。
您可以使用 client.channels.fetch 之类的方法来获取频道对象。
放入就绪事件的示例代码:
client.channels.fetch(id) // voice channel's id
.then((channel) => { // channel object
const VoiceConnection = joinVoiceChannel({
channelId: channel.id, // the voice channel's id
guildId: channel.guild.id, // the guild that the channel is in
adapterCreator: channel.guild.voiceAdapterCreator // and setting the voice adapter creator
});
});