[英]Why can't my bot get channels? discord.js
I get this error in my console: TypeError: Cannot read property 'channels' of undefined
.我在控制台中收到此错误: TypeError: Cannot read property 'channels' of undefined
。
The code that is causing the problem:导致问题的代码:
const channel = guild.channels.cache.find(c => c.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))
Index.js:索引.js:
client.on("guildCreate", guild => {
client.commands.get("joinserver").execute(guild)
});
joinserver.js:加入服务器.js:
const Discord = require("discord.js")
module.exports = {
name: 'joinserver',
description: '',
execute(message, args, client, guild) {
const channel = guild.channels.cache.find(c => c.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))
const embeds = new Discord.MessageEmbed()
channel.send(embeds)
}
}
You passing your guild
object into the execute
function as first parameter (which is not guild
but message
parameter).您将guild
对象作为第一个参数(不是guild
而是message
参数)传递到execute
函数中。 So your guild is accessible inside execute
function as message
right now.所以你的公会现在可以在execute
函数中作为message
访问。 You should pass guild into correct argument (4th argument in your example) or change the way how execute
function receiving arguments.您应该将 guild 传递给正确的参数(示例中的第四个参数)或更改execute
函数接收参数的方式。
client.on("guildCreate", guild => {
// This should work: you need to pass null to `message`, `args` and `client`
// because these arguments marked as required
client.commands.get("joinserver").execute(null, null, null, guild)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.