Whenever I try and make an invite to one of my guild's channels, it doesn't work.
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);
I get the title error and I don't understand why it wont work as I'm getting a channel and I'm creating an invite. Thanks
CodePudding user response:
The error likely lies in you filtering the guild's channels. text
is not a valid channel type.
https://discord.js.org/#/docs/main/stable/typedef/ChannelType
Check the ChannelType
documentation for your corresponding discord.js version.
CodePudding user response:
Fixed my own question:
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);