if (command === 'guilds') {
if (message.author.id === ownerID) {
let guilding = client.guild.channels.cache.find(channel => channel.name === "pain-logs")
if (!guild.me.hasPermission("CREATE_INSTANT_INVITE")) {
return message.channel.send(
'I cannot Create Invites for ${guild.me.name}.'
);
}
if (!guild.me.hasPermission("VIEW_CHANNEL")) {
return message.channel.send(
'I Cannot View Channels In ${guild.me.name}'
);
}
guilding.createInvite().then(inv => console.log('${guild.name} | ${inv.url}', message.channel.send('${guild.name} | ${inv.url}')))
}
}错误:
'TypeError: Cannot read property 'channels' of undefined'所以我试着找到频道(痛苦日志),一旦找到频道,它就会创建一个对频道的邀请,但我一直收到这个错误
发布于 2020-06-09 02:23:12
client.guild不存在,而client.guilds确实存在,所以如果您想从特定的行会获取特定的通道,您必须这样做:
//or some other way of getting it like `.get(id)`
const guild = client.guilds.cache.find(g => g.name === "name");
if(!guild || !guild.available) return message.channel.send("Can't find guild");
const channel = guild.channels.cache.find(c => c.name === "pain-logs");如果你没有机器人所在的任何其他服务器,或者你不关心它来自哪个服务器,你可以使用client.channels
//might need to fetch it if it's not in the cache
const channel = client.channels.find(c => c.name === "pain-logs");之后,只需检查通道是否可见并创建它
if(!channel) return message.channel.send("No channel found");
if(!channel.viewable) return message.channel.send("Can't view the channel");
channel.createInvite()
.then(inv => {
//guild.name will only work if you used the first method
console.log(`${guild.name} | ${inv.url}`);
message.channel.send(`${guild.name} | ${inv.url}`);
})
.catch(err => {
console.error(err);
message.channel.send("Don't have permission");
});https://stackoverflow.com/questions/62266774
复制相似问题