我的不和谐机器人没有加入语音频道,但它没有给我任何错误消息



我在javascript中为服务器制作一个不和谐机器人,我需要它在启动时加入语音通道,但代码只是不起作用。它具有所需的权限,但它不做任何事情,甚至没有错误消息这是代码(在channelId和guildId中,我只是使用了我需要的频道和我需要的公会的实际id):

const Discord = require("discord.js")
const VoiceDiscord= require("@discordjs/voice");
const Client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.GuildMembers
]
});
Client.once("ready",() => {
const connection =VoiceDiscord.joinVoiceChannel({
channelId: 980878176928550912,
guildId: 980878092849528832,
adapterCreator: Client.guilds.cache.find(guild => guild.id == 980878092849528832).voiceAdapterCreator
})
});

我尝试卸载和重新安装discordjs和@discordjs/voice,我尝试使用另一个bot,它也不起作用

事件侦听器永远不会触发,因为它应该是Client.on而不是Client.once。正确的代码如下:

const Discord = require("discord.js")
const VoiceDiscord= require("@discordjs/voice");
const Client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.GuildMembers
]
});
Client.on("ready",() => {
const connection =VoiceDiscord.joinVoiceChannel({
channelId: 980878176928550912,
guildId: 980878092849528832,
adapterCreator: Client.guilds.cache.find(guild => guild.id == 980878092849528832).voiceAdapterCreator
})
});

最新更新