考虑:
const Discord = require("discord.js")
const TOKEN = "I WAS WRITE MT TOKEN"
const { Client, GatewayIntentBits } = require('discord.js');
const { MemberFetchNonceLength } = require("discord.js/src/errors/ErrorCodes");
const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.GuildVoiceStates,
]
})
client.on("ready", () => {
console.log(`${client.user.tag} kullanımda`)
})
client.on('error', (err) => {
console.log(err.message)
});
client.on("voiceStateUpdate", async (oldState, newState) => {
const user = await client.user.fetch(newState.id);
const member = newState.guild.member(user);
if (!oldState.channel && newState.channel.id === "I WAS WRITE MY CHANNEL ID") {
const channel = await newState.guild.channel.create(user.tag, {
type: "voice",
parent: newState.channel.parent,
});
member.voice.setChannel(channel);
voiceCollection.set(user.id, channel.id);
} else if(!newState.channel) {
if(oldState.channelId === voiceCollection.get(newState.id))
return oldState.channel.delete();
}
});
client.login(TOKEN)
我正在构建这个机器人来建立一个自动语音频道。我的代码运行良好,但它不会创建通道。每次我进入语音频道时,我都会得到错误";newState.guild.member不是函数"。
如何解决此问题?
Guild
类不包含名为member()
的方法。
如果您试图获取特定的成员,则应该使用.fetch()
。
client.on("voiceStateUpdate", async (oldState, newState) => {
// the member's id is the same as it's corresponding user id
const member = await newState.guild.members.fetch(newState.id);
... // etc