无法读取未定义的属性(读取"通道")



我正在尝试创建一个事件,当有人添加我的bot时,它会在我的bot可以发送消息嵌入的频道上发送消息嵌入。

discord.js:v13.6.0

节点:v17.7.2

事件/guildCreate.js

const client = require("../index");
const discord = require("discord.js")
client.on("guildCreate", async (client, guild) => {
let channel = guild.channels.cache.find(
channel =>
channel.type === "text" &&
channel.permissionsFor(guild.me).has("SEND_MESSAGES")
);
channel.send( new discord.MessageEmbed()
.setDescription("**Thank you for adding me!**")
.setColor("#fcba03"))
})

编辑:我有点修复我的问题与阅读通道:

const client = require("../index");
const { MessageEmbed } = require("discord.js")
client.on("guildCreate", async (guild, message) => {
let channel = guild.channels.cache.find(
channel =>
channel.type === "text" &&
channel.permissionsFor(guild.me).has("SEND_MESSAGES")
);
const embed = new MessageEmbed()
embed.setDescription("Thank you for adding me!")
embed.setColor("#2f3136")
message.guild.channels.cache.get(channel).send(embed)
})

,但又得到新的错误:TypeError: Cannot read property of undefined (reading 'guild')

我认为你的" channel "是一个数组而不是一个channel对象,因为你正在过滤所有的文本通道。确保选择数组/集合的第一个通道。

尝试显示当您记录"通道"时显示的内容

最新更新