我试图在创建消息后立即向其发送消息,但该消息似乎无效。我正在使用discord.js@v12
这是代码:
message.guild.channels.create(cpl, 'text').then(ma => {
ma.setParent(cat);
ma.lockPermissions();
}).catch(err => console.log(err))
let nChannel = bot.channels.cache.find(ch => ch.name === cpl)
console.log(nChannel)
let embed = new Discord.MessageEmbed()
.setTitle("New Ticket")
nChannel.send(embed)
这是记录到控制台的内容:
Cannot read property 'send' of undefined
答案 0 :(得分:0)
这是因为您在尝试发送消息之前没有等待创建通道。与使用.setParent()
和.lockPermissions()
之前等待其准备就绪的方式相同,应该使用.send()
之前等待。
这是我的处理方式:
message.guild.channels.create(cpl, 'text').then(async (newChannel) => {
// You're inside .then, so all of this is happening AFTER the channel is created
// Wait for .setParent and .lockPermissions to fulfill
await newChannel.setParent(cat)
await newChannel.lockPermissions()
// You can now send your message
let embed = new Discord.MessageEmbed()
.setTitle("New Ticket")
newChannel.send(embed)
})