类型错误:无法读取未定义的属性(读取"创建邀请")



每当我尝试向我的公会频道发出邀请时,它都不起作用。

const {
Client
} = require("discord.js");
const client = new Client({ intents: [] });
client.on("ready", async () => {
console.log(`Bot ${client.user.username} is ready`);
const guild = client.guilds.cache.first()
await guild.channels.cache
.filter(channel => channel.type === "text")
.first()
.createInvite()
.then((invite) => console.log('Server: ' + invite.code))
})

client.login(process.env.TOKEN);

我得到标题错误,我不明白为什么它不会工作,因为我正在获得一个频道,我正在创建一个邀请。由于

这个错误可能是因为你过滤了公会的频道。text不是一个有效的通道类型。

https://discord.js.org//docs/主/稳定/类型/ChannelType

查看ChannelType文档中对应的discord.js版本。

修正了我自己的问题:

const {
Client
} = require("discord.js");
const client = new Client({ intents: [] });
client.on("ready", async () => {
console.log(`Bot ${client.user.username} is ready`);
try {
var channel = await client.channels.fetch('1056353927471308802');
var invite = await channel.createInvite()
console.log(`https://discord.gg/${invite.code}`)
} catch {
throw new Error(`Channel with ID ${sendChannel} not found`);
}
})

client.login(process.env.TOKEN);

相关内容

最新更新