为什么我的机器人无法获取频道?不和谐.js



我在控制台得到这个错误:TypeError: Cannot read property 'channels' of undefined.

导致问题的代码:

const channel = guild.channels.cache.find(c => c.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))

Index.js:

client.on("guildCreate", guild => {
client.commands.get("joinserver").execute(guild)
});

joinserver.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)
}
}

您将guild对象传递给execute函数作为第一个参数(不是guild而是message参数)。所以你的公会现在可以在execute功能中访问message。你应该把guild传递给正确的参数(在你的例子中是第4个参数)或者改变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)
});

相关内容

  • 没有找到相关文章

最新更新