很抱歉今天有很多问题。我正在使用票务命令,但出现此错误类型错误:无法读取未定义的“发送”属性
知道我在做什么错吗? 任何形式的帮助将不胜感激。
这是我的代码:
bot.on("message", message =>{
const args = message.content.substring(PREFIX.length).split(" ")
if(message.author.bot) return
if(message.channel.type === "dm") return
if(message.content.startsWith(`${PREFIX}openticket`)){
const reason = message.content.split(" ").slice(1).join(" ");
const role2 = message.guild.roles.cache.find(role2 => role2.name == "@everyone");
message.guild.channels.create(`ticket-${message.author.username}`, {
permissionOverwrites: [
{
id: role2.id,
deny: 'VIEW_CHANNEL',
deny: 'READ_MESSAGE_HISTORY',
deny: 'SEND_MESSAGES'
}, {
id: message.author.id,
allow: 'VIEW_CHANNEL',
allow: 'READ_MESSAGE_HISTORY',
allow: 'SEND_MESSAGES'
}
]
})
const embedcreated = new Discord.MessageEmbed()
.setColor("#f00202")
.setDescription(`You ticket has been created ` + `#ticket-${message.author.username}` )
.setTitle("Tickets")
.setFooter(`Tickets System`)
.setTimestamp()
message.channel.send(embedcreated);
const embedticket = new Discord.MessageEmbed()
.setColor("#f00202")
.addField(`Hey ${message.author.username}!`, ` Please wait until support arrives`)
.setTimestamp();
const ticketchannel = message.guild.channels.cache.get(channel => channel.name == `ticket-${message.author.username}`)
ticketchannel.send(embedticket),
ticketchannel.send(`${message.author}`)
}})
错误在这里:ticketchannel.send
我尝试了let ticketchannel = message.guild.channels.cache.get(channel => channel.name == `ticket-${message.author.username}`)
然后将代码放在不同的位置,但仍然无法正常工作
答案 0 :(得分:0)
似乎您正在执行message.guild.channels.cache
中应该具有send
方法的某些对象。这里可能发生两件事-
channel.name == ticket-${message.author.username}
不能通过message.guild.channels.cache
中存在的任何条件来满足此条件。message.guild.channels.cache.get
获取的任何对象都没有send
方法。 let
和const
与该值无关。除非您重新分配变量,否则它们是可替换的。
答案 1 :(得分:0)
与其尝试在变量中获取通道,不如使用回调。此外,allow
和deny
属性允许arrays
,因此您可以将所有权限标志组合到array
message.guild.channels
.create(`ticket-${message.author.username}`, {
permissionOverwrites: [
{
id: role2.id,
deny: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES'],
},
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES'],
},
],
})
.then((channel) => { // pass the `channel` parameter in the callback
// ...
channel.send(embedticket);
channel.send(`${message.author}`);
});